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

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
3
our $VERSION = '0.1694';
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

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
22
our @COMMON_ARGS = qw/bind_type table query filter id primary_key
23
                      type_rule_off type/;
cleanup
Yuki Kimoto authored on 2011-03-21
24

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
102
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
103
    my $self = shift;
104
    my $option = pop if ref $_[-1] eq 'HASH';
105
    my $real_table = shift;
106
    my $columns = shift;
107
    my $table = $option->{alias} || $real_table;
108
    
109
    # Columns
110
    unless ($columns) {
111
        $columns ||= $self->model($real_table)->columns;
112
    }
added helper method
yuki-kimoto authored on 2010-10-17
113
    
cleanup
Yuki Kimoto authored on 2011-04-02
114
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
115
    my $q = $self->reserved_word_quote;
116
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
117
    # Separator
118
    my $separator = $self->separator;
119
    
cleanup
Yuki Kimoto authored on 2011-04-02
120
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
121
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
122
    $columns ||= [];
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
123
    push @column, "$q$table$q.$q$_$q as $q${table}${separator}$_$q"
124
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
125
    
126
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
127
}
128

            
packaging one directory
yuki-kimoto authored on 2009-11-16
129
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
130
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
131
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
132
    # Connect
133
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
134
    
packaging one directory
yuki-kimoto authored on 2009-11-16
135
    return $self;
136
}
137

            
cleanup
yuki-kimoto authored on 2010-10-17
138
sub create_query {
139
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
140
    
cleanup
yuki-kimoto authored on 2010-10-17
141
    # Cache
142
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
143
    
cleanup
Yuki Kimoto authored on 2011-04-02
144
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
145
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
146
    
147
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
148
    if ($cache) {
149
        
150
        # Get query
151
        my $q = $self->cache_method->($self, $source);
152
        
153
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
154
        if ($q) {
155
            $query = DBIx::Custom::Query->new($q);
156
            $query->filters($self->filters);
157
        }
cleanup
yuki-kimoto authored on 2010-10-17
158
    }
159
    
cleanup
Yuki Kimoto authored on 2011-04-02
160
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
161
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
162

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

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

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

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

            
231
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
232
    }
233
}
234

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
278
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
279
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
280
    my $q = $self->reserved_word_quote;
281
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
282
    push @sql, $append if $append;
283
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
284
    
285
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
286
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
287
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
288
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
289
        table => $table,
290
        %args
291
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
292
}
293

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

            
added helper method
yuki-kimoto authored on 2010-10-17
296
sub DESTROY { }
297

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
298
sub create_model {
299
    my $self = shift;
300
    
cleanup
Yuki Kimoto authored on 2011-04-02
301
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
302
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
303
    $args->{dbi} = $self;
304
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
305
    my $model_name  = delete $args->{name};
306
    my $model_table = delete $args->{table};
307
    $model_name ||= $model_table;
308
    
cleanup
Yuki Kimoto authored on 2011-04-02
309
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
310
    my $model = $model_class->new($args);
311
    $model->name($model_name) unless $model->name;
312
    $model->table($model_table) unless $model->table;
313
    
314
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
315
    my $filter = ref $model->filter eq 'HASH'
316
               ? [%{$model->filter}]
317
               : $model->filter;
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
318
    warn "DBIx::Custom::Model filter method is DEPRECATED!"
319
      if @$filter;
cleanup
Yuki Kimoto authored on 2011-06-13
320
    $self->_apply_filter($model->table, @$filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
321

            
322
    # Set model
323
    $self->model($model->name, $model);
324
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
325
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
326
}
327

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

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

            
349
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
350
    my $self = shift;
351
    my $query = shift;
352
    my $param;
353
    $param = shift if @_ % 2;
354
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
355
    
cleanup
Yuki Kimoto authored on 2011-04-02
356
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
357
    my $p = delete $args{param} || {};
358
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
359
    my $tables = delete $args{table} || [];
360
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
361
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
362
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
363
    my $bind_type = delete $args{bind_type} || delete $args{type};
364
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
365
    my $type_rule_off = delete $args{type_rule_off};
cleanup
Yuki Kimoto authored on 2011-06-09
366
    my $query_return = delete $args{query};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
367
    
cleanup
Yuki Kimoto authored on 2011-03-09
368
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
369
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
370
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
371
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
372
    }
