DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3025 lines | 75.735kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
2

            
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
3
our $VERSION = '0.1691';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
5

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
6
use Object::Simple -base;
many change
yuki-kimoto authored on 2010-02-11
7

            
packaging one directory
yuki-kimoto authored on 2009-11-16
8
use Carp 'croak';
9
use DBI;
10
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
11
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
12
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
13
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
14
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
15
use DBIx::Custom::Tag;
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/;
packaging one directory
yuki-kimoto authored on 2009-11-16
18

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
22
our @COMMON_ARGS = qw/table query filter type id primary_key type_rule_off/;
cleanup
Yuki Kimoto authored on 2011-03-21
23

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

            
added helper method
yuki-kimoto authored on 2010-10-17
61
our $AUTOLOAD;
62
sub AUTOLOAD {
63
    my $self = shift;
64

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
68
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
69
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
70
    if (my $method = $self->{_methods}->{$mname}) {
71
        return $self->$method(@_)
72
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
73
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
74
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
75
    }
76
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
77
        croak qq{Can't locate object method "$mname" via "$package" }
78
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
79
    }
added helper method
yuki-kimoto authored on 2010-10-17
80
}
81

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
82
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
83
    my ($self, $param) = @_;
84
    
85
    # Create set tag
86
    my @params;
87
    my $safety = $self->safety_character;
88
    my $q = $self->reserved_word_quote;
89
    foreach my $column (keys %$param) {
90
        croak qq{"$column" is not safety column name } . _subname
91
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
92
        my $column_quote = "$q$column$q";
93
        $column_quote =~ s/\./$q.$q/;
94
        push @params, "$column_quote = :$column";
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
95
    }
96
    my $tag = join(', ', @params);
97
    
98
    return $tag;
99
}
100

            
cleanup
Yuki Kimoto authored on 2011-03-21
101
sub column {
102
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
103
    
cleanup
Yuki Kimoto authored on 2011-04-02
104
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
105
    my $q = $self->reserved_word_quote;
106
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
107
    # Separator
108
    my $separator = $self->separator;
109
    
cleanup
Yuki Kimoto authored on 2011-04-02
110
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
111
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
112
    $columns ||= [];
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
113
    push @column, "$q$table$q.$q$_$q as $q${table}${separator}$_$q"
114
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
115
    
116
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
117
}
118

            
packaging one directory
yuki-kimoto authored on 2009-11-16
119
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
120
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
121
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
122
    # Connect
123
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
124
    
packaging one directory
yuki-kimoto authored on 2009-11-16
125
    return $self;
126
}
127

            
cleanup
yuki-kimoto authored on 2010-10-17
128
sub create_query {
129
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
130
    
cleanup
yuki-kimoto authored on 2010-10-17
131
    # Cache
132
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
133
    
cleanup
Yuki Kimoto authored on 2011-04-02
134
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
135
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
136
    
137
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
138
    if ($cache) {
139
        
140
        # Get query
141
        my $q = $self->cache_method->($self, $source);
142
        
143
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
144
        if ($q) {
145
            $query = DBIx::Custom::Query->new($q);
146
            $query->filters($self->filters);
147
        }
cleanup
yuki-kimoto authored on 2010-10-17
148
    }
149
    
cleanup
Yuki Kimoto authored on 2011-04-02
150
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
151
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
152

            
cleanup
yuki-kimoto authored on 2010-10-17
153
        # Create query
cleanup
Yuki Kimoto authored on 2011-04-02
154
        my $builder = $self->query_builder;
cleanup
yuki-kimoto authored on 2010-10-17
155
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
156

            
cleanup
Yuki Kimoto authored on 2011-04-02
157
        # Remove reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
158
        if (my $q = $self->reserved_word_quote) {
cleanup
Yuki Kimoto authored on 2011-04-02
159
            $_ =~ s/$q//g for @{$query->columns}
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
160
        }
161

            
cleanup
Yuki Kimoto authored on 2011-04-02
162
        # Save query to cache
163
        $self->cache_method->(
164
            $self, $source,
165
            {
166
                sql     => $query->sql, 
167
                columns => $query->columns,
168
                tables  => $query->tables
169
            }
170
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
171
    }
172
    
cleanup
yuki-kimoto authored on 2010-10-17
173
    # Prepare statement handle
174
    my $sth;
175
    eval { $sth = $self->dbh->prepare($query->{sql})};
improved error messages
Yuki Kimoto authored on 2011-04-18
176
    
177
    if ($@) {
178
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
179
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
180
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
181
    
cleanup
yuki-kimoto authored on 2010-10-17
182
    # Set statement handle
183
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
184
    
cleanup
Yuki Kimoto authored on 2011-02-09
185
    # Set filters
186
    $query->filters($self->filters);
187
    
cleanup
yuki-kimoto authored on 2010-10-17
188
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
189
}
190

            
update pod
Yuki Kimoto authored on 2011-03-13
191
sub dbh {
192
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
193
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
194
    # Set
195
    if (@_) {
196
        $self->{dbh} = $_[0];
197
        
198
        return $self;
199
    }
200
    
201
    # Get
202
    else {
203
        # From Connction manager
204
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
205
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
206
              unless ref $connector && $connector->can('dbh');
207
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
208
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
209
        }
210
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
211
        # Connect
212
        $self->{dbh} ||= $self->_connect;
213
        
214
        # Quote
215
        unless ($self->reserved_word_quote) {
216
            my $driver = $self->{dbh}->{Driver}->{Name};
217
            my $quote = $driver eq 'mysql' ? '`' : '"';
218
            $self->reserved_word_quote($quote);
219
        }
220

            
221
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
222
    }
223
}
224

            
cleanup
Yuki Kimoto authored on 2011-03-21
225
our %DELETE_ARGS
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
226
  = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all where_param/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
227

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
268
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
269
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
270
    my $q = $self->reserved_word_quote;
271
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
272
    push @sql, $append if $append;
273
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
274
    
275
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
276
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
277
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
278
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
279
        table => $table,
280
        %args
281
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
282
}
283

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

            
added helper method
yuki-kimoto authored on 2010-10-17
286
sub DESTROY { }
287

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
288
sub create_model {
289
    my $self = shift;
290
    
cleanup
Yuki Kimoto authored on 2011-04-02
291
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
292
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
293
    $args->{dbi} = $self;
294
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
295
    my $model_name  = delete $args->{name};
296
    my $model_table = delete $args->{table};
297
    $model_name ||= $model_table;
298
    
cleanup
Yuki Kimoto authored on 2011-04-02
299
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
300
    my $model = $model_class->new($args);
301
    $model->name($model_name) unless $model->name;
302
    $model->table($model_table) unless $model->table;
303
    
304
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
305
    my $filter = ref $model->filter eq 'HASH'
306
               ? [%{$model->filter}]
307
               : $model->filter;
cleanup
Yuki Kimoto authored on 2011-06-13
308
    $self->_apply_filter($model->table, @$filter);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
309
    my $result_filter = ref $model->result_filter eq 'HASH'
310
               ? [%{$model->result_filter}]
311
               : $model->result_filter;
312
    for (my $i = 1; $i < @$result_filter; $i += 2) {
313
        $result_filter->[$i] = {in => $result_filter->[$i]};
314
    }
cleanup
Yuki Kimoto authored on 2011-06-13
315
    $self->_apply_filter($model->table, @$result_filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
316
    
cleanup
Yuki Kimoto authored on 2011-04-02
317
    # Associate table with model
cleanup
Yuki Kimoto authored on 2011-04-25
318
    croak "Table name is duplicated " . _subname
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
319
      if exists $self->{_model_from}->{$model->table};
320
    $self->{_model_from}->{$model->table} = $model->name;
321

            
322
    # Table alias
323
    $self->{_table_alias} ||= {};
324
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
325
    
326
    # Set model
327
    $self->model($model->name, $model);
328
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
329
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
330
}
331

            
332
sub each_column {
333
    my ($self, $cb) = @_;
334
    
335
    # Iterate all tables
336
    my $sth_tables = $self->dbh->table_info;
337
    while (my $table_info = $sth_tables->fetchrow_hashref) {
338
        
339
        # Table
340
        my $table = $table_info->{TABLE_NAME};
341
        
342
        # Iterate all columns
343
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
344
        while (my $column_info = $sth_columns->fetchrow_hashref) {
345
            my $column = $column_info->{COLUMN_NAME};
346
            $self->$cb($table, $column, $column_info);
347
        }
348
    }
349
}
350

            
cleanup
Yuki Kimoto authored on 2011-04-02
351
our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param';
352

            
353
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
354
    my $self = shift;
355
    my $query = shift;
356
    my $param;
357
    $param = shift if @_ % 2;
358
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
359
    
cleanup
Yuki Kimoto authored on 2011-04-02
360
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
361
    my $p = delete $args{param} || {};
362
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
363
    my $tables = delete $args{table} || [];
364
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
365
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
366
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
367
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
368
    $type = _array_to_hash($type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
369
    my $type_rule_off = delete $args{type_rule_off};
cleanup
Yuki Kimoto authored on 2011-06-09
370
    my $query_return = delete $args{query};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
371
    
cleanup
Yuki Kimoto authored on 2011-03-09
372
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
373
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
374
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
375
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
376
    }
377
    
cleanup
Yuki Kimoto authored on 2011-04-02
378
    # Create query
379
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
380
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
381
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
382
    
cleanup
Yuki Kimoto authored on 2011-04-02
383
    # Tables
384
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
385
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
386
    $tables = $self->_remove_duplicate_table($tables, $main_table);
387
    if (my $q = $self->reserved_word_quote) {
388
        $_ =~ s/$q//g for @$tables;
389
    }
cleanup
Yuki Kimoto authored on 2011-04-02
390
    
391
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
392
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
393
        
cleanup
Yuki Kimoto authored on 2011-04-02
394
        # No need
395
        next unless my $alias = $self->{_table_alias}->{$table};
396
        $self->{filter} ||= {};
397
        next if $self->{filter}{out}{$table};
398
        
399
        # Filter
400
        $self->{filter}{out} ||= {};
401
        $self->{filter}{in}  ||= {};
402
        $self->{filter}{end} ||= {};
403
        
404
        # Create alias filter
405
        foreach my $type (qw/out in end/) {
406
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
407
            foreach my $filter_name (@filter_names) {
408
                my $filter_name_alias = $filter_name;
409
                $filter_name_alias =~ s/^$alias\./$table\./;
410
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
cleanup
Yuki Kimoto authored on 2011-06-13
411
                $filter_name_alias =~ s/^${alias}-/${table}-/; 
cleanup
Yuki Kimoto authored on 2011-04-02
412
                $self->{filter}{$type}{$table}{$filter_name_alias}
413
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
414
            }
415
        }
416
    }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
