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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
25
has [qw/connector dsn password quote user/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
26
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
27
    cache_method => sub {
28
        sub {
29
            my $self = shift;
30
            
31
            $self->{_cached} ||= {};
32
            
33
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
34
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
35
            }
36
            else {
update pod
Yuki Kimoto authored on 2011-03-13
37
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
38
            }
39
        }
update pod
Yuki Kimoto authored on 2011-03-13
40
    },
41
    dbi_option => sub { {} },
42
    default_dbi_option => sub {
43
        {
44
            RaiseError => 1,
45
            PrintError => 0,
46
            AutoCommit => 1
47
        }
48
    },
fix tests
Yuki Kimoto authored on 2011-01-13
49
    filters => sub {
50
        {
51
            encode_utf8 => sub { encode_utf8($_[0]) },
52
            decode_utf8 => sub { decode_utf8($_[0]) }
53
        }
update pod
Yuki Kimoto authored on 2011-03-13
54
    },
55
    models => sub { {} },
56
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
57
    result_class  => 'DBIx::Custom::Result',
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;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
88
    my $q = $self->_quote;
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
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
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
114
    my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
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
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
167
        if (my $q = $self->_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
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
224
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
225
            my $driver = $self->{dbh}->{Driver}->{Name};
226
            my $quote = $driver eq 'mysql' ? '`' : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
227
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
228
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
229
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
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;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
279
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
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);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
362
    my $bind_type = delete $args{bind_type} || delete $args{type};
363
    $bind_type = _array_to_hash($bind_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);
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
382
    if (my $q = $self->_quote) {
cleanup
Yuki Kimoto authored on 2011-04-02
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,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
437
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
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++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
445
            my $bind_type = $bind->[$i]->{bind_type};
446
            $sth->bind_param(
447
                $i + 1,
448
                $bind->[$i]->{value},
449
                $bind_type ? $bind_type : ()
450
            );
cleanup
Yuki Kimoto authored on 2011-03-21
451
        }
452
        $affected = $sth->execute;
453
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
454
    
455
    if ($@) {
456
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
457
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
458
    }
cleanup
yuki-kimoto authored on 2010-10-17
459
    
improved debug message
Yuki Kimoto authored on 2011-05-23
460
    # DEBUG message
461
    if (DEBUG) {
462
        print STDERR "SQL:\n" . $query->sql . "\n";
463
        my @output;
464
        foreach my $b (@$bind) {
465
            my $value = $b->{value};
466
            $value = 'undef' unless defined $value;
467
            $value = encode(DEBUG_ENCODING(), $value)
468
              if utf8::is_utf8($value);
469
            push @output, $value;
470
        }
471
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
472
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
473
    
cleanup
Yuki Kimoto authored on 2011-04-02
474
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
475
    if ($sth->{NUM_OF_FIELDS}) {
476
        
cleanup
Yuki Kimoto authored on 2011-04-02
477
        # Filter
478
        my $filter = {};
479
        $filter->{in}  = {};
480
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
481
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
482
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
483
            foreach my $way (qw/in end/) {
484
                $filter->{$way} = {
485
                    %{$filter->{$way}},
486
                    %{$self->{filter}{$way}{$table} || {}}
487
                };
488
            }
cleanup
Yuki Kimoto authored on 2011-01-12
489
        }
490
        
491
        # Result
492
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
493
            sth => $sth,
494
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
495
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
496
            filter => $filter->{in} || {},
497
            end_filter => $filter->{end} || {},
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
498
            type_rule => \%{$self->type_rule->{from}},
cleanup
yuki-kimoto authored on 2010-10-17
499
        );
500

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1354
sub _quote {
1355
    my $self = shift;
1356
    
1357
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1358
         : defined $self->quote ? $self->quote
1359
         : '';
1360
}
1361

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1431
# DEPRECATED!
1432
sub apply_filter {
1433
    my $self = shift;
1434
    
1435
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1436
         "use type_rule method and DBIx::Custom::Result filter method, " .
1437
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1438
    
1439
    return $self->_apply_filter(@_);
1440
}
1441

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

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

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

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

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

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

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1555
# DEPRECATED!
1556
sub register_tag {
1557
    warn "register_tag is DEPRECATED!";
1558
    shift->query_builder->register_tag(@_)
1559
}
1560

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1561
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1562
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1563
has dbi_options => sub { {} };
1564
has filter_check  => 1;
1565
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1566

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1673
=head1 NAME
1674

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

            
1677
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1678

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

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

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

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

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

            
1747
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1748

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1758
=item *
1759

            
1760
Filter when data is send or receive.
1761

            
1762
=item *
1763

            
1764
Data filtering system
1765

            
1766
=item *
1767

            
1768
Model support.
1769

            
1770
=item *
1771

            
1772
Generate where clause dinamically.
1773

            
1774
=item *
1775

            
1776
Generate join clause dinamically.
1777

            
1778
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1779

            
1780
=head1 GUIDE
1781

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

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

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

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

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

            
1792
    my $connector = $dbi->connector;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1793
    $dbi = $dbi->connector(DBIx::Connector->new(...));
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1794

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

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

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

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

            
1812
    my $dsn = $dbi->dsn;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1813
    $dbi = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
