DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3028 lines | 75.569kb
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
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
387
    my $type_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
            {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
402
                $type_filter->{$column} = $rule;
403
                $type_filter->{"$table.$column"} = $rule;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
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
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
409
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
410
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
411
        $applied_filter = {
412
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
413
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
414
        }
415
    }
cleanup
Yuki Kimoto authored on 2011-04-02
416
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
417
    
cleanup
Yuki Kimoto authored on 2011-04-02
418
    # Replace filter name to code
419
    foreach my $column (keys %$filter) {
420
        my $name = $filter->{$column};
421
        if (!defined $name) {
422
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
423
        }
cleanup
Yuki Kimoto authored on 2011-04-02
424
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
425
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
426
            unless exists $self->filters->{$name};
427
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
428
        }
429
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
430
    
cleanup
Yuki Kimoto authored on 2011-04-02
431
    # Create bind values
432
    my $bind = $self->_create_bind_values(
433
        $param,
434
        $query->columns,
435
        $filter,
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
436
        $type_filter,
cleanup
Yuki Kimoto authored on 2011-04-02
437
        $type
438
    );
cleanup
yuki-kimoto authored on 2010-10-17
439
    
440
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
441
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
442
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
443
    eval {
444
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
445
            my $type = $bind->[$i]->{type};
446
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
447
        }
448
        $affected = $sth->execute;
449
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
450
    
451
    if ($@) {
452
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
453
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
454
    }
cleanup
yuki-kimoto authored on 2010-10-17
455
    
improved debug message
Yuki Kimoto authored on 2011-05-23
456
    # DEBUG message
457
    if (DEBUG) {
458
        print STDERR "SQL:\n" . $query->sql . "\n";
459
        my @output;
460
        foreach my $b (@$bind) {
461
            my $value = $b->{value};
462
            $value = 'undef' unless defined $value;
463
            $value = encode(DEBUG_ENCODING(), $value)
464
              if utf8::is_utf8($value);
465
            push @output, $value;
466
        }
467
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
468
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
469
    
cleanup
Yuki Kimoto authored on 2011-04-02
470
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
471
    if ($sth->{NUM_OF_FIELDS}) {
472
        
cleanup
Yuki Kimoto authored on 2011-04-02
473
        # Filter
474
        my $filter = {};
475
        $filter->{in}  = {};
476
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
477
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
478
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
479
            foreach my $way (qw/in end/) {
480
                $filter->{$way} = {
481
                    %{$filter->{$way}},
482
                    %{$self->{filter}{$way}{$table} || {}}
483
                };
484
            }
cleanup
Yuki Kimoto authored on 2011-01-12
485
        }
486
        
487
        # Result
488
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
489
            sth => $sth,
490
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
491
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
492
            filter => $filter->{in} || {},
493
            end_filter => $filter->{end} || {},
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
494
            type_rule => \%{$self->type_rule->{from}},
cleanup
yuki-kimoto authored on 2010-10-17
495
        );
496

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1543
# DEPRECATED!
1544
sub register_tag {
1545
    warn "register_tag is DEPRECATED!";
1546
    shift->query_builder->register_tag(@_)
1547
}
1548

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1549
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1550
has 'data_source';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1551

            
cleanup
Yuki Kimoto authored on 2011-01-25
1552
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1553
has dbi_options => sub { {} },
1554
    filter_check  => 1;