417

            
418
    # Type rule
419
    my $applied_filter = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
420
    unless ($type_rule_off) {
421
        foreach my $name (keys %$param) {
422
            my $table;
423
            my $column;
424
            if ($name =~ /(?:(.+)\.)?(.+)/) {
425
                $table = $1;
426
                $column = $2;
427
            }
428
            $table ||= $main_table;
429
            
430
            my $into = $self->{_into} || {};
431
            if (defined $table && $into->{$table} &&
432
                (my $rule = $into->{$table}->{$column}))
433
            {
434
                $applied_filter->{$column} = $rule;
435
                $applied_filter->{"$table.$column"} = $rule;
436
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
437
        }
438
    }
cleanup
Yuki Kimoto authored on 2011-04-02
439
    
440
    # Applied filter
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
441
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
442
        $applied_filter = {
443
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
444
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
445
        }
446
    }
cleanup
Yuki Kimoto authored on 2011-04-02
447
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
448
    
cleanup
Yuki Kimoto authored on 2011-04-02
449
    # Replace filter name to code
450
    foreach my $column (keys %$filter) {
451
        my $name = $filter->{$column};
452
        if (!defined $name) {
453
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
454
        }
cleanup
Yuki Kimoto authored on 2011-04-02
455
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
456
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
457
            unless exists $self->filters->{$name};
458
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
459
        }
460
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
461
    
cleanup
Yuki Kimoto authored on 2011-04-02
462
    # Create bind values
463
    my $bind = $self->_create_bind_values(
464
        $param,
465
        $query->columns,
466
        $filter,
467
        $type
468
    );
cleanup
yuki-kimoto authored on 2010-10-17
469
    
470
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
471
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
472
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
473
    eval {
474
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
475
            my $type = $bind->[$i]->{type};
476
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
477
        }
478
        $affected = $sth->execute;
479
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
480
    
481
    if ($@) {
482
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
483
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
484
    }
cleanup
yuki-kimoto authored on 2010-10-17
485
    
improved debug message
Yuki Kimoto authored on 2011-05-23
486
    # DEBUG message
487
    if (DEBUG) {
488
        print STDERR "SQL:\n" . $query->sql . "\n";
489
        my @output;
490
        foreach my $b (@$bind) {
491
            my $value = $b->{value};
492
            $value = 'undef' unless defined $value;
493
            $value = encode(DEBUG_ENCODING(), $value)
494
              if utf8::is_utf8($value);
495
            push @output, $value;
496
        }
497
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
498
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
499
    
cleanup
Yuki Kimoto authored on 2011-04-02
500
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
501
    if ($sth->{NUM_OF_FIELDS}) {
502
        
cleanup
Yuki Kimoto authored on 2011-04-02
503
        # Filter
504
        my $filter = {};
505
        $filter->{in}  = {};
506
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
507
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
508
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
509
            foreach my $way (qw/in end/) {
510
                $filter->{$way} = {
511
                    %{$filter->{$way}},
512
                    %{$self->{filter}{$way}{$table} || {}}
513
                };
514
            }
cleanup
Yuki Kimoto authored on 2011-01-12
515
        }
516
        
517
        # Result
518
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
519
            sth => $sth,
520
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
521
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
522
            filter => $filter->{in} || {},
523
            end_filter => $filter->{end} || {},
524
            type_rule => $self->type_rule,
cleanup
yuki-kimoto authored on 2010-10-17
525
        );
526

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
534
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param/;
update pod
Yuki Kimoto authored on 2011-03-13
535

            
cleanup
yuki-kimoto authored on 2010-10-17
536
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
537
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
538
    
cleanup
yuki-kimoto authored on 2010-10-17
539
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
540
    my $param;
541
    $param = shift if @_ % 2;
542
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
543
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
544
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
545
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
546
    my $p = delete $args{param} || {};
547
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
548
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
549
    my $id = delete $args{id};
550
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
551
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
552
          "must be specified when id is specified " . _subname
553
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
554
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
555

            
556
    # Check arguments
557
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
558
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
559
          unless $INSERT_ARGS{$name};
560
    }
561

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
562
    # Merge parameter
563
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
564
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
565
        $param = $self->merge_param($id_param, $param);
566
    }
567

            
cleanup
Yuki Kimoto authored on 2011-04-02
568
    # Reserved word quote
569
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
570
    
cleanup
Yuki Kimoto authored on 2011-04-02
571
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
572
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
573
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
574
    push @sql, $append if $append;
575
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
576
    
577
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
578
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
579
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
580
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
581
        table => $table,
582
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
583
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
584
}
585

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
586
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
587
    my ($self, $param) = @_;
588
    
cleanup
Yuki Kimoto authored on 2011-04-02
589
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
590
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
591
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
592
    my @columns;
593
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
594
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
595
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
596
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
597
        my $column_quote = "$q$column$q";
598
        $column_quote =~ s/\./$q.$q/;
599
        push @columns, $column_quote;
600
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
601
    }
602
    
cleanup
Yuki Kimoto authored on 2011-04-02
603
    return '(' . join(', ', @columns) . ') ' . 'values ' .
604
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
605
}
606

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
607
sub include_model {
608
    my ($self, $name_space, $model_infos) = @_;
609
    
cleanup
Yuki Kimoto authored on 2011-04-02
610
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
611
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
612
    
613
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
614
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
615

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
616
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
617
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
618
          if $name_space =~ /[^\w:]/;
619
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
620
        croak qq{Name space module "$name_space.pm" is needed. $@ }
621
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
622
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
623
        
624
        # Search model modules
625
        my $path = $INC{"$name_space.pm"};
626
        $path =~ s/\.pm$//;
627
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
628
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
629
        $model_infos = [];
630
        while (my $module = readdir $dh) {
631
            push @$model_infos, $module
632
              if $module =~ s/\.pm$//;
633
        }
634
        close $dh;
635
    }
636
    
cleanup
Yuki Kimoto authored on 2011-04-02
637
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
638
    foreach my $model_info (@$model_infos) {
639
        
cleanup
Yuki Kimoto authored on 2011-04-02
640
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
641
        my $model_class;
642
        my $model_name;
643
        my $model_table;
644
        if (ref $model_info eq 'HASH') {
645
            $model_class = $model_info->{class};
646
            $model_name  = $model_info->{name};
647
            $model_table = $model_info->{table};
648
            
649
            $model_name  ||= $model_class;
650
            $model_table ||= $model_name;
651
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
652
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
653
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
654
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
655
          if $mclass =~ /[^\w:]/;
656
        unless ($mclass->can('isa')) {
657
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
658
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
659
        }
660
        
cleanup
Yuki Kimoto authored on 2011-04-02
661
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
662
        my $args = {};
663
        $args->{model_class} = $mclass if $mclass;
664
        $args->{name}        = $model_name if $model_name;
665
        $args->{table}       = $model_table if $model_table;
666
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
667
    }
668
    
669
    return $self;
670
}
671

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
672
sub merge_param {
673
    my ($self, @params) = @_;
674
    
cleanup
Yuki Kimoto authored on 2011-04-02
675
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
676
    my $merge = {};
677
    foreach my $param (@params) {
678
        foreach my $column (keys %$param) {
679
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
680
            
681
            if (exists $merge->{$column}) {
682
                $merge->{$column} = [$merge->{$column}]
683
                  unless ref $merge->{$column} eq 'ARRAY';
684
                push @{$merge->{$column}},
685
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
686
            }
687
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
688
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
689
            }
690
        }
691
    }
692
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
693
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
694
}
695

            
cleanup
Yuki Kimoto authored on 2011-03-21
696
sub method {
697
    my $self = shift;
698
    
cleanup
Yuki Kimoto authored on 2011-04-02
699
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
700
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
701
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
702
    
703
    return $self;
704
}
705

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
706
sub model {
707
    my ($self, $name, $model) = @_;
708
    
cleanup
Yuki Kimoto authored on 2011-04-02
709
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
710
    if ($model) {
711
        $self->models->{$name} = $model;
712
        return $self;
713
    }
714
    
715
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
716
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
717
      unless $self->models->{$name};
718
    
cleanup
Yuki Kimoto authored on 2011-04-02
719
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
720
    return $self->models->{$name};
721
}
722

            
cleanup
Yuki Kimoto authored on 2011-03-21
723
sub mycolumn {
724
    my ($self, $table, $columns) = @_;
725
    
cleanup
Yuki Kimoto authored on 2011-04-02
726
    # Create column clause
727
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
728
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
729
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
730
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
731
    
732
    return join (', ', @column);
733
}
734

            
added dbi_options attribute
kimoto authored on 2010-12-20
735
sub new {
736
    my $self = shift->SUPER::new(@_);
737
    
cleanup
Yuki Kimoto authored on 2011-04-02
738
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
739
    my @attrs = keys %$self;
740
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
741
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
742
          unless $self->can($attr);
743
    }
