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

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
3
our $VERSION = '0.1690';
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,
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
525
            type_rule_off => $type_rule_off
cleanup
yuki-kimoto authored on 2010-10-17
526
        );
527

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1758
Filter when data is send or receive.
1759

            
1760
=item *
1761

            
1762
Data filtering system
1763

            
1764
=item *
1765

            
1766
Model support.
1767

            
1768
=item *
1769

            
1770
Generate where clause dinamically.
1771

            
1772
=item *
1773

            
1774
Generate join clause dinamically.
1775

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

            
1778
=head1 GUIDE
1779

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1825
=head2 C<default_dbi_option>
1826

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1907
    print $dbi->available_data_type;
1908

            
1909
Get available data type.
1910

            
cleanup
Yuki Kimoto authored on 2011-06-13
1911
=head2 C<apply_filter> DEPRECATED!
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1912

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1913
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1914
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1915
        'issue_date' => {
1916
            out => 'tp_to_date',
1917
            in  => 'date_to_tp',
1918
            end => 'tp_to_displaydate'
1919
        },
1920
        'write_date' => {
1921
            out => 'tp_to_date',
1922
            in  => 'date_to_tp',
1923
            end => 'tp_to_displaydate'
1924
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1925
    );
1926

            
update pod
Yuki Kimoto authored on 2011-03-13
1927
Apply filter to columns.
1928
C<out> filter is executed before data is send to database.
1929
C<in> filter is executed after a row is fetch.
1930
C<end> filter is execute after C<in> filter is executed.
1931

            
1932
Filter is applied to the follwoing tree column name pattern.
cleanup
Yuki Kimoto authored on 2010-12-21
1933

            
update pod
Yuki Kimoto authored on 2011-03-13
1934
       PETTERN         EXAMPLE
1935
    1. Column        : author
1936
    2. Table.Column  : book.author
1937
    3. Table__Column : book__author
cleanup
Yuki Kimoto authored on 2011-06-13
1938
    4. Table-Column  : book-author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1939

            
update pod
Yuki Kimoto authored on 2011-03-13
1940
If column name is duplicate with other table,
1941
Main filter specified by C<table> option is used.
1942

            
1943
You can set multiple filters at once.
1944

            
1945
    $dbi->apply_filter(
1946
        'book',
1947
        [qw/issue_date write_date/] => {
1948
            out => 'tp_to_date',
1949
            in  => 'date_to_tp',
1950
            end => 'tp_to_displaydate'
1951
        }
1952
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1953

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

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

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

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

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

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

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

            
1968
Create column clause. The follwoing column clause is created.
1969

            
1970
    book.author as "book.author",
1971
    book.title as "book.title"
1972

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1975
    # Separator is double underbar
1976
    $dbi->separator('__');
1977
    
1978
    book.author as "book__author",
1979
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1980

            
cleanup
Yuki Kimoto authored on 2011-06-13
1981
    # Separator is hyphen
1982
    $dbi->separator('-');
1983
    
1984
    book.author as "book-author",
1985
    book.title as "book-title"
1986
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1987
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1988

            
update pod
Yuki Kimoto authored on 2011-03-13
1989
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1990
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1991
        user => 'ken',
1992
        password => '!LFKD%$&',
1993
        dbi_option => {mysql_enable_utf8 => 1}
1994
    );
1995

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2004
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2005
        table => 'book',
2006
        primary_key => 'id',
2007
        join => [
2008
            'inner join company on book.comparny_id = company.id'
2009
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2010
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2011
            publish_date => {
2012
                out => 'tp_to_date',
2013
                in => 'date_to_tp',
2014
                end => 'tp_to_displaydate'
2015
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2016
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2017
    );
2018

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

            
2022
   $dbi->model('book')->select(...);
2023

            
cleanup
yuki-kimoto authored on 2010-10-17
2024
=head2 C<create_query>
2025
    
2026
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
2027
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
2028
    );
update document
yuki-kimoto authored on 2009-11-19
2029

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

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

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

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

            
2040
    my $dbh = $dbi->dbh;
2041

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

            
2045
=head2 C<each_column>
2046

            
2047
    $dbi->each_column(
2048
        sub {
2049
            my ($dbi, $table, $column, $column_info) = @_;
2050
            
2051
            my $type = $column_info->{TYPE_NAME};
2052
            
2053
            if ($type eq 'DATE') {
2054
                # ...
2055
            }
2056
        }
2057
    );
2058

            
2059
Iterate all column informations of all table from database.
2060
Argument is callback when one column is found.
2061
Callback receive four arguments, dbi object, table name,
2062
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2063

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

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

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

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

            
2077
    select * from where title = ? and author like ?;
2078

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

            
2081
=over 4
2082

            
2083
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2084
    
2085
    filter => {
2086
        title  => sub { uc $_[0] }
2087
        author => sub { uc $_[0] }
2088
    }