373
    
cleanup
Yuki Kimoto authored on 2011-04-02
374
    # Create query
375
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
376
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
377
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
378
    
cleanup
Yuki Kimoto authored on 2011-04-02
379
    # Tables
380
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
381
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
382
    $tables = $self->_remove_duplicate_table($tables, $main_table);
383
    if (my $q = $self->reserved_word_quote) {
384
        $_ =~ s/$q//g for @$tables;
385
    }
cleanup
Yuki Kimoto authored on 2011-04-02
386
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
387
    # Type rule
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
388
    my $type_filter = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
389
    unless ($type_rule_off) {
390
        foreach my $name (keys %$param) {
391
            my $table;
392
            my $column;
393
            if ($name =~ /(?:(.+)\.)?(.+)/) {
394
                $table = $1;
395
                $column = $2;
396
            }
397
            $table ||= $main_table;
398
            
399
            my $into = $self->{_into} || {};
400
            if (defined $table && $into->{$table} &&
401
                (my $rule = $into->{$table}->{$column}))
402
            {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
403
                $type_filter->{$column} = $rule;
404
                $type_filter->{"$table.$column"} = $rule;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
405
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
406
        }
407
    }
cleanup
Yuki Kimoto authored on 2011-04-02
408
    
409
    # Applied filter
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
410
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
411
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
412
        $applied_filter = {
413
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
414
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
415
        }
416
    }
cleanup
Yuki Kimoto authored on 2011-04-02
417
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
418
    
cleanup
Yuki Kimoto authored on 2011-04-02
419
    # Replace filter name to code
420
    foreach my $column (keys %$filter) {
421
        my $name = $filter->{$column};
422
        if (!defined $name) {
423
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
424
        }
cleanup
Yuki Kimoto authored on 2011-04-02
425
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
426
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
427
            unless exists $self->filters->{$name};
428
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
429
        }
430
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
431
    
cleanup
Yuki Kimoto authored on 2011-04-02
432
    # Create bind values
433
    my $bind = $self->_create_bind_values(
434
        $param,
435
        $query->columns,
436
        $filter,
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
437
        $type_filter,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
438
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
439
    );
cleanup
yuki-kimoto authored on 2010-10-17
440
    
441
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
442
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
443
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
444
    eval {
445
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
446
            my $bind_type = $bind->[$i]->{bind_type};
447
            $sth->bind_param(
448
                $i + 1,
449
                $bind->[$i]->{value},
450
                $bind_type ? $bind_type : ()
451
            );
cleanup
Yuki Kimoto authored on 2011-03-21
452
        }
453
        $affected = $sth->execute;
454
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
455
    
456
    if ($@) {
457
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
458
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
459
    }
cleanup
yuki-kimoto authored on 2010-10-17
460
    
improved debug message
Yuki Kimoto authored on 2011-05-23
461
    # DEBUG message
462
    if (DEBUG) {
463
        print STDERR "SQL:\n" . $query->sql . "\n";
464
        my @output;
465
        foreach my $b (@$bind) {
466
            my $value = $b->{value};
467
            $value = 'undef' unless defined $value;
468
            $value = encode(DEBUG_ENCODING(), $value)
469
              if utf8::is_utf8($value);
470
            push @output, $value;
471
        }
472
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
473
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
474
    
cleanup
Yuki Kimoto authored on 2011-04-02
475
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
476
    if ($sth->{NUM_OF_FIELDS}) {
477
        
cleanup
Yuki Kimoto authored on 2011-04-02
478
        # Filter
479
        my $filter = {};
480
        $filter->{in}  = {};
481
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
482
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
483
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
484
            foreach my $way (qw/in end/) {
485
                $filter->{$way} = {
486
                    %{$filter->{$way}},
487
                    %{$self->{filter}{$way}{$table} || {}}
488
                };
489
            }
cleanup
Yuki Kimoto authored on 2011-01-12
490
        }
491
        
492
        # Result
493
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
494
            sth => $sth,
495
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
496
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
497
            filter => $filter->{in} || {},
498
            end_filter => $filter->{end} || {},
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
499
            type_rule => \%{$self->type_rule->{from}},
cleanup
yuki-kimoto authored on 2010-10-17
500
        );