cleanup
Yuki Kimoto authored on 2011-04-02
744
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
745
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
746
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
747
        '?'     => \&DBIx::Custom::Tag::placeholder,
748
        '='     => \&DBIx::Custom::Tag::equal,
749
        '<>'    => \&DBIx::Custom::Tag::not_equal,
750
        '>'     => \&DBIx::Custom::Tag::greater_than,
751
        '<'     => \&DBIx::Custom::Tag::lower_than,
752
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
753
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
754
        'like'  => \&DBIx::Custom::Tag::like,
755
        'in'    => \&DBIx::Custom::Tag::in,
756
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
757
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
758
    };
added dbi_options attribute
kimoto authored on 2010-12-20
759
    
760
    return $self;
761
}
762

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
763
sub not_exists { bless {}, 'DBIx::Custom::NotExists' }
764

            
cleanup
yuki-kimoto authored on 2010-10-17
765
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
766
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
767
    
768
    # Register filter
769
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
770
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
771
    
cleanup
Yuki Kimoto authored on 2011-04-02
772
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
773
}
packaging one directory
yuki-kimoto authored on 2009-11-16
774

            
cleanup
Yuki Kimoto authored on 2011-03-21
775
our %SELECT_ARGS
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
776
  = map { $_ => 1 } @COMMON_ARGS,
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
777
                    qw/column where relation join param where_param wrap
778
                       prefix/;
refactoring select
yuki-kimoto authored on 2010-04-28
779

            
packaging one directory
yuki-kimoto authored on 2009-11-16
780
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
781
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
782

            
refactoring select
yuki-kimoto authored on 2010-04-28
783
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
784
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
785
    my $tables = ref $table eq 'ARRAY' ? $table
786
               : defined $table ? [$table]
787
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
788
    my $columns   = delete $args{column};
789
    my $where     = delete $args{where} || {};
790
    my $append    = delete $args{append};
791
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
792
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
793
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
794
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
795
    warn "select() relation option is DEPRECATED! use join option instead"
796
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
797
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
798
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
799
      if keys %$param;
800
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
801
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
802
    my $id = delete $args{id};
803
    my $primary_key = delete $args{primary_key};
804
    croak "update method primary_key option " .
805
          "must be specified when id is specified " . _subname
806
      if defined $id && !defined $primary_key;
807
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
808
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
809
    
cleanup
Yuki Kimoto authored on 2011-04-02
810
    # Check arguments
811
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
812
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
813
          unless $SELECT_ARGS{$name};
814
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
815
    
cleanup
Yuki Kimoto authored on 2011-03-09
816
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
817
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
818
    
cleanup
Yuki Kimoto authored on 2011-04-02
819
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
820
    my @sql;
821
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
822
    
- select() column option can...
Yuki Kimoto authored on 2011-06-08
823
    # Reserved word quote
824
    my $q = $self->reserved_word_quote;
825
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
826
    # Prefix
827
    push @sql, $prefix if defined $prefix;
828
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
829
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
830
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
831
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
832
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
833
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
834
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
835
            }
836
            elsif (ref $column eq 'ARRAY') {
837
                croak "Format must be [COLUMN, as => ALIAS] " . _subname
838
                  unless @$column == 3 && $column->[1] eq 'as';
839
                $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
840
            }
cleanup
Yuki Kimoto authored on 2011-04-02
841
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
842
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
843
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
844
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
845
    }
846
    else { push @sql, '*' }
847
    
848
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
849
    push @sql, 'from';
850
    if ($relation) {
851
        my $found = {};
852
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
853
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
854
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
855
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
856
    }
cleanup
Yuki Kimoto authored on 2011-03-30
857
    else {
858
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
859
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
860
    }
861
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
862
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
863
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
864

            
cleanup
Yuki Kimoto authored on 2011-04-02
865
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
866
    unshift @$tables,
867
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
868
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
869
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
870
    my $where_clause = '';
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
871
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
cleanup
Yuki Kimoto authored on 2011-04-25
872
    if (ref $where) {
873
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
874
        $where_param = keys %$where_param
875
                     ? $self->merge_param($where_param, $where->param)
876
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
877
        
878
        # String where
879
        $where_clause = $where->to_string;
880
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
881
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
882
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
883
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
884
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
885
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
886
    # Push join
887
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
888
    
cleanup
Yuki Kimoto authored on 2011-03-09
889
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
890
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
891
    
cleanup
Yuki Kimoto authored on 2011-03-08
892
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
893
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
894
    
cleanup
Yuki Kimoto authored on 2011-04-02
895
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
896
    push @sql, $append if $append;
897
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
898
    # Wrap
899
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
900
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
901
          unless ref $wrap eq 'ARRAY';
902
        unshift @sql, $wrap->[0];
903
        push @sql, $wrap->[1];
904
    }
905
    
cleanup
Yuki Kimoto authored on 2011-01-27
906
    # SQL
907
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
908
    
909
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
910
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
911
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
912
        param => $where_param, 
cleanup
Yuki Kimoto authored on 2011-03-21
913
        table => $tables,
914
        %args
915
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
916
    
917
    return $result;