update pod
Yuki Kimoto authored on 2011-03-13
2089

            
updated pod
Yuki Kimoto authored on 2011-06-09
2090
    # Filter name
2091
    filter => {
2092
        title  => 'upper_case',
2093
        author => 'upper_case'
2094
    }
2095
        
2096
    # At once
2097
    filter => [
2098
        [qw/title author/]  => sub { uc $_[0] }
2099
    ]
2100

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

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

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

            
2109
    query => 1
2110

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2113
=item C<table>
2114
    
2115
    table => 'author'
2116
    table => ['author', 'book']
2117

            
2118
Table names for filtering.
2119

            
2120
Filtering by C<apply_filter> is off in C<execute> method,
2121
because we don't know what filter is applied.
2122

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

            
2125
Specify database data type.
2126

            
2127
    type => [image => DBI::SQL_BLOB]
2128
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2129

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

            
2132
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2133

            
2134
C<type> option is also available
2135
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2136

            
2137
=item C<type_rule_off> EXPERIMENTAL
2138

            
2139
    type_rule_off => 1
2140

            
2141
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2142

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2153
=over 4
2154

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

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

            
2159
=item C<filter>
2160

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2165
    id => 4
2166
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2167

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2171
    $dbi->delete(
2172
        parimary_key => ['id1', 'id2'],
2173
        id => [4, 5],
2174
        table => 'book',
2175
    );
update pod
Yuki Kimoto authored on 2011-03-13
2176

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

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

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

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

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

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

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

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

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

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

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

            
2199
Same as C<execute> method's C<type> option.
2200

            
2201
=item C<type_rule_off> EXPERIMENTAL
2202

            
2203
Same as C<execute> method's C<type_rule_off> option.
2204

            
updated pod
Yuki Kimoto authored on 2011-06-08
2205
=back
update pod
Yuki Kimoto authored on 2011-03-13
2206

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2214
=head2 C<insert>
2215

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

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

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

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

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

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

            
2228
=item C<filter>
2229

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

            
2232
=item C<id>
2233

            
updated document
Yuki Kimoto authored on 2011-06-09
2234
    id => 4
2235
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2236

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2240
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2241
        {title => 'Perl', author => 'Ken'}
2242
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2243
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2244
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2245
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2246

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

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

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

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

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

            
2261
=item C<param>
2262

            
2263
    param => {title => 'Perl', author => 'Ken'}
2264

            
2265
Insert data.
2266

            
2267
If C<insert> method's arguments is odd numbers,
2268
first argument is received as C<param>.
2269

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

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

            
2274
Same as C<execute> method's C<query> option.
2275

            
2276
=item C<table>
2277

            
2278
    table => 'book'
2279

            
2280
Table name.
2281

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2290
=back
2291

            
2292
=over 4
2293

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2309
    lib / MyModel.pm
2310
        / MyModel / book.pm
2311
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2312

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

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

            
2317
    package MyModel;
2318
    
2319
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2320
    
2321
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2322

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2327
    package MyModel::book;
2328
    
2329
    use base 'MyModel';
2330
    
2331
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2332

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2335
    package MyModel::company;
2336
    
2337
    use base 'MyModel';
2338
    
2339
    1;
2340
    
2341
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2342

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

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

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

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

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

            
2354
Merge paramters.
2355

            
2356
$param:
2357

            
2358
    {key1 => [1, 1], key2 => 2}
2359

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

            
2362
    $dbi->method(
2363
        update_or_insert => sub {
2364
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2365
            
2366
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2367
        },
2368
        find_or_create   => sub {
2369
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2370
            
2371
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2372
        }
2373
    );
2374

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

            
2377
    $dbi->update_or_insert;
2378
    $dbi->find_or_create;
2379

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

            
2382
    $dbi->model('book')->method(
2383
        insert => sub { ... },
2384
        update => sub { ... }
2385
    );
2386
    
2387
    my $model = $dbi->model('book');
2388

            
2389
Set and get a L<DBIx::Custom::Model> object,
2390

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

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

            
2395
Create column clause for myself. The follwoing column clause is created.
2396

            
2397
    book.author as author,
2398
    book.title as title
2399

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2402
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2403
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2404
        user => 'ken',
2405
        password => '!LFKD%$&',
2406
        dbi_option => {mysql_enable_utf8 => 1}
2407
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2408

            
2409
Create a new L<DBIx::Custom> object.
2410

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

            
2413
    my $not_exists = $dbi->not_exists;
2414

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2418
=head2 C<register_filter>
2419

            
update pod
Yuki Kimoto authored on 2011-03-13
2420
    $dbi->register_filter(
2421
        # Time::Piece object to database DATE format
2422
        tp_to_date => sub {
2423
            my $tp = shift;
2424
            return $tp->strftime('%Y-%m-%d');
2425
        },
2426
        # database DATE format to Time::Piece object
2427
        date_to_tp => sub {
2428
           my $date = shift;
2429
           return Time::Piece->strptime($date, '%Y-%m-%d');
2430
        }
2431
    );