501

            
502
        return $result;
503
    }
cleanup
Yuki Kimoto authored on 2011-04-02
504
    
505
    # Not select statement
506
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
507
}
508

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

            
cleanup
yuki-kimoto authored on 2010-10-17
511
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
512
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
513
    
cleanup
yuki-kimoto authored on 2010-10-17
514
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
515
    my $param;
516
    $param = shift if @_ % 2;
517
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
518
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
519
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
520
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
521
    my $p = delete $args{param} || {};
522
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
523
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
524
    my $id = delete $args{id};
525
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
526
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
527
          "must be specified when id is specified " . _subname
528
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
529
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
530

            
531
    # Check arguments
532
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
533
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
534
          unless $INSERT_ARGS{$name};
535
    }
536

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
537
    # Merge parameter
538
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
539
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
540
        $param = $self->merge_param($id_param, $param);
541
    }
542

            
cleanup
Yuki Kimoto authored on 2011-04-02
543
    # Reserved word quote
544
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
545
    
cleanup
Yuki Kimoto authored on 2011-04-02
546
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
547
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
548
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
549
    push @sql, $append if $append;
550
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
551
    
552
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
553
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
554
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
555
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
556
        table => $table,
557
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
558
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
559
}
560

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

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

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

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
647
sub merge_param {
648
    my ($self, @params) = @_;
649
    
cleanup
Yuki Kimoto authored on 2011-04-02
650
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
651
    my $merge = {};
652
    foreach my $param (@params) {
653
        foreach my $column (keys %$param) {
654
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
655
            
656
            if (exists $merge->{$column}) {
657
                $merge->{$column} = [$merge->{$column}]
658
                  unless ref $merge->{$column} eq 'ARRAY';
659
                push @{$merge->{$column}},
660
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
661
            }
662
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
663
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
664
            }
665
        }
666
    }
667
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
668
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
669
}
670

            
cleanup
Yuki Kimoto authored on 2011-03-21
671
sub method {
672
    my $self = shift;
673
    
cleanup
Yuki Kimoto authored on 2011-04-02
674
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
675
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
676
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
677
    
678
    return $self;
679
}
680

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
681
sub model {
682
    my ($self, $name, $model) = @_;
683
    
cleanup
Yuki Kimoto authored on 2011-04-02
684
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
685
    if ($model) {
686
        $self->models->{$name} = $model;
687
        return $self;
688
    }
689
    
690
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
691
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
692
      unless $self->models->{$name};
693
    
cleanup
Yuki Kimoto authored on 2011-04-02
694
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
695
    return $self->models->{$name};
696
}
697

            
cleanup
Yuki Kimoto authored on 2011-03-21
698
sub mycolumn {
699
    my ($self, $table, $columns) = @_;
700
    
cleanup
Yuki Kimoto authored on 2011-04-02
701
    # Create column clause
702
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
703
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
704
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
705
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
706
    
707
    return join (', ', @column);
708
}
709

            
added dbi_options attribute
kimoto authored on 2010-12-20
710
sub new {
711
    my $self = shift->SUPER::new(@_);
712
    
cleanup
Yuki Kimoto authored on 2011-04-02
713
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
714
    my @attrs = keys %$self;
715
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
716
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
717
          unless $self->can($attr);
718
    }
cleanup
Yuki Kimoto authored on 2011-04-02
719
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
720
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
721
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
722
        '?'     => \&DBIx::Custom::Tag::placeholder,
723
        '='     => \&DBIx::Custom::Tag::equal,
724
        '<>'    => \&DBIx::Custom::Tag::not_equal,
725
        '>'     => \&DBIx::Custom::Tag::greater_than,
726
        '<'     => \&DBIx::Custom::Tag::lower_than,
727
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
728
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
729
        'like'  => \&DBIx::Custom::Tag::like,
730
        'in'    => \&DBIx::Custom::Tag::in,
731
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
732
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
733
    };
added dbi_options attribute
kimoto authored on 2010-12-20
734
    
735
    return $self;