918
}
919

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
920
sub separator {
921
    my $self = shift;
922
    
923
    if (@_) {
924
        my $separator = $_[0] || '';
925
        croak qq{Separator must be "." or "__" or "-" } . _subname
926
          unless $separator eq '.' || $separator eq '__'
927
              || $separator eq '-';
928
        
929
        $self->{separator} = $separator;
930
    
931
        return $self;
932
    }
933
    return $self->{separator} ||= '.';
934
}
935

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

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
951
sub available_data_type {
952
    my $self = shift;
953
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
954
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
955
    foreach my $i (-1000 .. 1000) {
956
         my $type_info = $self->dbh->type_info($i);
957
         my $data_type = $type_info->{DATA_TYPE};
958
         my $type_name = $type_info->{TYPE_NAME};
959
         $data_types .= "$data_type ($type_name)\n"
960
           if defined $data_type;
961
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
962
    return "Data Type maybe equal to Type Name" unless $data_types;
963
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
964
    return $data_types;
965
}
966

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
967
sub type_rule {
968
    my $self = shift;
969
    
970
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
971
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
972
        
973
        # Into
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
974
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
975
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
976
        $self->{_into} ||= {};
977
        $self->each_column(sub {
978
            my ($dbi, $table, $column, $column_info) = @_;
979
            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
980
            my $type_name = $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
981
            if ($type_rule->{into} &&
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
982
                (my $filter = $type_rule->{into}->{$type_name}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
983
            {
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
984
                return unless exists $type_rule->{into}->{$type_name};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
985
                if  (defined $filter && ref $filter ne 'CODE') 
986
                {
987
                    my $fname = $filter;
988
                    croak qq{Filter "$fname" is not registered" } . _subname
989
                      unless exists $self->filters->{$fname};
990
                    
991
                    $filter = $self->filters->{$fname};
992
                }
993

            
994
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
995
            }
996
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
997
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
998

            
999
        # From
1000
        $type_rule->{from} = _array_to_hash($type_rule->{from});
1001
        foreach my $data_type (keys %{$type_rule->{from} || {}}) {
1002
            my $fname = $type_rule->{from}{$data_type};
1003
            if (defined $fname && ref $fname ne 'CODE') {
1004
                croak qq{Filter "$fname" is not registered" } . _subname
1005
                  unless exists $self->filters->{$fname};
1006
                
1007
                $type_rule->{from}{$data_type} = $self->filters->{$fname};
1008
            }
1009
        }
1010
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1011
        return $self;
1012
    }
1013
    
1014
    return $self->{type_rule} || {};
1015
}
1016

            
cleanup
Yuki Kimoto authored on 2011-03-21
1017
our %UPDATE_ARGS
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1018
  = map { $_ => 1 } @COMMON_ARGS, qw/param where allow_update_all where_param/;
cleanup
yuki-kimoto authored on 2010-10-17
1019

            
1020
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1021
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1022

            
cleanup
yuki-kimoto authored on 2010-10-17
1023
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1024
    my $param;
1025
    $param = shift if @_ % 2;
1026
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1027
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1028
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1029
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1030
    my $p = delete $args{param} || {};
1031
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1032
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1033
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1034
    my $append           = delete $args{append} || '';
1035
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1036
    my $id = delete $args{id};
1037
    my $primary_key = delete $args{primary_key};
1038
    croak "update method primary_key option " .
1039
          "must be specified when id is specified " . _subname
1040
      if defined $id && !defined $primary_key;
1041
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1042
    
cleanup
Yuki Kimoto authored on 2011-04-02
1043
    # Check argument names
1044
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1045
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1046
          unless $UPDATE_ARGS{$name};
1047
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1048

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

            
1052
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1053
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1054
    my $where_clause = '';
1055
    if (ref $where) {
1056
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1057
        $where_param = keys %$where_param
1058
                     ? $self->merge_param($where_param, $where->param)
1059
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1060
        
1061
        # String where
1062
        $where_clause = $where->to_string;
1063
    }
1064
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1065
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1066
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1067
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1068
    # Merge param
1069
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1070
    
cleanup
Yuki Kimoto authored on 2011-04-02
1071
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1072
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1073
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1074
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1075
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1076
    
cleanup
Yuki Kimoto authored on 2011-01-27
1077
    # SQL
1078
    my $sql = join(' ', @sql);
1079
    
cleanup
yuki-kimoto authored on 2010-10-17
1080
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1081
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1082
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1083
        param  => $param, 
1084
        table => $table,
1085
        %args
1086
    );
cleanup
yuki-kimoto authored on 2010-10-17
1087
    
1088
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1089
}
1090

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1093
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1094
    my ($self, $param, $opt) = @_;
1095
    
cleanup
Yuki Kimoto authored on 2011-04-02
1096
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1097
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1098
    $tag = "set $tag" unless $opt->{no_set};
1099

            
cleanup
Yuki Kimoto authored on 2011-04-02
1100
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1101
}
1102

            
cleanup
Yuki Kimoto authored on 2011-01-25
1103
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1104
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1105
    
1106
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1107
    return DBIx::Custom::Where->new(
1108
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1109
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1110
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1111
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1112
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1113
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1114

            
cleanup
Yuki Kimoto authored on 2011-06-13
1115
sub _apply_filter {
1116
    my ($self, $table, @cinfos) = @_;
1117

            
1118
    # Initialize filters
1119
    $self->{filter} ||= {};
1120
    $self->{filter}{out} ||= {};
1121
    $self->{filter}{in} ||= {};
1122
    $self->{filter}{end} ||= {};
1123
    
1124
    # Usage
1125
    my $usage = "Usage: \$dbi->apply_filter(" .
1126
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1127
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1128
    
1129
    # Apply filter
1130
    for (my $i = 0; $i < @cinfos; $i += 2) {
1131
        
1132
        # Column
1133
        my $column = $cinfos[$i];
1134
        if (ref $column eq 'ARRAY') {
1135
            foreach my $c (@$column) {
1136
                push @cinfos, $c, $cinfos[$i + 1];
1137
            }
1138
            next;
1139
        }
1140
        
1141
        # Filter infomation
1142
        my $finfo = $cinfos[$i + 1] || {};
1143
        croak "$usage (table: $table) " . _subname
1144
          unless  ref $finfo eq 'HASH';
1145
        foreach my $ftype (keys %$finfo) {
1146
            croak "$usage (table: $table) " . _subname
1147
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1148
        }
1149
        
1150
        # Set filters
1151
        foreach my $way (qw/in out end/) {
1152
        
1153
            # Filter
1154
            my $filter = $finfo->{$way};
1155
            
1156
            # Filter state
1157
            my $state = !exists $finfo->{$way} ? 'not_exists'
1158
                      : !defined $filter        ? 'not_defined'
1159
                      : ref $filter eq 'CODE'   ? 'code'
1160
                      : 'name';
1161
            
1162
            # Filter is not exists
1163
            next if $state eq 'not_exists';
1164
            
1165
            # Check filter name
1166
            croak qq{Filter "$filter" is not registered } . _subname
1167
              if  $state eq 'name'
1168
               && ! exists $self->filters->{$filter};
1169
            
1170
            # Set filter
1171
            my $f = $state eq 'not_defined' ? undef
1172
                  : $state eq 'code'        ? $filter
1173
                  : $self->filters->{$filter};
1174
            $self->{filter}{$way}{$table}{$column} = $f;
1175
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1176
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1177
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1178
        }
1179
    }
1180
    
1181
    return $self;
1182
}
1183

            
cleanup
Yuki Kimoto authored on 2011-04-02
1184
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1185
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1186
    
cleanup
Yuki Kimoto authored on 2011-04-02
1187
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1188
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1189
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1190
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1191
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1192
        
1193
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1194
        my $value;
1195
        if(ref $params->{$column} eq 'ARRAY') {
1196
            my $i = $count->{$column} || 0;
1197
            $i += $not_exists->{$column} || 0;
1198
            my $found;
1199
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1200
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1201
                    $not_exists->{$column}++;
1202
                }
1203
                else  {
1204
                    $value = $params->{$column}->[$k];
1205
                    $found = 1;
1206
                    last
1207
                }
1208
            }
1209
            next unless $found;
1210
        }
1211
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1212
        
cleanup
Yuki Kimoto authored on 2011-01-12
1213
        # Filter
1214
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1215
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1216
        # Type
1217
        push @$bind, {
1218
            value => $f ? $f->($value) : $value,
1219
            type => $type->{$column}
1220
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1221
        
1222
        # Count up 
1223
        $count->{$column}++;
1224
    }
1225
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1226
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1227
}
1228

            
cleanup
Yuki Kimoto authored on 2011-06-08
1229
sub _create_param_from_id {
1230
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1231
    
cleanup
Yuki Kimoto authored on 2011-06-08
1232
    # Create parameter
1233
    my $param = {};
1234
    if ($id) {
1235
        $id = [$id] unless ref $id;
1236
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1237
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1238
          unless !ref $id || ref $id eq 'ARRAY';
1239
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1240
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1241
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1242
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1243
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1244
        }
1245
    }
1246
    
cleanup
Yuki Kimoto authored on 2011-06-08
1247
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1248
}
1249

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1250
sub _connect {
1251
    my $self = shift;
1252
    
1253
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1254
    my $dsn = $self->data_source;
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1255
    warn "data_source is DEPRECATED! use dsn instead\n"
1256
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1257
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1258
    croak qq{"dsn" must be specified } . _subname
1259
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1260
    my $user        = $self->user;
1261
    my $password    = $self->password;
1262
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1263
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1264
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1265
    
1266
    # Connect
1267
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1268
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1269
        $user,
1270
        $password,
1271
        {
1272
            %{$self->default_dbi_option},
1273
            %$dbi_option
1274
        }
1275
    )};
1276
    
1277
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1278
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1279
    
1280
    return $dbh;
1281
}
1282

            
cleanup
yuki-kimoto authored on 2010-10-17
1283
sub _croak {
1284
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1285
    
1286
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1287
    $append ||= "";
1288
    
1289
    # Verbose
1290
    if ($Carp::Verbose) { croak $error }
1291
    
1292
    # Not verbose
1293
    else {
1294
        
1295
        # Remove line and module infromation
1296
        my $at_pos = rindex($error, ' at ');
1297
        $error = substr($error, 0, $at_pos);
1298
        $error =~ s/\s+$//;
1299
        croak "$error$append";
1300
    }
1301
}
1302

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1303
sub _need_tables {
1304
    my ($self, $tree, $need_tables, $tables) = @_;
1305
    
cleanup
Yuki Kimoto authored on 2011-04-02
1306
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1307
    foreach my $table (@$tables) {
1308
        if ($tree->{$table}) {
1309
            $need_tables->{$table} = 1;
1310
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1311
        }
1312
    }
1313
}
1314

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1315
sub _push_join {
1316
    my ($self, $sql, $join, $join_tables) = @_;
1317
    
cleanup
Yuki Kimoto authored on 2011-04-02
1318
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1319
    return unless @$join;
1320
    
cleanup
Yuki Kimoto authored on 2011-04-02
1321
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1322
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1323
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1324
    for (my $i = 0; $i < @$join; $i++) {
1325
        
cleanup
Yuki Kimoto authored on 2011-04-02
1326
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1327
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1328
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1329
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1330
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1331
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1332
            my $table1 = $1;
1333
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1334
            croak qq{right side table of "$join_clause" must be unique }
1335
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1336
              if exists $tree->{$table2};
1337
            $tree->{$table2}
1338
              = {position => $i, parent => $table1, join => $join_clause};
1339
        }
1340
        else {
improved error message
Yuki Kimoto authored on 2011-06-13
1341
            croak qq{join clause must have two table name after "on" keyword. } .
1342
                  qq{"$join_clause" is passed }  . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1343
        }
1344
    }
1345
    
cleanup
Yuki Kimoto authored on 2011-04-02
1346
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1347
    my $need_tables = {};
1348
    $self->_need_tables($tree, $need_tables, $join_tables);
1349
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1350
    
1351
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1352
    foreach my $need_table (@need_tables) {
1353
        push @$sql, $tree->{$need_table}{join};
1354
    }
1355
}
cleanup
Yuki Kimoto authored on 2011-03-08
1356

            
cleanup
Yuki Kimoto authored on 2011-04-02
1357
sub _remove_duplicate_table {
1358
    my ($self, $tables, $main_table) = @_;
1359
    
1360
    # Remove duplicate table
1361
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1362
    delete $tables{$main_table} if $main_table;
1363
    
1364
    return [keys %tables, $main_table ? $main_table : ()];
1365
}
1366

            
cleanup
Yuki Kimoto authored on 2011-04-02
1367
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1368
    my ($self, $source) = @_;
1369
    
cleanup
Yuki Kimoto authored on 2011-04-02
1370
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1371
    my $tables = [];
1372
    my $safety_character = $self->safety_character;
1373
    my $q = $self->reserved_word_quote;
1374
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1375
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1376
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1377
    while ($source =~ /$table_re/g) {
1378
        push @$tables, $1;
1379
    }
1380
    
1381
    return $tables;
1382
}
1383

            
cleanup
Yuki Kimoto authored on 2011-04-02
1384
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1385
    my ($self, $where) = @_;
1386
    
cleanup
Yuki Kimoto authored on 2011-04-02
1387
    my $obj;
1388
    
1389
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1390
    if (ref $where eq 'HASH') {
1391
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1392
        my $q = $self->reserved_word_quote;
1393
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1394
            my $column_quote = "$q$column$q";
1395
            $column_quote =~ s/\./$q.$q/;
1396
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1397
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1398
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1399
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1400
    
1401
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1402
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1403
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1404
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1405
    
1406
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1407
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1408
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1409
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1410
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1411
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1412
            clause => $where->[0],
1413
            param  => $where->[1]
1414
        );
1415
    }
1416
    
cleanup
Yuki Kimoto authored on 2011-04-02
1417
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1418
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1419
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1420
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1421
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1422
    