cleanup
yuki-kimoto authored on 2010-10-17
2432
    
update pod
Yuki Kimoto authored on 2011-03-13
2433
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2434

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

            
2437
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2438
        into => {
2439
            DATE => sub { ... },
2440
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2441
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2442
        from => {
2443
            # DATE
2444
            9 => sub { ... },
2445
            
2446
            # DATETIME or TIMESTAMP
2447
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2448
        }
2449
    );
2450

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

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

            
2458
=over 4
2459

            
2460
=item 1. column name
2461

            
2462
    issue_date
2463
    issue_datetime
2464

            
2465
=item 2. table name and column name, separator is dot
2466

            
2467
    book.issue_date
2468
    book.issue_datetime
2469

            
2470
=back
2471

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

            
2476
    print $dbi->available_data_type;
2477

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

            
2480
=item 1. column name
2481

            
2482
    issue_date
2483
    issue_datetime
2484

            
2485
=item 2. table name and column name, separator is dot
2486

            
2487
    book.issue_date
2488
    book.issue_datetime
2489

            
2490
=item 3. table name and column name, separator is double underbar
2491

            
2492
    book__issue_date
2493
    book__issue_datetime
2494

            
2495
=item 4. table name and column name, separator is hyphen
2496

            
2497
    book-issue_date
2498
    book-issue_datetime
2499

            
2500
This is useful in HTML.
2501

            
2502
=back
2503

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

            
2506
    $dbi->type_rule(
2507
        into => [
2508
            [qw/DATE DATETIME/] => sub { ... },
2509
        ],
2510
        from => {
2511
            # DATE
2512
            [qw/9 11/] => sub { ... },
2513
        }
2514
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2515

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2518
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2519
        table  => 'book',
2520
        column => ['author', 'title'],
2521
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2522
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2523
    
updated document
Yuki Kimoto authored on 2011-06-09
2524
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2525

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

            
2528
=over 4
2529

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2534
Append statement to last of SQL.
2535
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2536
=item C<column>
2537
    
updated document
Yuki Kimoto authored on 2011-06-09
2538
    column => 'author'
2539
    column => ['author', 'title']
2540

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2549
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2550
        {book => [qw/author title/]},
2551
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2552
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2553

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

            
2556
    book.author as "book.author",
2557
    book.title as "book.title",
2558
    person.name as "person.name",
2559
    person.age as "person.age"
2560

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2563
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2564
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2565
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2566

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

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

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

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

            
2575
=item C<id>
2576

            
2577
    id => 4
2578
    id => [4, 5]
2579

            
2580
ID corresponding to C<primary_key>.
2581
You can select rows by C<id> and C<primary_key>.
2582

            
2583
    $dbi->select(
2584
        parimary_key => ['id1', 'id2'],
2585
        id => [4, 5],
2586
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2587
    );
2588

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2591
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2592
        where => {id1 => 4, id2 => 5},
2593
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2594
    );
2595
    
updated document
Yuki Kimoto authored on 2011-06-09
2596
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2597

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

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

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

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

            
2610
    prefix => 'SQL_CALC_FOUND_ROWS'
2611

            
2612
Prefix of column cluase
2613

            
2614
    select SQL_CALC_FOUND_ROWS title, author from book;
2615

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

            
2618
    join => [
2619
        'left outer join company on book.company_id = company_id',
2620
        'left outer join location on company.location_id = location.id'
2621
    ]
2622
        
2623
Join clause. If column cluase or where clause contain table name like "company.name",
2624
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2625

            
2626
    $dbi->select(
2627
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2628
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2629
        where => {'company.name' => 'Orange'},
2630
        join => [
2631
            'left outer join company on book.company_id = company.id',
2632
            'left outer join location on company.location_id = location.id'
2633
        ]
2634
    );
2635

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2639
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2640
    from book
2641
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2642
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2643

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2663
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2664

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2669
=item C<where>
2670
    
2671
    # Hash refrence
2672
    where => {author => 'Ken', 'title' => 'Perl'}
2673
    
2674
    # DBIx::Custom::Where object
2675
    where => $dbi->where(
2676
        clause => ['and', 'author = :author', 'title like :title'],
2677
        param  => {author => 'Ken', title => '%Perl%'}
2678
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2679

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2684
Where clause.
2685
    
improved pod
Yuki Kimoto authored on 2011-04-19
2686
=item C<wrap> EXPERIMENTAL
2687

            
2688
Wrap statement. This is array reference.
2689

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

            
2692
This option is for Oracle and SQL Server paging process.
2693

            
update pod
Yuki Kimoto authored on 2011-03-12
2694
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2695

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2704
=over 4
2705

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2716
    id => 4
2717
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2718

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2722
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2723
        {title => 'Perl', author => 'Ken'}
2724
        parimary_key => ['id1', 'id2'],
2725
        id => [4, 5],
2726
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2727
    );