736
}
737

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

            
cleanup
yuki-kimoto authored on 2010-10-17
740
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
741
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
742
    
743
    # Register filter
744
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
745
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
746
    
cleanup
Yuki Kimoto authored on 2011-04-02
747
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
748
}
packaging one directory
yuki-kimoto authored on 2009-11-16
749

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
840
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
841
    unshift @$tables,
842
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
843
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
844
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
845
    my $where_clause = '';
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
846
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
cleanup
Yuki Kimoto authored on 2011-04-25
847
    if (ref $where) {
848
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
849
        $where_param = keys %$where_param
850
                     ? $self->merge_param($where_param, $where->param)
851
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
852
        
853
        # String where
854
        $where_clause = $where->to_string;
855
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
856
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
857
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
858
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
859
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
860
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
861
    # Push join
862
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
863
    
cleanup
Yuki Kimoto authored on 2011-03-09
864
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
865
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
866
    
cleanup
Yuki Kimoto authored on 2011-03-08
867
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
868
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
869
    
cleanup
Yuki Kimoto authored on 2011-04-02
870
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
871
    push @sql, $append if $append;
872
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
873
    # Wrap
874
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
875
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
876
          unless ref $wrap eq 'ARRAY';
877
        unshift @sql, $wrap->[0];
878
        push @sql, $wrap->[1];
879
    }
880
    
cleanup
Yuki Kimoto authored on 2011-01-27
881
    # SQL
882
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
883
    
884
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
885
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
886
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
887
        param => $where_param, 
cleanup
Yuki Kimoto authored on 2011-03-21
888
        table => $tables,
889
        %args
890
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
891
    
892
    return $result;