cleanup
Yuki Kimoto authored on 2011-04-02
1423
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1424
}
1425

            
cleanup
Yuki Kimoto authored on 2011-06-13
1426
# DEPRECATED!
1427
sub apply_filter {
1428
    my $self = shift;
1429
    
1430
    warn "apply_filter is DEPRECATED! " . 
1431
         "use type_rule method, DBIx::Custom::Result filter method, " .
1432
         "and DBIx::Custom::Model result_filter method instead";
1433
    
1434
    return $self->_apply_filter(@_);
1435
}
1436

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1437
# DEPRECATED!
1438
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1439
sub select_at {
1440
    my ($self, %args) = @_;
1441

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1444
    # Arguments
1445
    my $primary_keys = delete $args{primary_key};
1446
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1447
    my $where = delete $args{where};
1448
    my $param = delete $args{param};
1449
    
1450
    # Check arguments
1451
    foreach my $name (keys %args) {
1452
        croak qq{"$name" is wrong option } . _subname
1453
          unless $SELECT_AT_ARGS{$name};
1454
    }
1455
    
1456
    # Table
1457
    croak qq{"table" option must be specified } . _subname
1458
      unless $args{table};
1459
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1460
    
1461
    # Create where parameter
1462
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1463
    
1464
    return $self->select(where => $where_param, %args);
1465
}
1466

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1467
# DEPRECATED!
1468
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1469
sub delete_at {
1470
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1471

            
1472
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1473
    
1474
    # Arguments
1475
    my $primary_keys = delete $args{primary_key};
1476
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1477
    my $where = delete $args{where};
1478
    
1479
    # Check arguments
1480
    foreach my $name (keys %args) {
1481
        croak qq{"$name" is wrong option } . _subname
1482
          unless $DELETE_AT_ARGS{$name};
1483
    }
1484
    
1485
    # Create where parameter
1486
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1487
    
1488
    return $self->delete(where => $where_param, %args);
1489
}
1490

            
cleanup
Yuki Kimoto authored on 2011-06-08
1491
# DEPRECATED!
1492
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1493
sub update_at {
1494
    my $self = shift;
1495

            
1496
    warn "update_at is DEPRECATED! use update and id option instead";
1497
    
1498
    # Arguments
1499
    my $param;
1500
    $param = shift if @_ % 2;
1501
    my %args = @_;
1502
    my $primary_keys = delete $args{primary_key};
1503
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1504
    my $where = delete $args{where};
1505
    my $p = delete $args{param} || {};
1506
    $param  ||= $p;
1507
    
1508
    # Check arguments
1509
    foreach my $name (keys %args) {
1510
        croak qq{"$name" is wrong option } . _subname
1511
          unless $UPDATE_AT_ARGS{$name};
1512
    }
1513
    
1514
    # Create where parameter
1515
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1516
    
1517
    return $self->update(where => $where_param, param => $param, %args);
1518
}
1519

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1520
# DEPRECATED!
1521
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1522
sub insert_at {
1523
    my $self = shift;
1524
    
1525
    warn "insert_at is DEPRECATED! use insert and id option instead";
1526
    
1527
    # Arguments
1528
    my $param;
1529
    $param = shift if @_ % 2;
1530
    my %args = @_;
1531
    my $primary_key = delete $args{primary_key};
1532
    $primary_key = [$primary_key] unless ref $primary_key;
1533
    my $where = delete $args{where};
1534
    my $p = delete $args{param} || {};
1535
    $param  ||= $p;
1536
    
1537
    # Check arguments
1538
    foreach my $name (keys %args) {
1539
        croak qq{"$name" is wrong option } . _subname
1540
          unless $INSERT_AT_ARGS{$name};
1541
    }
1542
    
1543
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1544
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1545
    $param = $self->merge_param($where_param, $param);
1546
    
1547
    return $self->insert(param => $param, %args);
1548
}
1549

            
added warnings
Yuki Kimoto authored on 2011-06-07
1550
# DEPRECATED!
1551
sub register_tag {
1552
    warn "register_tag is DEPRECATED!";
1553
    shift->query_builder->register_tag(@_)
1554
}
1555

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1556
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1557
has 'data_source';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1558

            
cleanup
Yuki Kimoto authored on 2011-01-25
1559
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1560
has dbi_options => sub { {} },
1561
    filter_check  => 1;
1562

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1563

            
cleanup
Yuki Kimoto authored on 2011-01-25
1564
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1565
sub default_bind_filter {
1566
    my $self = shift;
1567
    
cleanup
Yuki Kimoto authored on 2011-06-13
1568
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1569
    
cleanup
Yuki Kimoto authored on 2011-01-12
1570
    if (@_) {
1571
        my $fname = $_[0];
1572
        
1573
        if (@_ && !$fname) {
1574
            $self->{default_out_filter} = undef;
1575
        }
1576
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1577
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1578
              unless exists $self->filters->{$fname};
1579
        
1580
            $self->{default_out_filter} = $self->filters->{$fname};
1581
        }
1582
        return $self;
1583
    }
1584
    
1585
    return $self->{default_out_filter};
1586
}
1587

            
cleanup
Yuki Kimoto authored on 2011-01-25
1588
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1589
sub default_fetch_filter {
1590
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1591

            
cleanup
Yuki Kimoto authored on 2011-06-13
1592
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1593
    
1594
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1595
        my $fname = $_[0];
1596

            
cleanup
Yuki Kimoto authored on 2011-01-12
1597
        if (@_ && !$fname) {
1598
            $self->{default_in_filter} = undef;
1599
        }
1600
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1601
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1602
              unless exists $self->filters->{$fname};
1603
        
1604
            $self->{default_in_filter} = $self->filters->{$fname};
1605
        }
1606
        
1607
        return $self;
1608
    }
1609
    
many changed
Yuki Kimoto authored on 2011-01-23
1610
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1611
}
1612

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1613
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1614
sub insert_param_tag {
1615
    warn "insert_param_tag is DEPRECATED! " .
1616
         "use insert_param instead!";
1617
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1618
}
1619

            
cleanup
Yuki Kimoto authored on 2011-01-25
1620
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1621
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1622
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1623
    return shift->query_builder->register_tag_processor(@_);
1624
}
1625

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1626
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1627
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1628
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1629
         "use update_param instead";
1630
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1631
}
cleanup
Yuki Kimoto authored on 2011-03-08
1632
# DEPRECATED!
1633
sub _push_relation {
1634
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1635
    
1636
    if (keys %{$relation || {}}) {
1637
        push @$sql, $need_where ? 'where' : 'and';
1638
        foreach my $rcolumn (keys %$relation) {
1639
            my $table1 = (split (/\./, $rcolumn))[0];
1640
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1641
            push @$tables, ($table1, $table2);
1642
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1643
        }
1644
    }
1645
    pop @$sql if $sql->[-1] eq 'and';    
1646
}
1647

            
1648
# DEPRECATED!
1649
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1650
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1651
    
1652
    if (keys %{$relation || {}}) {
1653
        foreach my $rcolumn (keys %$relation) {
1654
            my $table1 = (split (/\./, $rcolumn))[0];
1655
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1656
            my $table1_exists;
1657
            my $table2_exists;
1658
            foreach my $table (@$tables) {
1659
                $table1_exists = 1 if $table eq $table1;
1660
                $table2_exists = 1 if $table eq $table2;
1661
            }
1662
            unshift @$tables, $table1 unless $table1_exists;
1663
            unshift @$tables, $table2 unless $table2_exists;
1664
        }
1665
    }
1666
}
1667

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1670
=head1 NAME
1671

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1672
DBIx::Custom - Useful database access, respecting SQL!
removed reconnect method
yuki-kimoto authored on 2010-05-28
1673

            
1674
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1675

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1676
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1677
    
1678
    # Connect
1679
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1680
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1681
        user => 'ken',
1682
        password => '!LFKD%$&',
1683
        dbi_option => {mysql_enable_utf8 => 1}
1684
    );
cleanup
yuki-kimoto authored on 2010-08-05
1685

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1686
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1687
    $dbi->insert(
1688
        table  => 'book',
1689
        param  => {title => 'Perl', author => 'Ken'}
1690
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1691
    
1692
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1693
    $dbi->update(
1694
        table  => 'book', 
1695
        param  => {title => 'Perl', author => 'Ken'}, 
1696
        where  => {id => 5},
1697
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1698
    
1699
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1700
    $dbi->delete(
1701
        table  => 'book',
1702
        where  => {author => 'Ken'},
1703
    );
cleanup
yuki-kimoto authored on 2010-08-05
1704

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1705
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1706
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1707
        table  => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
1708
        column => ['title', 'author'],
update document
yuki-kimoto authored on 2010-05-27
1709
        where  => {author => 'Ken'},
added commit method
yuki-kimoto authored on 2010-05-27
1710
    );
cleanup
yuki-kimoto authored on 2010-08-05
1711

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1712
    # Select, more complex
1713
    my $result = $dbi->select(
1714
        table  => 'book',
1715
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1716
            {book => [qw/title author/]},
1717
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1718
        ],
1719
        where  => {'book.author' => 'Ken'},
1720
        join => ['left outer join company on book.company_id = company.id'],
1721
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1722
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1723
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1724
    # Fetch
1725
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1726
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1727
    }
1728
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1729
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1730
    while (my $row = $result->fetch_hash) {
1731
        
1732
    }
1733
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1734
    # Execute SQL with parameter.
1735
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1736
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1737
        param  => {author => 'ken', title => '%Perl%'}
1738
    );
1739
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1740
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1741

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1742
L<DBIx::Custom> is L<DBI> wrapper module.
1743

            
1744
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1745

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1746
=over 4
removed reconnect method
yuki-kimoto authored on 2010-05-28
1747

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1748
=item *
removed reconnect method
yuki-kimoto authored on 2010-05-28
1749

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1750
There are many basic methods to execute various queries.
1751
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1752
C<delete_all()>, C<select()>,
- select() column option can...
Yuki Kimoto authored on 2011-06-08
1753
C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1754

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1755
=item *
1756

            
1757
Filter when data is send or receive.
1758

            
1759
=item *
1760

            
1761
Data filtering system
1762

            
1763
=item *
1764

            
1765
Model support.
1766

            
1767
=item *
1768

            
1769
Generate where clause dinamically.
1770

            
1771
=item *
1772

            
1773
Generate join clause dinamically.
1774

            
1775
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1776

            
1777
=head1 GUIDE
1778

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1779
L<DBIx::Custom::Guide> - L<DBIx::Custom> Guide
pod fix
Yuki Kimoto authored on 2011-01-21
1780

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1781
=head1 Wiki
pod fix
Yuki Kimoto authored on 2011-01-21
1782

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1783
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
updated document
yuki-kimoto authored on 2010-08-08
1784

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

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

            
1789
    my $connector = $dbi->connector;