1814

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

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1819
    my $dbi_option = $dbi->dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1820
    $dbi = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1821

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

            
1825
=head2 C<default_dbi_option>
1826

            
1827
    my $default_dbi_option = $dbi->default_dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1828
    $dbi = $dbi->default_dbi_option($default_dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1829

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1844
    my $filters = $dbi->filters;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1845
    $dbi = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
1846

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

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

            
1851
    my $models = $dbi->models;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1852
    $dbi = $dbi->models(\%models);
add models() attribute
Yuki Kimoto authored on 2011-02-21
1853

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

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

            
1858
    my $password = $dbi->password;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1859
    $dbi = $dbi->password('lkj&le`@s');
cleanup
yuki-kimoto authored on 2010-10-17
1860

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1870
=head2 C<quote>
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1871

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1872
     my quote = $dbi->quote;
1873
     $dbi = $dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1874

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1881
    my $result_class = $dbi->result_class;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1882
    $dbi = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
1883

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1888
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1889
    $dbi = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
1890

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1896
    my $user = $dbi->user;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1897
    $dbi = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1898

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

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

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

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

            
1909
    print $dbi->available_data_type;
1910

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

            
1914
=head2 C<available_type_name> EXPERIMENTAL
1915

            
1916
    print $dbi->available_type_name;
1917

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

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

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

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

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

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

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

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

            
1935
Create column clause. The follwoing column clause is created.
1936

            
1937
    book.author as "book.author",
1938
    book.title as "book.title"
1939

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1942
    # Separator is double underbar
1943
    $dbi->separator('__');
1944
    
1945
    book.author as "book__author",
1946
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1947

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

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

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

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

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

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

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

            
1989
   $dbi->model('book')->select(...);
1990

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

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

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

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

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

            
2007
    my $dbh = $dbi->dbh;
2008

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

            
2012
=head2 C<each_column>
2013

            
2014
    $dbi->each_column(
2015
        sub {
2016
            my ($dbi, $table, $column, $column_info) = @_;
2017
            
2018
            my $type = $column_info->{TYPE_NAME};
2019
            
2020
            if ($type eq 'DATE') {
2021
                # ...
2022
            }
2023
        }
2024
    );
2025

            
2026
Iterate all column informations of all table from database.
2027
Argument is callback when one column is found.
2028
Callback receive four arguments, dbi object, table name,
2029
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2030

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

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

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

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

            
2044
    select * from where title = ? and author like ?;
2045

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

            
2048
=over 4
2049

            
2050
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2051
    
2052
    filter => {
2053
        title  => sub { uc $_[0] }
2054
        author => sub { uc $_[0] }
2055
    }
update pod
Yuki Kimoto authored on 2011-03-13
2056

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

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

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

            
2075
    query => 1
2076

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2079
=item C<table>
2080
    
2081
    table => 'author'
2082
    table => ['author', 'book']
2083

            
2084
Table names for filtering.
2085

            
2086
Filtering by C<apply_filter> is off in C<execute> method,
2087
because we don't know what filter is applied.
2088

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

            
2091
Specify database data type.
2092

            
2093
    type => [image => DBI::SQL_BLOB]
2094
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2095

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

            
2098
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2099

            
2100
C<type> option is also available
2101
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2102

            
2103
=item C<type_rule_off> EXPERIMENTAL
2104

            
2105
    type_rule_off => 1
2106

            
2107
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2108

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2119
=over 4
2120

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

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

            
2125
=item C<filter>
2126

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2131
    id => 4
2132
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2133

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2137
    $dbi->delete(
2138
        parimary_key => ['id1', 'id2'],
2139
        id => [4, 5],
2140
        table => 'book',
2141
    );
update pod
Yuki Kimoto authored on 2011-03-13
2142

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

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

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

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

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

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

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

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

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

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

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

            
2165
Same as C<execute> method's C<type> option.
2166

            
2167
=item C<type_rule_off> EXPERIMENTAL
2168

            
2169
Same as C<execute> method's C<type_rule_off> option.
2170

            
updated pod
Yuki Kimoto authored on 2011-06-08
2171
=back
update pod
Yuki Kimoto authored on 2011-03-13
2172

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2180
=head2 C<insert>
2181

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

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

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

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

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

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

            
2194
=item C<filter>
2195

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

            
2198
=item C<id>
2199

            
updated document
Yuki Kimoto authored on 2011-06-09
2200
    id => 4
2201
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2202

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

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

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

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

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

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

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

            
2227
=item C<param>
2228

            
2229
    param => {title => 'Perl', author => 'Ken'}
2230

            
2231
Insert data.
2232

            
2233
If C<insert> method's arguments is odd numbers,
2234
first argument is received as C<param>.
2235

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

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

            
2240
Same as C<execute> method's C<query> option.
2241

            
2242
=item C<table>
2243

            
2244
    table => 'book'
2245

            
2246
Table name.
2247

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2256
=back
2257

            
2258
=over 4
2259

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2275
    lib / MyModel.pm
2276
        / MyModel / book.pm
2277
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2278

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

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

            
2283
    package MyModel;
2284
    
2285
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2286
    
2287
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2288

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2293
    package MyModel::book;
2294
    
2295
    use base 'MyModel';
2296
    
2297
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2298

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2301
    package MyModel::company;
2302
    
2303
    use base 'MyModel';
2304
    
2305
    1;
2306
    
2307
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2308

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

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

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

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

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

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

            
2322
$param:
2323

            
2324
    {key1 => [1, 1], key2 => 2}
2325

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

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

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

            
2343
    $dbi->update_or_insert;
2344
    $dbi->find_or_create;
2345

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

            
2348
    $dbi->model('book')->method(
2349
        insert => sub { ... },
2350
        update => sub { ... }
2351
    );
2352
    
2353
    my $model = $dbi->model('book');
2354

            
2355
Set and get a L<DBIx::Custom::Model> object,
2356

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

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

            
2361
Create column clause for myself. The follwoing column clause is created.
2362

            
2363
    book.author as author,
2364
    book.title as title
2365

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

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

            
2375
Create a new L<DBIx::Custom> object.
2376

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

            
2379
    my $not_exists = $dbi->not_exists;
2380

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2384
=head2 C<register_filter>
2385

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2427
=over 4
2428

            
2429
=item 1. column name
2430

            
2431
    issue_date
2432
    issue_datetime
2433

            
2434
=item 2. table name and column name, separator is dot
2435

            
2436
    book.issue_date
2437
    book.issue_datetime
2438

            
2439
=back
2440

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

            
2443
    print $dbi->available_type_name;
2444

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

            
2449
    print $dbi->available_data_type;
2450

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

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

            
2455
    book-issue_date
2456
    book-issue_datetime
2457

            
2458
This is useful in HTML.
2459

            
2460
=back
2461

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

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

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

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

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

            
2486
=over 4
2487

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2533
=item C<id>
2534

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

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

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

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

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

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

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

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

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

            
2568
    prefix => 'SQL_CALC_FOUND_ROWS'
2569

            
2570
Prefix of column cluase
2571

            
2572
    select SQL_CALC_FOUND_ROWS title, author from book;
2573

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2646
Wrap statement. This is array reference.
2647

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2730
=item C<type_rule_off> EXPERIMENTAL
2731

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

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

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

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

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

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

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

            
2747
Create update parameter tag.
2748

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

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2767
=head1 Parameter
2768

            
2769
Parameter start at ':'. This is replaced to place holoder
2770

            
2771
    $dbi->execute(
2772
        "select * from book where title = :title and author = :author"
2773
        param => {title => 'Perl', author => 'Ken'}
2774
    );
2775

            
2776
    "select * from book where title = ? and author = ?"
2777

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

            
2780
=head2 C<DBIX_CUSTOM_DEBUG>
2781

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

            
2785
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2786

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

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

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

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

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

            
2798
C<< <kimoto.yuki at gmail.com> >>
2799

            
2800
L<http://github.com/yuki-kimoto/DBIx-Custom>
2801

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2802
=head1 AUTHOR
2803

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

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

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

            
2810
This program is free software; you can redistribute it and/or modify it
2811
under the same terms as Perl itself.
2812

            
2813
=cut