893
}
894

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
895
sub separator {
896
    my $self = shift;
897
    
898
    if (@_) {
899
        my $separator = $_[0] || '';
900
        croak qq{Separator must be "." or "__" or "-" } . _subname
901
          unless $separator eq '.' || $separator eq '__'
902
              || $separator eq '-';
903
        
904
        $self->{separator} = $separator;
905
    
906
        return $self;
907
    }
908
    return $self->{separator} ||= '.';
909
}
910

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
911
sub setup_model {
912
    my $self = shift;
913
    
cleanup
Yuki Kimoto authored on 2011-04-02
914
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
915
    $self->each_column(
916
        sub {
917
            my ($self, $table, $column, $column_info) = @_;
918
            if (my $model = $self->models->{$table}) {
919
                push @{$model->columns}, $column;
920
            }
921
        }
922
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
923
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
924
}
925

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
926
sub available_data_type {
927
    my $self = shift;
928
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
929
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
930
    foreach my $i (-1000 .. 1000) {
931
         my $type_info = $self->dbh->type_info($i);
932
         my $data_type = $type_info->{DATA_TYPE};
933
         my $type_name = $type_info->{TYPE_NAME};
934
         $data_types .= "$data_type ($type_name)\n"
935
           if defined $data_type;
936
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
937
    return "Data Type maybe equal to Type Name" unless $data_types;
938
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
939
    return $data_types;
940
}
941

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
942
sub available_type_name {
943
    my $self = shift;
944
    
945
    # Type Names
946
    my $type_names = {};
947
    $self->each_column(sub {
948
        my ($self, $table, $column, $column_info) = @_;
949
        $type_names->{$column_info->{TYPE_NAME}} = 1
950
          if $column_info->{TYPE_NAME};
951
    });
952
    my @output = sort keys %$type_names;
953
    unshift @output, "Type Name";
954
    return join "\n", @output;
955
}
956

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
957
sub type_rule {
958
    my $self = shift;
959
    
960
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
961
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
962
        
963
        # Into
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
964
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
965
        $self->{type_rule} = $type_rule;
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
966
        $self->{_into} = {};
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
967
        foreach my $type_name (keys %{$type_rule->{into} || {}}) {
968
            croak qq{type name of into section must be lower case}
969
              if $type_name =~ /[A-Z]/;
970
        }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
971
        $self->each_column(sub {
972
            my ($dbi, $table, $column, $column_info) = @_;
973
            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
974
            my $type_name = lc $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
975
            if ($type_rule->{into} &&
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
976
                (my $filter = $type_rule->{into}->{$type_name}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
977
            {
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
978
                return unless exists $type_rule->{into}->{$type_name};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
979
                if  (defined $filter && ref $filter ne 'CODE') 
980
                {
981
                    my $fname = $filter;
982
                    croak qq{Filter "$fname" is not registered" } . _subname
983
                      unless exists $self->filters->{$fname};
984
                    
985
                    $filter = $self->filters->{$fname};
986
                }
987

            
988
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
989
            }
990
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
991
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
992

            
993
        # From
994
        $type_rule->{from} = _array_to_hash($type_rule->{from});
995
        foreach my $data_type (keys %{$type_rule->{from} || {}}) {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
996
            croak qq{data type of into section must be lower case or number}
997
              if $data_type =~ /[A-Z]/;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
998
            my $fname = $type_rule->{from}{$data_type};
999
            if (defined $fname && ref $fname ne 'CODE') {
1000
                croak qq{Filter "$fname" is not registered" } . _subname
1001
                  unless exists $self->filters->{$fname};
1002
                
1003
                $type_rule->{from}{$data_type} = $self->filters->{$fname};
1004
            }
1005
        }
1006
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1007
        return $self;
1008
    }
1009
    
1010
    return $self->{type_rule} || {};
1011
}
1012

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1096
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1097
}
1098

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1668
=head1 NAME
1669

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

            
1672
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1673

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

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

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

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

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

            
1742
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1743

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1753
=item *
1754

            
1755
Filter when data is send or receive.
1756

            
1757
=item *
1758

            
1759
Data filtering system
1760

            
1761
=item *
1762

            
1763
Model support.
1764

            
1765
=item *
1766

            
1767
Generate where clause dinamically.
1768

            
1769
=item *
1770

            
1771
Generate join clause dinamically.
1772

            
1773
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1774

            
1775
=head1 GUIDE
1776

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1820
=head2 C<default_dbi_option>
1821

            
1822
    my $default_dbi_option = $dbi->default_dbi_option;
1823
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1824

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

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

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

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

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

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

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

            
1846
    my $models = $dbi->models;
1847
    $dbi       = $dbi->models(\%models);
1848

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1851
=head2 C<password>
1852

            
1853
    my $password = $dbi->password;
1854
    $dbi         = $dbi->password('lkj&le`@s');
1855

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

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

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

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

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

            
1867
     my reserved_word_quote = $dbi->reserved_word_quote;
1868
     $dbi                   = $dbi->reserved_word_quote('"');
1869

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1904
    print $dbi->available_data_type;
1905

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
1906
Get available data types. You can use these data types
1907
in C<type rule>'s C<from> section.
1908

            
1909
=head2 C<available_type_name> EXPERIMENTAL
1910

            
1911
    print $dbi->available_type_name;
1912

            
1913
Get available type names. You can use these type names in
1914
C<type_rule>'s C<into> section.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1915

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

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

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

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

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

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

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

            
1930
Create column clause. The follwoing column clause is created.
1931

            
1932
    book.author as "book.author",
1933
    book.title as "book.title"
1934

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1937
    # Separator is double underbar
1938
    $dbi->separator('__');
1939
    
1940
    book.author as "book__author",
1941
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1942

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

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

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

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

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

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

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

            
1984
   $dbi->model('book')->select(...);
1985

            
cleanup
yuki-kimoto authored on 2010-10-17
1986
=head2 C<create_query>
1987
    
1988
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1989
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1990
    );
update document
yuki-kimoto authored on 2009-11-19
1991

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

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

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

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

            
2002
    my $dbh = $dbi->dbh;
2003

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

            
2007
=head2 C<each_column>
2008

            
2009
    $dbi->each_column(
2010
        sub {
2011
            my ($dbi, $table, $column, $column_info) = @_;
2012
            
2013
            my $type = $column_info->{TYPE_NAME};
2014
            
2015
            if ($type eq 'DATE') {
2016
                # ...
2017
            }
2018
        }
2019
    );
2020

            
2021
Iterate all column informations of all table from database.
2022
Argument is callback when one column is found.
2023
Callback receive four arguments, dbi object, table name,
2024
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2025

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

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

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

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

            
2039
    select * from where title = ? and author like ?;
2040

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

            
2043
=over 4
2044

            
2045
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2046
    
2047
    filter => {
2048
        title  => sub { uc $_[0] }
2049
        author => sub { uc $_[0] }
2050
    }
update pod
Yuki Kimoto authored on 2011-03-13
2051

            
updated pod
Yuki Kimoto authored on 2011-06-09
2052
    # Filter name
2053
    filter => {
2054
        title  => 'upper_case',
2055
        author => 'upper_case'
2056
    }
2057
        
2058
    # At once
2059
    filter => [
2060
        [qw/title author/]  => sub { uc $_[0] }
2061
    ]
2062

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2063
Filter. You can set subroutine or filter name
2064
registered by by C<register_filter()>.
2065
This filter is executed before data is saved into database.
2066
and before type rule filter is executed.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2067

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

            
2070
    query => 1
2071

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2074
=item C<table>
2075
    
2076
    table => 'author'
2077
    table => ['author', 'book']
2078

            
2079
Table names for filtering.
2080

            
2081
Filtering by C<apply_filter> is off in C<execute> method,
2082
because we don't know what filter is applied.
2083

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

            
2086
Specify database data type.
2087

            
2088
    type => [image => DBI::SQL_BLOB]
2089
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2090

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2091
This is used to bind parameter by C<bind_param()> of statment handle.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2092

            
2093
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2094

            
2095
C<type> option is also available
2096
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2097

            
2098
=item C<type_rule_off> EXPERIMENTAL
2099

            
2100
    type_rule_off => 1
2101

            
2102
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2103

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2114
=over 4
2115

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

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

            
2120
=item C<filter>
2121

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2126
    id => 4
2127
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2128

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2132
    $dbi->delete(
2133
        parimary_key => ['id1', 'id2'],
2134
        id => [4, 5],
2135
        table => 'book',
2136
    );
update pod
Yuki Kimoto authored on 2011-03-13
2137

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

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

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

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

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

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

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

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

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

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

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

            
2160
Same as C<execute> method's C<type> option.
2161

            
2162
=item C<type_rule_off> EXPERIMENTAL
2163

            
2164
Same as C<execute> method's C<type_rule_off> option.
2165

            
updated pod
Yuki Kimoto authored on 2011-06-08
2166
=back
update pod
Yuki Kimoto authored on 2011-03-13
2167

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2175
=head2 C<insert>
2176

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

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

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

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

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

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

            
2189
=item C<filter>
2190

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

            
2193
=item C<id>
2194

            
updated document
Yuki Kimoto authored on 2011-06-09
2195
    id => 4
2196
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2197

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

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

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

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

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

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

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

            
2222
=item C<param>
2223

            
2224
    param => {title => 'Perl', author => 'Ken'}
2225

            
2226
Insert data.
2227

            
2228
If C<insert> method's arguments is odd numbers,
2229
first argument is received as C<param>.
2230

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

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

            
2235
Same as C<execute> method's C<query> option.
2236

            
2237
=item C<table>
2238

            
2239
    table => 'book'
2240

            
2241
Table name.
2242

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2251
=back
2252

            
2253
=over 4
2254

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2270
    lib / MyModel.pm
2271
        / MyModel / book.pm
2272
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2273

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

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

            
2278
    package MyModel;
2279
    
2280
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2281
    
2282
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2283

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2288
    package MyModel::book;
2289
    
2290
    use base 'MyModel';
2291
    
2292
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2293

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2296
    package MyModel::company;
2297
    
2298
    use base 'MyModel';
2299
    
2300
    1;
2301
    
2302
MyModel::book and MyModel::company is included by 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
You can get model object by C<model()>.
2305

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

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

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

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

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

            
2317
$param:
2318

            
2319
    {key1 => [1, 1], key2 => 2}
2320

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

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

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

            
2338
    $dbi->update_or_insert;
2339
    $dbi->find_or_create;
2340

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

            
2343
    $dbi->model('book')->method(
2344
        insert => sub { ... },
2345
        update => sub { ... }
2346
    );
2347
    
2348
    my $model = $dbi->model('book');
2349

            
2350
Set and get a L<DBIx::Custom::Model> object,
2351

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

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

            
2356
Create column clause for myself. The follwoing column clause is created.
2357

            
2358
    book.author as author,
2359
    book.title as title
2360

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

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

            
2370
Create a new L<DBIx::Custom> object.
2371

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

            
2374
    my $not_exists = $dbi->not_exists;
2375

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2379
=head2 C<register_filter>
2380

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

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

            
2398
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2399
        into => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2400
            date => sub { ... },
2401
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2402
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2403
        from => {
2404
            # DATE
2405
            9 => sub { ... },
2406
            
2407
            # DATETIME or TIMESTAMP
2408
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2409
        }
2410
    );
2411

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

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

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2419
Note that type name and data type don't contain upper case.
2420
If that contain upper case charactor, you specify it lower case.
2421

            
cleanup
Yuki Kimoto authored on 2011-06-13
2422
=over 4
2423

            
2424
=item 1. column name
2425

            
2426
    issue_date
2427
    issue_datetime
2428

            
2429
=item 2. table name and column name, separator is dot
2430

            
2431
    book.issue_date
2432
    book.issue_datetime
2433

            
2434
=back
2435

            
update pod
Yuki Kimoto authored on 2011-06-15
2436
You get all type name used in database by C<available_type_name>.
2437

            
2438
    print $dbi->available_type_name;
2439

            
cleanup
Yuki Kimoto authored on 2011-06-13
2440
In C<from> you can't specify type name defined by create table.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2441
You must specify data type, this is internal one.
2442
You get all data type by C<available_data_type>.
2443

            
2444
    print $dbi->available_data_type;
2445

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

            
2448
=item 4. table name and column name, separator is hyphen
2449

            
2450
    book-issue_date
2451
    book-issue_datetime
2452

            
2453
This is useful in HTML.
2454

            
2455
=back
2456

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

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

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

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

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

            
2481
=over 4
2482

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

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

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

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

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

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

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

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

            
2509
    book.author as "book.author",
2510
    book.title as "book.title",
2511
    person.name as "person.name",
2512
    person.age as "person.age"
2513

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

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

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

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

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

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

            
2528
=item C<id>
2529

            
2530
    id => 4
2531
    id => [4, 5]
2532

            
2533
ID corresponding to C<primary_key>.
2534
You can select rows by C<id> and C<primary_key>.
2535

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

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

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

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

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

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

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

            
2563
    prefix => 'SQL_CALC_FOUND_ROWS'
2564

            
2565
Prefix of column cluase
2566

            
2567
    select SQL_CALC_FOUND_ROWS title, author from book;
2568

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2616
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2617

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

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

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

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

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

            
2641
Wrap statement. This is array reference.
2642

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

            
2645
This option is for Oracle and SQL Server paging process.
2646

            
update pod
Yuki Kimoto authored on 2011-03-12
2647
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2648

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2657
=over 4
2658

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2669
    id => 4
2670
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2671

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2725
=item C<type_rule_off> EXPERIMENTAL
2726

            
update pod
Yuki Kimoto authored on 2011-06-15
2727
Same as C<execute> method's <type_rule_off>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2728

            
updated pod
Yuki Kimoto authored on 2011-06-08
2729
=back
update pod
Yuki Kimoto authored on 2011-03-13
2730

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

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

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

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

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

            
2742
Create update parameter tag.
2743

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

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

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

            
2753
Create a new L<DBIx::Custom::Where> object.
2754

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2762
=head1 Parameter
2763

            
2764
Parameter start at ':'. This is replaced to place holoder
2765

            
2766
    $dbi->execute(
2767
        "select * from book where title = :title and author = :author"
2768
        param => {title => 'Perl', author => 'Ken'}
2769
    );
2770

            
2771
    "select * from book where title = ? and author = ?"
2772

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

            
2775
=head2 C<DBIX_CUSTOM_DEBUG>
2776

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

            
2780
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2781

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

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

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

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

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

            
2793
C<< <kimoto.yuki at gmail.com> >>
2794

            
2795
L<http://github.com/yuki-kimoto/DBIx-Custom>
2796

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2797
=head1 AUTHOR
2798

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

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

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

            
2805
This program is free software; you can redistribute it and/or modify it
2806
under the same terms as Perl itself.
2807

            
2808
=cut