1790
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1791

            
1792
Connection manager object. if connector is set, you can get C<dbh()>
1793
from connection manager. conection manager object must have dbh() mehtod.
1794

            
1795
This is L<DBIx::Connector> example. Please pass
1796
C<default_dbi_option> to L<DBIx::Connector>.
1797

            
1798
    my $connector = DBIx::Connector->new(
1799
        "dbi:mysql:database=$DATABASE",
1800
        $USER,
1801
        $PASSWORD,
1802
        DBIx::Custom->new->default_dbi_option
1803
    );
1804
    
1805
    my $dbi = DBIx::Custom->new(connector => $connector);
1806

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

            
1809
    my $dsn = $dbi->dsn;
1810
    $dbi    = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
1811

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1812
Data source name, used when C<connect()> is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1813

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1814
C<data_source> is DEPRECATED! It is renamed to C<dsn>.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1815

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1818
    my $dbi_option = $dbi->dbi_option;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1819
    $dbi           = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1820

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1821
L<DBI> option, used when C<connect()> is executed.
1822
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1823

            
1824
=head2 C<default_dbi_option>
1825

            
1826
    my $default_dbi_option = $dbi->default_dbi_option;
1827
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1828

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1829
L<DBI> default option, used when C<connect()> is executed,
1830
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1831

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1832
    {
1833
        RaiseError => 1,
1834
        PrintError => 0,
1835
        AutoCommit => 1,
1836
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1837

            
update pod
Yuki Kimoto authored on 2011-03-13
1838
You should not change C<AutoCommit> value directly,
1839
the value is used to check if the process is in transaction.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1840

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1843
    my $filters = $dbi->filters;
1844
    $dbi        = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
1845

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1846
Filters, registered by C<register_filter()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1847

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

            
1850
    my $models = $dbi->models;
1851
    $dbi       = $dbi->models(\%models);
1852

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1853
Models, included by C<include_model()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1854

            
cleanup
yuki-kimoto authored on 2010-10-17
1855
=head2 C<password>
1856

            
1857
    my $password = $dbi->password;
1858
    $dbi         = $dbi->password('lkj&le`@s');
1859

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1860
Password, used when C<connect()> is executed.
update document
yuki-kimoto authored on 2010-01-30
1861

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

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1864
    my $sql_class = $dbi->query_builder;
1865
    $dbi          = $dbi->query_builder(DBIx::Custom::QueryBuilder->new);
added commit method
yuki-kimoto authored on 2010-05-27
1866

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1867
Query builder, default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
1868

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1869
=head2 C<reserved_word_quote>
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1870

            
1871
     my reserved_word_quote = $dbi->reserved_word_quote;
1872
     $dbi                   = $dbi->reserved_word_quote('"');
1873

            
cleanup
Yuki Kimoto authored on 2011-04-02
1874
Reserved word quote, default to empty string.
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1875

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1878
    my $result_class = $dbi->result_class;
1879
    $dbi             = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
1880

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1885
    my $safety_character = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-03-10
1886
    $dbi                 = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
1887

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1893
    my $user = $dbi->user;
1894
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1895

            
cleanup
Yuki Kimoto authored on 2011-03-10
1896
User name, used when C<connect()> is executed.
update pod
Yuki Kimoto authored on 2011-01-27
1897

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

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

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1904
=head2 C<available_data_type> EXPERIMENTAL
1905

            
1906
    print $dbi->available_data_type;
1907

            
1908
Get available data type.
1909

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1920
=head2 C<column> EXPERIMETNAL
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1921

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

            
1924
Create column clause. The follwoing column clause is created.
1925

            
1926
    book.author as "book.author",
1927
    book.title as "book.title"
1928

            
cleanup
Yuki Kimoto authored on 2011-06-13
1929
You can change separator by C<separator> method.
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1930

            
cleanup
Yuki Kimoto authored on 2011-06-13
1931
    # Separator is double underbar
1932
    $dbi->separator('__');
1933
    
1934
    book.author as "book__author",
1935
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1936

            
cleanup
Yuki Kimoto authored on 2011-06-13
1937
    # Separator is hyphen
1938
    $dbi->separator('-');
1939
    
1940
    book.author as "book-author",
1941
    book.title as "book-title"
1942
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1943
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1944

            
update pod
Yuki Kimoto authored on 2011-03-13
1945
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1946
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1947
        user => 'ken',
1948
        password => '!LFKD%$&',
1949
        dbi_option => {mysql_enable_utf8 => 1}
1950
    );
1951

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1960
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1961
        table => 'book',
1962
        primary_key => 'id',
1963
        join => [
1964
            'inner join company on book.comparny_id = company.id'
1965
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1966
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1967
            publish_date => {
1968
                out => 'tp_to_date',
1969
                in => 'date_to_tp',
1970
                end => 'tp_to_displaydate'
1971
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1972
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1973
    );
1974

            
1975
Create L<DBIx::Custom::Model> object and initialize model.
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1976
the module is also used from model() method.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1977

            
1978
   $dbi->model('book')->select(...);
1979

            
cleanup
yuki-kimoto authored on 2010-10-17
1980
=head2 C<create_query>
1981
    
1982
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1983
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1984
    );
update document
yuki-kimoto authored on 2009-11-19
1985

            
update pod
Yuki Kimoto authored on 2011-03-13
1986
Create L<DBIx::Custom::Query> object.
1987

            
cleanup
yuki-kimoto authored on 2010-10-17
1988
If you want to get high performance,
update pod
Yuki Kimoto authored on 2011-03-13
1989
create L<DBIx::Custom::Query> object and execute the query by C<execute()>
1990
instead of other methods, such as C<insert>, C<update>.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1991

            
cleanup
yuki-kimoto authored on 2010-10-17
1992
    $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
version 0.0901
yuki-kimoto authored on 2009-12-17
1993

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

            
1996
    my $dbh = $dbi->dbh;
1997

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1998
Get L<DBI> database handle. if C<connector> is set, you can get
1999
database handle from C<connector>.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2000

            
2001
=head2 C<each_column>
2002

            
2003
    $dbi->each_column(
2004
        sub {
2005
            my ($dbi, $table, $column, $column_info) = @_;
2006
            
2007
            my $type = $column_info->{TYPE_NAME};
2008
            
2009
            if ($type eq 'DATE') {
2010
                # ...
2011
            }
2012
        }
2013
    );
2014

            
2015
Iterate all column informations of all table from database.
2016
Argument is callback when one column is found.
2017
Callback receive four arguments, dbi object, table name,
2018
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2019

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2022
    my $result = $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2023
        "select * from book where title = :title and author like :author",
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
2024
        {title => 'Perl', author => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2025
    );
2026

            
updated pod
Yuki Kimoto authored on 2011-06-09
2027
Execute SQL. SQL can contain parameter such as :author.
2028
Return value is L<DBIx::Custom::Result> when select statement is executed,
2029
or the count of affected rows in insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2030

            
updated pod
Yuki Kimoto authored on 2011-06-09
2031
Parameter is replaced by placeholder C<?>.
update pod
Yuki Kimoto authored on 2011-03-13
2032

            
2033
    select * from where title = ? and author like ?;
2034

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

            
2037
=over 4
2038

            
2039
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2040
    
2041
    filter => {
2042
        title  => sub { uc $_[0] }
2043
        author => sub { uc $_[0] }
2044
    }
update pod
Yuki Kimoto authored on 2011-03-13
2045

            
updated pod
Yuki Kimoto authored on 2011-06-09
2046
    # Filter name
2047
    filter => {
2048
        title  => 'upper_case',
2049
        author => 'upper_case'
2050
    }
2051
        
2052
    # At once
2053
    filter => [
2054
        [qw/title author/]  => sub { uc $_[0] }
2055
    ]
2056

            
2057
Filter, executed before data is saved into database.
update pod
Yuki Kimoto authored on 2011-03-13
2058
Filter value is code reference or
2059
filter name registerd by C<register_filter()>.
2060

            
2061
These filters are added to the C<out> filters, set by C<apply_filter()>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2062

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

            
2065
    query => 1
2066

            
2067
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
2068

            
updated pod
Yuki Kimoto authored on 2011-06-09
2069
=item C<table>
2070
    
2071
    table => 'author'
2072
    table => ['author', 'book']
2073

            
2074
Table names for filtering.
2075

            
2076
Filtering by C<apply_filter> is off in C<execute> method,
2077
because we don't know what filter is applied.
2078

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2079
=item C<type>
2080

            
2081
Specify database data type.
2082

            
2083
    type => [image => DBI::SQL_BLOB]
2084
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2085

            
2086
This is used to bind paramter by C<bind_param()> of statment handle.
2087

            
2088
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2089

            
2090
C<type> option is also available
2091
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2092

            
2093
=item C<type_rule_off> EXPERIMENTAL
2094

            
2095
    type_rule_off => 1
2096

            
2097
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2098

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2109
=over 4
2110

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

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

            
2115
=item C<filter>
2116

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2121
    id => 4
2122
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2123

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2127
    $dbi->delete(
2128
        parimary_key => ['id1', 'id2'],
2129
        id => [4, 5],
2130
        table => 'book',
2131
    );