1555

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1581
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1582
sub default_fetch_filter {
1583
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1584

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1663
=head1 NAME
1664

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

            
1667
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1668

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

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

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

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

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

            
1737
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1738

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1748
=item *
1749

            
1750
Filter when data is send or receive.
1751

            
1752
=item *
1753

            
1754
Data filtering system
1755

            
1756
=item *
1757

            
1758
Model support.
1759

            
1760
=item *
1761

            
1762
Generate where clause dinamically.
1763

            
1764
=item *
1765

            
1766
Generate join clause dinamically.
1767

            
1768
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1769

            
1770
=head1 GUIDE
1771

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

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

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

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

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

            
1782
    my $connector = $dbi->connector;
1783
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1784

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

            
1788
This is L<DBIx::Connector> example. Please pass
1789
C<default_dbi_option> to L<DBIx::Connector>.
1790

            
1791
    my $connector = DBIx::Connector->new(
1792
        "dbi:mysql:database=$DATABASE",
1793
        $USER,
1794
        $PASSWORD,
1795
        DBIx::Custom->new->default_dbi_option
1796
    );
1797
    
1798
    my $dbi = DBIx::Custom->new(connector => $connector);
1799

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

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

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

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

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

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

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

            
1817
=head2 C<default_dbi_option>
1818

            
1819
    my $default_dbi_option = $dbi->default_dbi_option;
1820
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1821

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

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

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

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

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

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

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

            
1843
    my $models = $dbi->models;
1844
    $dbi       = $dbi->models(\%models);
1845

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1848
=head2 C<password>
1849

            
1850
    my $password = $dbi->password;
1851
    $dbi         = $dbi->password('lkj&le`@s');
1852

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

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

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

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

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

            
1864
     my reserved_word_quote = $dbi->reserved_word_quote;
1865
     $dbi                   = $dbi->reserved_word_quote('"');
1866

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1886
    my $user = $dbi->user;
1887
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1888

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

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

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

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

            
1899
    print $dbi->available_data_type;
1900

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

            
1904
=head2 C<available_type_name> EXPERIMENTAL
1905

            
1906
    print $dbi->available_type_name;
1907

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1911
=head2 C<assign_param> EXPERIMENTAL
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
    my $assign_param = $dbi->assign_param({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1914

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2002
=head2 C<each_column>
2003

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

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

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

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

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

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

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

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

            
2038
=over 4
2039

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

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

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

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

            
2065
    query => 1
2066

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

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

            
2074
Table names for filtering.
2075

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

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

            
2081
Specify database data type.
2082

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

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

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

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

            
2093
=item C<type_rule_off> EXPERIMENTAL
2094

            
2095
    type_rule_off => 1
2096

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

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

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

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

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

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

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

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

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

            
2115
=item C<filter>
2116

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2157
=item C<type_rule_off> EXPERIMENTAL
2158

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

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

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

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

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

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

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

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

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

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

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

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

            
2184
=item C<filter>
2185

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

            
2188
=item C<id>
2189

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

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

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

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

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

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

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

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

            
2217
=item C<param>
2218

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

            
2221
Insert data.
2222

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

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

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

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

            
2232
=item C<table>
2233

            
2234
    table => 'book'
2235

            
2236
Table name.
2237

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

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

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

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

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

            
2248
=over 4
2249

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2310
Merge paramters.
2311

            
2312
$param:
2313

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2417
=over 4
2418

            
2419
=item 1. column name
2420

            
2421
    issue_date
2422
    issue_datetime
2423

            
2424
=item 2. table name and column name, separator is dot
2425

            
2426
    book.issue_date
2427
    book.issue_datetime
2428

            
2429
=back
2430

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

            
2435
    print $dbi->available_data_type;
2436

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

            
2439
=item 1. column name
2440

            
2441
    issue_date
2442
    issue_datetime
2443

            
2444
=item 2. table name and column name, separator is dot
2445

            
2446
    book.issue_date
2447
    book.issue_datetime
2448

            
2449
=item 3. table name and column name, separator is double underbar
2450

            
2451
    book__issue_date
2452
    book__issue_datetime
2453

            
2454
=item 4. table name and column name, separator is hyphen
2455

            
2456
    book-issue_date
2457
    book-issue_datetime
2458

            
2459
This is useful in HTML.
2460

            
2461
=back
2462

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

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

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

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

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

            
2487
=over 4
2488

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

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

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

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

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

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

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

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

            
2515
    book.author as "book.author",
2516
    book.title as "book.title",
2517
    person.name as "person.name",
2518
    person.age as "person.age"
2519

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

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

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

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

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

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

            
2534
=item C<id>
2535

            
2536
    id => 4
2537
    id => [4, 5]
2538

            
2539
ID corresponding to C<primary_key>.
2540
You can select rows by C<id> and C<primary_key>.
2541

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

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

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

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

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

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

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

            
2569
    prefix => 'SQL_CALC_FOUND_ROWS'
2570

            
2571
Prefix of column cluase
2572

            
2573
    select SQL_CALC_FOUND_ROWS title, author from book;
2574

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2622
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2623

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

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

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

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

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

            
2647
Wrap statement. This is array reference.
2648

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

            
2651
This option is for Oracle and SQL Server paging process.
2652

            
update pod
Yuki Kimoto authored on 2011-03-12
2653
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2654

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2663
=over 4
2664

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2675
    id => 4
2676
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2677

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2729
Same as C<execute> method's C<type> option.
2730

            
2731
=item C<type_rule_off> EXPERIMENTAL
2732

            
2733
Turn type rule off.
2734

            
updated pod
Yuki Kimoto authored on 2011-06-08
2735
=back
update pod
Yuki Kimoto authored on 2011-03-13
2736

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

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

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

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

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

            
2748
Create update parameter tag.
2749

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

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

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

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

            
2761
Create a new L<DBIx::Custom::Where> object.
2762

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

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

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

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

            
2772
Update statement, using primary key.
2773

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

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

            
2785
=head2 C<delete_at()> DEPRECATED!
2786

            
2787
Delete statement, using primary key.
2788

            
2789
    $dbi->delete_at(
2790
        table => 'book',
2791
        primary_key => 'id',
2792
        where => '5'
2793
    );
2794

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

            
2799
=head2 C<select_at()> DEPRECATED!
2800

            
2801
Select statement, using primary key.
2802

            
2803
    $dbi->select_at(
2804
        table => 'book',
2805
        primary_key => 'id',
2806
        where => '5'
2807
    );
2808

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

            
2813
=head2 C<register_tag> DEPRECATED!
2814

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

            
2828
Register tag, used by C<execute()>.
2829

            
2830
See also L<Tags/Tags> about tag registered by default.
2831

            
2832
Tag parser receive arguments specified in tag.
2833
In the following tag, 'title' and 'author' is parser arguments
2834

            
2835
    {update_param title author} 
2836

            
2837
Tag parser must return array refrence,
2838
first element is the result statement, 
2839
second element is column names corresponding to place holders.
2840

            
2841
In this example, result statement is 
2842

            
2843
    set title = ?, author = ?
2844

            
2845
Column names is
2846

            
2847
    ['title', 'author']
2848

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

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

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

            
2870
Filter is applied to the follwoing tree column name pattern.
2871

            
2872
       PETTERN         EXAMPLE
2873
    1. Column        : author
2874
    2. Table.Column  : book.author
2875
    3. Table__Column : book__author
2876
    4. Table-Column  : book-author
2877

            
2878
If column name is duplicate with other table,
2879
Main filter specified by C<table> option is used.
2880

            
2881
You can set multiple filters at once.
2882

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2892
=head1 Parameter
2893

            
2894
Parameter start at ':'. This is replaced to place holoder
2895

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

            
2901
    "select * from book where title = ? and author = ?"
2902

            
2903
=head1 Tags DEPRECATED!
2904

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

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

            
2910
The following tags is available.
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
Placeholder tag.
2915

            
2916
    {? NAME}    ->   ?
2917

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

            
2920
Equal tag.
2921

            
2922
    {= NAME}    ->   NAME = ?
2923

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

            
2926
Not equal tag.
2927

            
2928
    {<> NAME}   ->   NAME <> ?
2929

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

            
2932
Lower 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 tag
2939

            
2940
    {> NAME}    ->   NAME > ?
2941

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

            
2944
Greater than or equal tag
2945

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

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

            
2950
Lower than or equal tag
2951

            
2952
    {<= NAME}   ->   NAME <= ?
2953

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

            
2956
Like tag
2957

            
2958
    {like NAME}   ->   NAME like ?
2959

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

            
2962
In tag.
2963

            
2964
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2965

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

            
2968
Insert parameter tag.
2969

            
2970
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2971

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

            
2974
Updata parameter tag.
2975

            
2976
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2977

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

            
2980
Insert statement, using primary key.
2981

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

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

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

            
2995
=head2 C<DBIX_CUSTOM_DEBUG>
2996

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

            
3000
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3001

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

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

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

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

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

            
3013
C<< <kimoto.yuki at gmail.com> >>
3014

            
3015
L<http://github.com/yuki-kimoto/DBIx-Custom>
3016

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3017
=head1 AUTHOR
3018

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

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

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

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

            
3028
=cut