update pod
Yuki Kimoto authored on 2011-03-13
2728

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2731
    $dbi->update(
2732
        {title => 'Perl', author => 'Ken'}
2733
        where => {id1 => 4, id2 => 5},
2734
        table => 'book'
2735
    );
update pod
Yuki Kimoto authored on 2011-03-13
2736

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2743
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
2744

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

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

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

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

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

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

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

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

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

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

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

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

            
2770
Same as C<execute> method's C<type> option.
2771

            
2772
=item C<type_rule_off> EXPERIMENTAL
2773

            
2774
Turn type rule off.
2775

            
updated pod
Yuki Kimoto authored on 2011-06-08
2776
=back
update pod
Yuki Kimoto authored on 2011-03-13
2777

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

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

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

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

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

            
2789
Create update parameter tag.
2790

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

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

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

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

            
2802
Create a new L<DBIx::Custom::Where> object.
2803

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

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

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

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

            
2813
Update statement, using primary key.
2814

            
2815
    $dbi->update_at(
2816
        table => 'book',
2817
        primary_key => 'id',
2818
        where => '5',
2819
        param => {title => 'Perl'}
2820
    );
2821

            
2822
This method is same as C<update()> exept that
2823
C<primary_key> is specified and C<where> is constant value or array refrence.
2824
all option of C<update()> is available.
2825

            
2826
=head2 C<delete_at()> DEPRECATED!
2827

            
2828
Delete statement, using primary key.
2829

            
2830
    $dbi->delete_at(
2831
        table => 'book',
2832
        primary_key => 'id',
2833
        where => '5'
2834
    );
2835

            
2836
This method is same as C<delete()> exept that
2837
C<primary_key> is specified and C<where> is constant value or array refrence.
2838
all option of C<delete()> is available.
2839

            
2840
=head2 C<select_at()> DEPRECATED!
2841

            
2842
Select statement, using primary key.
2843

            
2844
    $dbi->select_at(
2845
        table => 'book',
2846
        primary_key => 'id',
2847
        where => '5'
2848
    );
2849

            
2850
This method is same as C<select()> exept that
2851
C<primary_key> is specified and C<where> is constant value or array refrence.
2852
all option of C<select()> is available.
2853

            
2854
=head2 C<register_tag> DEPRECATED!
2855

            
2856
    $dbi->register_tag(
2857
        update => sub {
2858
            my @columns = @_;
2859
            
2860
            # Update parameters
2861
            my $s = 'set ';
2862
            $s .= "$_ = ?, " for @columns;
2863
            $s =~ s/, $//;
2864
            
2865
            return [$s, \@columns];
2866
        }
2867
    );
2868

            
2869
Register tag, used by C<execute()>.
2870

            
2871
See also L<Tags/Tags> about tag registered by default.
2872

            
2873
Tag parser receive arguments specified in tag.
2874
In the following tag, 'title' and 'author' is parser arguments
2875

            
2876
    {update_param title author} 
2877

            
2878
Tag parser must return array refrence,
2879
first element is the result statement, 
2880
second element is column names corresponding to place holders.
2881

            
2882
In this example, result statement is 
2883

            
2884
    set title = ?, author = ?
2885

            
2886
Column names is
2887

            
2888
    ['title', 'author']
2889

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

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

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

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

            
2901
=head1 Tags DEPRECATED!
2902

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

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

            
2908
The following tags is available.
2909

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

            
2912
Placeholder tag.
2913

            
2914
    {? NAME}    ->   ?
2915

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

            
2918
Equal tag.
2919

            
2920
    {= NAME}    ->   NAME = ?
2921

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

            
2924
Not equal tag.
2925

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

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

            
2930
Lower than tag
2931

            
2932
    {< NAME}    ->   NAME < ?
2933

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

            
2936
Greater than tag
2937

            
2938
    {> NAME}    ->   NAME > ?
2939

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

            
2942
Greater than or equal tag
2943

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

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

            
2948
Lower than or equal tag
2949

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

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

            
2954
Like tag
2955

            
2956
    {like NAME}   ->   NAME like ?
2957

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

            
2960
In tag.
2961

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

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

            
2966
Insert parameter tag.
2967

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

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

            
2972
Updata parameter tag.
2973

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

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

            
2978
Insert statement, using primary key.
2979

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

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

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

            
2993
=head2 C<DBIX_CUSTOM_DEBUG>
2994

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

            
2998
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2999

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

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

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

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

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

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

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

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

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

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

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

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

            
3026
=cut