update pod
Yuki Kimoto authored on 2011-03-13
2132

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2153
=item C<type>
2154

            
2155
Same as C<execute> method's C<type> option.
2156

            
2157
=item C<type_rule_off> EXPERIMENTAL
2158

            
2159
Same as C<execute> method's C<type_rule_off> option.
2160

            
updated pod
Yuki Kimoto authored on 2011-06-08
2161
=back
update pod
Yuki Kimoto authored on 2011-03-13
2162

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2167
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2168
Options is same as C<delete()>.
update pod
Yuki Kimoto authored on 2011-03-13
2169

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
2174
Execute insert statement.
update pod
Yuki Kimoto authored on 2011-03-13
2175

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

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

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

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

            
2184
=item C<filter>
2185

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

            
2188
=item C<id>
2189

            
updated document
Yuki Kimoto authored on 2011-06-09
2190
    id => 4
2191
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2192

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2196
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2197
        {title => 'Perl', author => 'Ken'}
2198
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2199
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2200
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2201
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2202

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

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

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

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

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

            
2217
=item C<param>
2218

            
2219
    param => {title => 'Perl', author => 'Ken'}
2220

            
2221
Insert data.
2222

            
2223
If C<insert> method's arguments is odd numbers,
2224
first argument is received as C<param>.
2225

            
2226
    $dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book');
2227

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

            
2230
Same as C<execute> method's C<query> option.
2231

            
2232
=item C<table>
2233

            
2234
    table => 'book'
2235

            
2236
Table name.
2237

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2238
=item C<type>
cleanup
yuki-kimoto authored on 2010-10-17
2239

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2240
Same as C<execute> method's C<type> option.
cleanup
yuki-kimoto authored on 2010-10-17
2241

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2246
=back
2247

            
2248
=over 4
2249

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2265
    lib / MyModel.pm
2266
        / MyModel / book.pm
2267
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2268

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

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

            
2273
    package MyModel;
2274
    
2275
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2276
    
2277
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2278

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2283
    package MyModel::book;
2284
    
2285
    use base 'MyModel';
2286
    
2287
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2288

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2291
    package MyModel::company;
2292
    
2293
    use base 'MyModel';
2294
    
2295
    1;
2296
    
2297
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2298

            
update pod
Yuki Kimoto authored on 2011-03-13
2299
You can get model object by C<model()>.
2300

            
2301
    my $book_model    = $dbi->model('book');
2302
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2303

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

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

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

            
2310
Merge paramters.
2311

            
2312
$param:
2313

            
2314
    {key1 => [1, 1], key2 => 2}
2315

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

            
2318
    $dbi->method(
2319
        update_or_insert => sub {
2320
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2321
            
2322
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2323
        },
2324
        find_or_create   => sub {
2325
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2326
            
2327
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2328
        }
2329
    );
2330

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

            
2333
    $dbi->update_or_insert;
2334
    $dbi->find_or_create;
2335

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

            
2338
    $dbi->model('book')->method(
2339
        insert => sub { ... },
2340
        update => sub { ... }
2341
    );
2342
    
2343
    my $model = $dbi->model('book');
2344

            
2345
Set and get a L<DBIx::Custom::Model> object,
2346

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

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

            
2351
Create column clause for myself. The follwoing column clause is created.
2352

            
2353
    book.author as author,
2354
    book.title as title
2355

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2358
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2359
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2360
        user => 'ken',
2361
        password => '!LFKD%$&',
2362
        dbi_option => {mysql_enable_utf8 => 1}
2363
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2364

            
2365
Create a new L<DBIx::Custom> object.
2366

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

            
2369
    my $not_exists = $dbi->not_exists;
2370

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2374
=head2 C<register_filter>
2375

            
update pod
Yuki Kimoto authored on 2011-03-13
2376
    $dbi->register_filter(
2377
        # Time::Piece object to database DATE format
2378
        tp_to_date => sub {
2379
            my $tp = shift;
2380
            return $tp->strftime('%Y-%m-%d');
2381
        },
2382
        # database DATE format to Time::Piece object
2383
        date_to_tp => sub {
2384
           my $date = shift;
2385
           return Time::Piece->strptime($date, '%Y-%m-%d');
2386
        }
2387
    );
cleanup
yuki-kimoto authored on 2010-10-17
2388
    
update pod
Yuki Kimoto authored on 2011-03-13
2389
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2390

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

            
2393
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2394
        into => {
2395
            DATE => sub { ... },
2396
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2397
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2398
        from => {
2399
            # DATE
2400
            9 => sub { ... },
2401
            
2402
            # DATETIME or TIMESTAMP
2403
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2404
        }
2405
    );
2406

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2407
Filtering rule when data is send into and get from database.
2408
This has a little complex problem. 
cleanup
Yuki Kimoto authored on 2011-06-13
2409

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2410
In C<into> you can specify type name as same as type name defined
2411
by create table, such as C<DATETIME> or C<DATE>.
cleanup
Yuki Kimoto authored on 2011-06-13
2412
Type rule of C<into> is enabled on the following pattern.
2413

            
2414
=over 4
2415

            
2416
=item 1. column name
2417

            
2418
    issue_date
2419
    issue_datetime
2420

            
2421
=item 2. table name and column name, separator is dot
2422

            
2423
    book.issue_date
2424
    book.issue_datetime
2425

            
2426
=back
2427

            
2428
In C<from> you can't specify type name defined by create table.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2429
You must specify data type, this is internal one.
2430
You get all data type by C<available_data_type>.
2431

            
2432
    print $dbi->available_data_type;
2433

            
cleanup
Yuki Kimoto authored on 2011-06-13
2434
Type rule of C<from> is enabled on the following pattern.
2435

            
2436
=item 1. column name
2437

            
2438
    issue_date
2439
    issue_datetime
2440

            
2441
=item 2. table name and column name, separator is dot
2442

            
2443
    book.issue_date
2444
    book.issue_datetime
2445

            
2446
=item 3. table name and column name, separator is double underbar
2447

            
2448
    book__issue_date
2449
    book__issue_datetime
2450

            
2451
=item 4. table name and column name, separator is hyphen
2452

            
2453
    book-issue_date
2454
    book-issue_datetime
2455

            
2456
This is useful in HTML.
2457

            
2458
=back
2459

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2460
You can also specify multiple types
2461

            
2462
    $dbi->type_rule(
2463
        into => [
2464
            [qw/DATE DATETIME/] => sub { ... },
2465
        ],
2466
        from => {
2467
            # DATE
2468
            [qw/9 11/] => sub { ... },
2469
        }
2470
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2471

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2474
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2475
        table  => 'book',
2476
        column => ['author', 'title'],
2477
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2478
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2479
    
updated document
Yuki Kimoto authored on 2011-06-09
2480
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2481

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

            
2484
=over 4
2485

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2490
Append statement to last of SQL.
2491
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2492
=item C<column>
2493
    
updated document
Yuki Kimoto authored on 2011-06-09
2494
    column => 'author'
2495
    column => ['author', 'title']
2496

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2503
You can specify hash reference in array reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2504

            
updated document
Yuki Kimoto authored on 2011-06-09
2505
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2506
        {book => [qw/author title/]},
2507
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2508
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2509

            
updated document
Yuki Kimoto authored on 2011-06-09
2510
This is expanded to the following one by using C<col> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2511

            
2512
    book.author as "book.author",
2513
    book.title as "book.title",
2514
    person.name as "person.name",
2515
    person.age as "person.age"
2516

            
updated document
Yuki Kimoto authored on 2011-06-09
2517
You can specify array reference in array reference.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2518

            
updated document
Yuki Kimoto authored on 2011-06-09
2519
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2520
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2521
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2522

            
updated document
Yuki Kimoto authored on 2011-06-09
2523
Alias is quoted and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2524

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

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

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

            
2531
=item C<id>
2532

            
2533
    id => 4
2534
    id => [4, 5]
2535

            
2536
ID corresponding to C<primary_key>.
2537
You can select rows by C<id> and C<primary_key>.
2538

            
2539
    $dbi->select(
2540
        parimary_key => ['id1', 'id2'],
2541
        id => [4, 5],
2542
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2543
    );
2544

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2547
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2548
        where => {id1 => 4, id2 => 5},
2549
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2550
    );
2551
    
updated document
Yuki Kimoto authored on 2011-06-09
2552
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2553

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

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

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

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2564
=itme C<prefix> EXPERIMENTAL
2565

            
2566
    prefix => 'SQL_CALC_FOUND_ROWS'
2567

            
2568
Prefix of column cluase
2569

            
2570
    select SQL_CALC_FOUND_ROWS title, author from book;
2571

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

            
2574
    join => [
2575
        'left outer join company on book.company_id = company_id',
2576
        'left outer join location on company.location_id = location.id'
2577
    ]
2578
        
2579
Join clause. If column cluase or where clause contain table name like "company.name",
2580
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2581

            
2582
    $dbi->select(
2583
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2584
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2585
        where => {'company.name' => 'Orange'},
2586
        join => [
2587
            'left outer join company on book.company_id = company.id',
2588
            'left outer join location on company.location_id = location.id'
2589
        ]
2590
    );
2591

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2595
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2596
    from book
2597
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2598
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2599

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2611
=item C<type>
updated pod
Yuki Kimoto authored on 2011-06-08
2612

            
updated document
Yuki Kimoto authored on 2011-06-09
2613
Same as C<execute> method's C<type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2614

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2619
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2620

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2625
=item C<where>
2626
    
2627
    # Hash refrence
2628
    where => {author => 'Ken', 'title' => 'Perl'}
2629
    
2630
    # DBIx::Custom::Where object
