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

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

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
8
use Carp 'croak';
9
use DBI;
10
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
11
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
12
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
13
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
14
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
15
use DBIx::Custom::Tag;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
17
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
495
        return $result;
496
    }
cleanup
Yuki Kimoto authored on 2011-04-02
497
    
498
    # Not select statement
499
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
500
}
501

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

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

            
524
    # Check arguments
525
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
526
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
527
          unless $INSERT_ARGS{$name};
528
    }
529

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
530
    # Merge parameter
531
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
532
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
533
        $param = $self->merge_param($id_param, $param);
534
    }
535

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
575
sub include_model {
576
    my ($self, $name_space, $model_infos) = @_;
577
    
cleanup
Yuki Kimoto authored on 2011-04-02
578
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
579
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
580
    
581
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
582
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
583

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
664
sub method {
665
    my $self = shift;
666
    
cleanup
Yuki Kimoto authored on 2011-04-02
667
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
668
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
669
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
670
    
671
    return $self;
672
}
673

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
691
sub mycolumn {
692
    my ($self, $table, $columns) = @_;
693
    
cleanup
Yuki Kimoto authored on 2011-04-02
694
    # Create column clause
695
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
696
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
697
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
698
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
699
    
700
    return join (', ', @column);
701
}
702

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
733
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
734
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
735
    
736
    # Register filter
737
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
738
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
739
    
cleanup
Yuki Kimoto authored on 2011-04-02
740
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
741
}
packaging one directory
yuki-kimoto authored on 2009-11-16
742

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

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

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

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

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
888
sub separator {
889
    my $self = shift;
890
    
891
    if (@_) {
892
        my $separator = $_[0] || '';
893
        croak qq{Separator must be "." or "__" or "-" } . _subname
894
          unless $separator eq '.' || $separator eq '__'
895
              || $separator eq '-';
896
        
897
        $self->{separator} = $separator;
898
    
899
        return $self;
900
    }
901
    return $self->{separator} ||= '.';
902
}
903

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
904
sub setup_model {
905
    my $self = shift;
906
    
cleanup
Yuki Kimoto authored on 2011-04-02
907
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
908
    $self->each_column(
909
        sub {
910
            my ($self, $table, $column, $column_info) = @_;
911
            if (my $model = $self->models->{$table}) {
912
                push @{$model->columns}, $column;
913
            }
914
        }
915
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
916
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
917
}
918

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

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

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

            
981
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
982
            }
983
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
984
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
985

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

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1082
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1083
    my ($self, $param, $opt) = @_;
1084
    
cleanup
Yuki Kimoto authored on 2011-04-02
1085
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1086
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1087
    $tag = "set $tag" unless $opt->{no_set};
1088

            
cleanup
Yuki Kimoto authored on 2011-04-02
1089
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1090
}
1091

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1272
sub _croak {
1273
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1274
    
1275
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1276
    $append ||= "";
1277
    
1278
    # Verbose
1279
    if ($Carp::Verbose) { croak $error }
1280
    
1281
    # Not verbose
1282
    else {
1283
        
1284
        # Remove line and module infromation
1285
        my $at_pos = rindex($error, ' at ');
1286
        $error = substr($error, 0, $at_pos);
1287
        $error =~ s/\s+$//;
1288
        croak "$error$append";
1289
    }
1290
}
1291

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1292
sub _need_tables {
1293
    my ($self, $tree, $need_tables, $tables) = @_;
1294
    
cleanup
Yuki Kimoto authored on 2011-04-02
1295
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1296
    foreach my $table (@$tables) {
1297
        if ($tree->{$table}) {
1298
            $need_tables->{$table} = 1;
1299
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1300
        }
1301
    }
1302
}
1303

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1346
sub _remove_duplicate_table {
1347
    my ($self, $tables, $main_table) = @_;
1348
    
1349
    # Remove duplicate table
1350
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1351
    delete $tables{$main_table} if $main_table;
1352
    
1353
    return [keys %tables, $main_table ? $main_table : ()];
1354
}
1355

            
cleanup
Yuki Kimoto authored on 2011-04-02
1356
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1357
    my ($self, $source) = @_;
1358
    
cleanup
Yuki Kimoto authored on 2011-04-02
1359
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1360
    my $tables = [];
1361
    my $safety_character = $self->safety_character;
1362
    my $q = $self->reserved_word_quote;
1363
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1364
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1365
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1366
    while ($source =~ /$table_re/g) {
1367
        push @$tables, $1;
1368
    }
1369
    
1370
    return $tables;