2631
    where => $dbi->where(
2632
        clause => ['and', 'author = :author', 'title like :title'],
2633
        param  => {author => 'Ken', title => '%Perl%'}
2634
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2635

            
updated document
Yuki Kimoto authored on 2011-06-09
2636
    # String(with where_param option)
2637
    where => 'title like :title',
2638
    where_param => {title => '%Perl%'}
update pod
Yuki Kimoto authored on 2011-03-12
2639

            
updated document
Yuki Kimoto authored on 2011-06-09
2640
Where clause.
2641
    
improved pod
Yuki Kimoto authored on 2011-04-19
2642
=item C<wrap> EXPERIMENTAL
2643

            
2644
Wrap statement. This is array reference.
2645

            
2646
    $dbi->select(wrap => ['select * from (', ') as t where ROWNUM < 10']);
2647

            
2648
This option is for Oracle and SQL Server paging process.
2649

            
update pod
Yuki Kimoto authored on 2011-03-12
2650
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2651

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2656
Execute update statement.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2657

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2660
=over 4
2661

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2672
    id => 4
2673
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2674

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2678
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2679
        {title => 'Perl', author => 'Ken'}
2680
        parimary_key => ['id1', 'id2'],
2681
        id => [4, 5],
2682
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2683
    );
update pod
Yuki Kimoto authored on 2011-03-13
2684

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2687
    $dbi->update(
2688
        {title => 'Perl', author => 'Ken'}
2689
        where => {id1 => 4, id2 => 5},
2690
        table => 'book'
2691
    );
update pod
Yuki Kimoto authored on 2011-03-13
2692

            
updated document
Yuki Kimoto authored on 2011-06-09
2693
=item C<param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2694

            
updated document
Yuki Kimoto authored on 2011-06-09
2695
    param => {title => 'Perl'}
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2696

            
updated document
Yuki Kimoto authored on 2011-06-09
2697
Update data.
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2698

            
updated document
Yuki Kimoto authored on 2011-06-09
2699
If C<update> method's arguments is odd numbers, first argument is received as C<param>.
update pod
Yuki Kimoto authored on 2011-03-13
2700

            
updated document
Yuki Kimoto authored on 2011-06-09
2701
    $dbi->update({title => 'Perl'}, table => 'book', where => {id => 2});
update pod
Yuki Kimoto authored on 2011-03-13
2702

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2724
=item C<type>
2725

            
2726
Same as C<execute> method's C<type> option.
2727

            
2728
=item C<type_rule_off> EXPERIMENTAL
2729

            
2730
Turn type rule off.
2731

            
updated pod
Yuki Kimoto authored on 2011-06-08
2732
=back
update pod
Yuki Kimoto authored on 2011-03-13
2733

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2738
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2739
Options is same as C<update()>.
update pod
Yuki Kimoto authored on 2011-03-13
2740

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

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

            
2745
Create update parameter tag.
2746

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2749
C<no_set> option is DEPRECATED! use C<assing_param> instead.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2750

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

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

            
2758
Create a new L<DBIx::Custom::Where> object.
2759

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2767
=head2 C<update_at()> DEPRECATED!
2768

            
2769
Update statement, using primary key.
2770

            
2771
    $dbi->update_at(
2772
        table => 'book',
2773
        primary_key => 'id',
2774
        where => '5',
2775
        param => {title => 'Perl'}
2776
    );
2777

            
2778
This method is same as C<update()> exept that
2779
C<primary_key> is specified and C<where> is constant value or array refrence.
2780
all option of C<update()> is available.
2781

            
2782
=head2 C<delete_at()> DEPRECATED!
2783

            
2784
Delete statement, using primary key.
2785

            
2786
    $dbi->delete_at(
2787
        table => 'book',
2788
        primary_key => 'id',
2789
        where => '5'
2790
    );
2791

            
2792
This method is same as C<delete()> exept that
2793
C<primary_key> is specified and C<where> is constant value or array refrence.
2794
all option of C<delete()> is available.
2795

            
2796
=head2 C<select_at()> DEPRECATED!
2797

            
2798
Select statement, using primary key.
2799

            
2800
    $dbi->select_at(
2801
        table => 'book',
2802
        primary_key => 'id',
2803
        where => '5'
2804
    );
2805

            
2806
This method is same as C<select()> exept that
2807
C<primary_key> is specified and C<where> is constant value or array refrence.
2808
all option of C<select()> is available.
2809

            
2810
=head2 C<register_tag> DEPRECATED!
2811

            
2812
    $dbi->register_tag(
2813
        update => sub {
2814
            my @columns = @_;
2815
            
2816
            # Update parameters
2817
            my $s = 'set ';
2818
            $s .= "$_ = ?, " for @columns;
2819
            $s =~ s/, $//;
2820
            
2821
            return [$s, \@columns];
2822
        }
2823
    );
2824

            
2825
Register tag, used by C<execute()>.
2826

            
2827
See also L<Tags/Tags> about tag registered by default.
2828

            
2829
Tag parser receive arguments specified in tag.
2830
In the following tag, 'title' and 'author' is parser arguments
2831

            
2832
    {update_param title author} 
2833

            
2834
Tag parser must return array refrence,
2835
first element is the result statement, 
2836
second element is column names corresponding to place holders.
2837

            
2838
In this example, result statement is 
2839

            
2840
    set title = ?, author = ?
2841

            
2842
Column names is
2843

            
2844
    ['title', 'author']
2845

            
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
2846
=head2 C<apply_filter> DEPRECATED!
2847

            
2848
    $dbi->apply_filter(
2849
        'book',
2850
        'issue_date' => {
2851
            out => 'tp_to_date',
2852
            in  => 'date_to_tp',
2853
            end => 'tp_to_displaydate'
2854
        },
2855
        'write_date' => {
2856
            out => 'tp_to_date',
2857
            in  => 'date_to_tp',
2858
            end => 'tp_to_displaydate'
2859
        }
2860
    );
2861

            
2862
Apply filter to columns.
2863
C<out> filter is executed before data is send to database.
2864
C<in> filter is executed after a row is fetch.
2865
C<end> filter is execute after C<in> filter is executed.
2866

            
2867
Filter is applied to the follwoing tree column name pattern.
2868

            
2869
       PETTERN         EXAMPLE
2870
    1. Column        : author
2871
    2. Table.Column  : book.author
2872
    3. Table__Column : book__author
2873
    4. Table-Column  : book-author
2874

            
2875
If column name is duplicate with other table,
2876
Main filter specified by C<table> option is used.
2877

            
2878
You can set multiple filters at once.
2879

            
2880
    $dbi->apply_filter(
2881
        'book',
2882
        [qw/issue_date write_date/] => {
2883
            out => 'tp_to_date',
2884
            in  => 'date_to_tp',
2885
            end => 'tp_to_displaydate'
2886
        }
2887
    );
2888

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2889
=head1 Parameter
2890

            
2891
Parameter start at ':'. This is replaced to place holoder
2892

            
2893
    $dbi->execute(
2894
        "select * from book where title = :title and author = :author"
2895
        param => {title => 'Perl', author => 'Ken'}
2896
    );
2897

            
2898
    "select * from book where title = ? and author = ?"
2899

            
2900
=head1 Tags DEPRECATED!
2901

            
2902
B<Tag> system is DEPRECATED! use parameter system :name instead.
2903
Parameter is simple and readable.
2904

            
2905
Note that you can't use both tag and paramter at same time.
cleanup
Yuki Kimoto authored on 2011-01-25
2906

            
2907
The following tags is available.
2908

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2909
=head2 C<?> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2910

            
2911
Placeholder tag.
2912

            
2913
    {? NAME}    ->   ?
2914

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2915
=head2 C<=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2916

            
2917
Equal tag.
2918

            
2919
    {= NAME}    ->   NAME = ?
2920

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2921
=head2 C<E<lt>E<gt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2922

            
2923
Not equal tag.
2924

            
2925
    {<> NAME}   ->   NAME <> ?
2926

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2927
=head2 C<E<lt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2928

            
2929
Lower than tag
2930

            
2931
    {< NAME}    ->   NAME < ?
2932

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2933
=head2 C<E<gt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2934

            
2935
Greater than tag
2936

            
2937
    {> NAME}    ->   NAME > ?
2938

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2939
=head2 C<E<gt>=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2940

            
2941
Greater than or equal tag
2942

            
2943
    {>= NAME}   ->   NAME >= ?
2944

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2945
=head2 C<E<lt>=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2946

            
2947
Lower than or equal tag
2948

            
2949
    {<= NAME}   ->   NAME <= ?
2950

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2951
=head2 C<like> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2952

            
2953
Like tag
2954

            
2955
    {like NAME}   ->   NAME like ?
2956

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2957
=head2 C<in> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2958

            
2959
In tag.
2960

            
2961
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2962

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2963
=head2 C<insert_param> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2964

            
2965
Insert parameter tag.
2966

            
2967
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2968

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2969
=head2 C<update_param> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2970

            
2971
Updata parameter tag.
2972

            
2973
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2974

            
updated pod
Yuki Kimoto authored on 2011-06-08
2975
=head2 C<insert_at()> DEPRECATED!
2976

            
2977
Insert statement, using primary key.
2978

            
2979
    $dbi->insert_at(
2980
        table => 'book',
2981
        primary_key => 'id',
2982
        where => '5',
2983
        param => {title => 'Perl'}
2984
    );
2985

            
2986
This method is same as C<insert()> exept that
2987
C<primary_key> is specified and C<where> is constant value or array refrence.
2988
all option of C<insert()> is available.
2989

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

            
2992
=head2 C<DBIX_CUSTOM_DEBUG>
2993

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

            
2997
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2998

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

            
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3001
=head1 STABILITY
3002

            
cleanup
Yuki Kimoto authored on 2011-01-25
3003
L<DBIx::Custom> is stable. APIs keep backword compatible
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3004
except EXPERIMENTAL one in the feature.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3005

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

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

            
3010
C<< <kimoto.yuki at gmail.com> >>
3011

            
3012
L<http://github.com/yuki-kimoto/DBIx-Custom>
3013

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3014
=head1 AUTHOR
3015

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

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

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

            
3022
This program is free software; you can redistribute it and/or modify it
3023
under the same terms as Perl itself.
3024

            
3025
=cut