1371
}
1372

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1415
# DEPRECATED!
1416
sub apply_filter {
1417
    my $self = shift;
1418
    
1419
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1420
         "use type_rule method and DBIx::Custom::Result filter method, " .
1421
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1422
    
1423
    return $self->_apply_filter(@_);
1424
}
1425

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1426
# DEPRECATED!
1427
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1428
sub select_at {
1429
    my ($self, %args) = @_;
1430

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

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

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1456
# DEPRECATED!
1457
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1458
sub delete_at {
1459
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1460

            
1461
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1462
    
1463
    # Arguments
1464
    my $primary_keys = delete $args{primary_key};
1465
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1466
    my $where = delete $args{where};
1467
    
1468
    # Check arguments
1469
    foreach my $name (keys %args) {
1470
        croak qq{"$name" is wrong option } . _subname
1471
          unless $DELETE_AT_ARGS{$name};
1472
    }
1473
    
1474
    # Create where parameter
1475
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1476
    
1477
    return $self->delete(where => $where_param, %args);
1478
}
1479

            
cleanup
Yuki Kimoto authored on 2011-06-08
1480
# DEPRECATED!
1481
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1482
sub update_at {
1483
    my $self = shift;
1484

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1539
# DEPRECATED!
1540
sub register_tag {
1541
    warn "register_tag is DEPRECATED!";
1542
    shift->query_builder->register_tag(@_)
1543
}
1544

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1545
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1546
has 'data_source';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1547

            
cleanup
Yuki Kimoto authored on 2011-01-25
1548
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1549
has dbi_options => sub { {} },
1550
    filter_check  => 1;
1551

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1577
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1578
sub default_fetch_filter {
1579
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1580

            
cleanup
Yuki Kimoto authored on 2011-06-13
1581
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1582
    
1583
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1584
        my $fname = $_[0];
1585

            
cleanup
Yuki Kimoto authored on 2011-01-12
1586
        if (@_ && !$fname) {
1587
            $self->{default_in_filter} = undef;
1588
        }
1589
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1590
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1591
              unless exists $self->filters->{$fname};
1592
        
1593
            $self->{default_in_filter} = $self->filters->{$fname};
1594
        }
1595
        
1596
        return $self;
1597
    }
1598
    
many changed
Yuki Kimoto authored on 2011-01-23
1599
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1600
}
1601

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1602
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1603
sub insert_param_tag {
1604
    warn "insert_param_tag is DEPRECATED! " .
1605
         "use insert_param instead!";
1606
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1607
}
1608

            
cleanup
Yuki Kimoto authored on 2011-01-25
1609
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1610
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1611
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1612
    return shift->query_builder->register_tag_processor(@_);
1613
}
1614

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

            
1637
# DEPRECATED!
1638
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1639
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1640
    
1641
    if (keys %{$relation || {}}) {
1642
        foreach my $rcolumn (keys %$relation) {
1643
            my $table1 = (split (/\./, $rcolumn))[0];
1644
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1645
            my $table1_exists;
1646
            my $table2_exists;
1647
            foreach my $table (@$tables) {
1648
                $table1_exists = 1 if $table eq $table1;
1649
                $table2_exists = 1 if $table eq $table2;
1650
            }
1651
            unshift @$tables, $table1 unless $table1_exists;
1652
            unshift @$tables, $table2 unless $table2_exists;
1653
        }
1654
    }
1655
}
1656

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1659
=head1 NAME
1660

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

            
1663
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1664

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1665
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1666
    
1667
    # Connect
1668
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1669
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1670
        user => 'ken',
1671
        password => '!LFKD%$&',
1672
        dbi_option => {mysql_enable_utf8 => 1}
1673
    );
cleanup
yuki-kimoto authored on 2010-08-05
1674

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1675
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1676
    $dbi->insert(
1677
        table  => 'book',
1678
        param  => {title => 'Perl', author => 'Ken'}
1679
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1680
    
1681
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1682
    $dbi->update(
1683
        table  => 'book', 
1684
        param  => {title => 'Perl', author => 'Ken'}, 
1685
        where  => {id => 5},
1686
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1687
    
1688
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1689
    $dbi->delete(
1690
        table  => 'book',
1691
        where  => {author => 'Ken'},
1692
    );
cleanup
yuki-kimoto authored on 2010-08-05
1693

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

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

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

            
1733
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1734

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1744
=item *
1745

            
1746
Filter when data is send or receive.
1747

            
1748
=item *
1749

            
1750
Data filtering system
1751

            
1752
=item *
1753

            
1754
Model support.
1755

            
1756
=item *
1757

            
1758
Generate where clause dinamically.
1759

            
1760
=item *
1761

            
1762
Generate join clause dinamically.
1763

            
1764
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1765

            
1766
=head1 GUIDE
1767

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

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

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

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

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

            
1778
    my $connector = $dbi->connector;
1779
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1780

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

            
1784
This is L<DBIx::Connector> example. Please pass
1785
C<default_dbi_option> to L<DBIx::Connector>.
1786

            
1787
    my $connector = DBIx::Connector->new(
1788
        "dbi:mysql:database=$DATABASE",
1789
        $USER,
1790
        $PASSWORD,
1791
        DBIx::Custom->new->default_dbi_option
1792
    );
1793
    
1794
    my $dbi = DBIx::Custom->new(connector => $connector);
1795

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

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

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

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

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

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

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

            
1813
=head2 C<default_dbi_option>
1814

            
1815
    my $default_dbi_option = $dbi->default_dbi_option;
1816
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1817

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1821
    {
1822
        RaiseError => 1,
1823
        PrintError => 0,
1824
        AutoCommit => 1,
1825
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1826

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

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

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

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

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

            
1839
    my $models = $dbi->models;
1840
    $dbi       = $dbi->models(\%models);
1841

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1844
=head2 C<password>
1845

            
1846
    my $password = $dbi->password;
1847
    $dbi         = $dbi->password('lkj&le`@s');
1848

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

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

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

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

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

            
1860
     my reserved_word_quote = $dbi->reserved_word_quote;
1861
     $dbi                   = $dbi->reserved_word_quote('"');
1862

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1882
    my $user = $dbi->user;
1883
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1884

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

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

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

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

            
1895
    print $dbi->available_data_type;
1896

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

            
1900
=head2 C<available_type_name> EXPERIMENTAL
1901

            
1902
    print $dbi->available_type_name;
1903

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

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

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

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

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

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

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

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

            
1921
Create column clause. The follwoing column clause is created.
1922

            
1923
    book.author as "book.author",
1924
    book.title as "book.title"
1925

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

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

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

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

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

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

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

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

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

            
1975
   $dbi->model('book')->select(...);
1976

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

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

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

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

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

            
1993
    my $dbh = $dbi->dbh;
1994

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

            
1998
=head2 C<each_column>
1999

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

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

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

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

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

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

            
2030
    select * from where title = ? and author like ?;
2031

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

            
2034
=over 4
2035

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

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

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

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

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

            
2062
    query => 1
2063

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

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

            
2071
Table names for filtering.
2072

            
2073
Filtering by C<apply_filter> is off in C<execute> method,
2074
because we don't know what filter is applied.
2075

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

            
2078
Specify database data type.
2079

            
2080
    type => [image => DBI::SQL_BLOB]
2081
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2082

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

            
2085
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2086

            
2087
C<type> option is also available
2088
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2089

            
2090
=item C<type_rule_off> EXPERIMENTAL
2091

            
2092
    type_rule_off => 1
2093

            
2094
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2095

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2106
=over 4
2107

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

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

            
2112
=item C<filter>
2113

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2118
    id => 4
2119
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2120

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2152
Same as C<execute> method's C<type> option.
2153

            
2154
=item C<type_rule_off> EXPERIMENTAL
2155

            
2156
Same as C<execute> method's C<type_rule_off> option.
2157

            
updated pod
Yuki Kimoto authored on 2011-06-08
2158
=back
update pod
Yuki Kimoto authored on 2011-03-13
2159

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2167
=head2 C<insert>
2168

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

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

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

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

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

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

            
2181
=item C<filter>
2182

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

            
2185
=item C<id>
2186

            
updated document
Yuki Kimoto authored on 2011-06-09
2187
    id => 4
2188
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2189

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

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

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

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

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

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

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

            
2214
=item C<param>
2215

            
2216
    param => {title => 'Perl', author => 'Ken'}
2217

            
2218
Insert data.
2219

            
2220
If C<insert> method's arguments is odd numbers,
2221
first argument is received as C<param>.
2222

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

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

            
2227
Same as C<execute> method's C<query> option.
2228

            
2229
=item C<table>
2230

            
2231
    table => 'book'
2232

            
2233
Table name.
2234

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2243
=back
2244

            
2245
=over 4
2246

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2286
B<MyModel/company.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::company;
2289
    
2290
    use base 'MyModel';
2291
    
2292
    1;
2293
    
2294
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2295

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

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

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

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

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

            
2307
Merge paramters.
2308

            
2309
$param:
2310

            
2311
    {key1 => [1, 1], key2 => 2}
2312

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

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

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

            
2330
    $dbi->update_or_insert;
2331
    $dbi->find_or_create;
2332

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

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

            
2342
Set and get a L<DBIx::Custom::Model> object,
2343

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

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

            
2348
Create column clause for myself. The follwoing column clause is created.
2349

            
2350
    book.author as author,
2351
    book.title as title
2352

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

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

            
2362
Create a new L<DBIx::Custom> object.
2363

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

            
2366
    my $not_exists = $dbi->not_exists;
2367

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2371
=head2 C<register_filter>
2372

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

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

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

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

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

            
2411
=over 4
2412

            
2413
=item 1. column name
2414

            
2415
    issue_date
2416
    issue_datetime
2417

            
2418
=item 2. table name and column name, separator is dot
2419

            
2420
    book.issue_date
2421
    book.issue_datetime
2422

            
2423
=back
2424

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

            
2429
    print $dbi->available_data_type;
2430

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

            
2433
=item 1. column name
2434

            
2435
    issue_date
2436
    issue_datetime
2437

            
2438
=item 2. table name and column name, separator is dot
2439

            
2440
    book.issue_date
2441
    book.issue_datetime
2442

            
2443
=item 3. table name and column name, separator is double underbar
2444

            
2445
    book__issue_date
2446
    book__issue_datetime
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

            
2727
Turn type rule off.
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

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

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

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

            
2755
Create a new L<DBIx::Custom::Where> object.
2756

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

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

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

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

            
2766
Update statement, using primary key.
2767

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

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

            
2779
=head2 C<delete_at()> DEPRECATED!
2780

            
2781
Delete statement, using primary key.
2782

            
2783
    $dbi->delete_at(
2784
        table => 'book',
2785
        primary_key => 'id',
2786
        where => '5'
2787
    );
2788

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

            
2793
=head2 C<select_at()> DEPRECATED!
2794

            
2795
Select statement, using primary key.
2796

            
2797
    $dbi->select_at(
2798
        table => 'book',
2799
        primary_key => 'id',
2800
        where => '5'
2801
    );
2802

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

            
2807
=head2 C<register_tag> DEPRECATED!
2808

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

            
2822
Register tag, used by C<execute()>.
2823

            
2824
See also L<Tags/Tags> about tag registered by default.
2825

            
2826
Tag parser receive arguments specified in tag.
2827
In the following tag, 'title' and 'author' is parser arguments
2828

            
2829
    {update_param title author} 
2830

            
2831
Tag parser must return array refrence,
2832
first element is the result statement, 
2833
second element is column names corresponding to place holders.
2834

            
2835
In this example, result statement is 
2836

            
2837
    set title = ?, author = ?
2838

            
2839
Column names is
2840

            
2841
    ['title', 'author']
2842

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

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

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

            
2864
Filter is applied to the follwoing tree column name pattern.
2865

            
2866
       PETTERN         EXAMPLE
2867
    1. Column        : author
2868
    2. Table.Column  : book.author
2869
    3. Table__Column : book__author
2870
    4. Table-Column  : book-author
2871

            
2872
If column name is duplicate with other table,
2873
Main filter specified by C<table> option is used.
2874

            
2875
You can set multiple filters at once.
2876

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2886
=head1 Parameter
2887

            
2888
Parameter start at ':'. This is replaced to place holoder
2889

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

            
2895
    "select * from book where title = ? and author = ?"
2896

            
2897
=head1 Tags DEPRECATED!
2898

            
2899
B<Tag> system is DEPRECATED! use parameter system :name instead.
2900
Parameter is simple and readable.
2901

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

            
2904
The following tags is available.
2905

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

            
2908
Placeholder tag.
2909

            
2910
    {? NAME}    ->   ?
2911

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

            
2914
Equal tag.
2915

            
2916
    {= NAME}    ->   NAME = ?
2917

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

            
2920
Not equal tag.
2921

            
2922
    {<> NAME}   ->   NAME <> ?
2923

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

            
2926
Lower than tag
2927

            
2928
    {< NAME}    ->   NAME < ?
2929

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

            
2932
Greater than tag
2933

            
2934
    {> NAME}    ->   NAME > ?
2935

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

            
2938
Greater than or equal tag
2939

            
2940
    {>= NAME}   ->   NAME >= ?
2941

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

            
2944
Lower than or equal tag
2945

            
2946
    {<= NAME}   ->   NAME <= ?
2947

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

            
2950
Like tag
2951

            
2952
    {like NAME}   ->   NAME like ?
2953

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

            
2956
In tag.
2957

            
2958
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2959

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

            
2962
Insert parameter tag.
2963

            
2964
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2965

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

            
2968
Updata parameter tag.
2969

            
2970
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2971

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

            
2974
Insert statement, using primary key.
2975

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

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

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

            
2989
=head2 C<DBIX_CUSTOM_DEBUG>
2990

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

            
2994
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2995

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

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

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

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

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

            
3007
C<< <kimoto.yuki at gmail.com> >>
3008

            
3009
L<http://github.com/yuki-kimoto/DBIx-Custom>
3010

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3011
=head1 AUTHOR
3012

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

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

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

            
3019
This program is free software; you can redistribute it and/or modify it
3020
under the same terms as Perl itself.
3021

            
3022
=cut