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

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

            
512
        return $result;
513
    }
cleanup
Yuki Kimoto authored on 2011-04-02
514
    
515
    # Not select statement
516
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
517
}
518

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

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

            
541
    # Check arguments
542
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
543
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
544
          unless $INSERT_ARGS{$name};
545
    }
546

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
547
    # Merge parameter
548
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
549
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
550
        $param = $self->merge_param($id_param, $param);
551
    }
552

            
cleanup
Yuki Kimoto authored on 2011-04-02
553
    # Reserved word quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
554
    my $q = $self->_quote;
cleanup
yuki-kimoto authored on 2010-10-17
555
    
cleanup
Yuki Kimoto authored on 2011-04-02
556
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
557
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
558
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
559
    push @sql, $append if $append;
560
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
561
    
562
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
563
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
564
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
565
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
566
        table => $table,
567
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
568
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
569
}
570

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
592
sub include_model {
593
    my ($self, $name_space, $model_infos) = @_;
594
    
cleanup
Yuki Kimoto authored on 2011-04-02
595
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
596
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
597
    
598
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
599
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
600

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

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
657
sub merge_param {
658
    my ($self, @params) = @_;
659
    
cleanup
Yuki Kimoto authored on 2011-04-02
660
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
661
    my $merge = {};
662
    foreach my $param (@params) {
663
        foreach my $column (keys %$param) {
664
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
665
            
666
            if (exists $merge->{$column}) {
667
                $merge->{$column} = [$merge->{$column}]
668
                  unless ref $merge->{$column} eq 'ARRAY';
669
                push @{$merge->{$column}},
670
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
671
            }
672
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
673
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
674
            }
675
        }
676
    }
677
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
678
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
679
}
680

            
cleanup
Yuki Kimoto authored on 2011-03-21
681
sub method {
682
    my $self = shift;
683
    
cleanup
Yuki Kimoto authored on 2011-04-02
684
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
685
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
686
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
687
    
688
    return $self;
689
}
690

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
691
sub model {
692
    my ($self, $name, $model) = @_;
693
    
cleanup
Yuki Kimoto authored on 2011-04-02
694
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
695
    if ($model) {
696
        $self->models->{$name} = $model;
697
        return $self;
698
    }
699
    
700
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
701
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
702
      unless $self->models->{$name};
703
    
cleanup
Yuki Kimoto authored on 2011-04-02
704
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
705
    return $self->models->{$name};
706
}
707

            
cleanup
Yuki Kimoto authored on 2011-03-21
708
sub mycolumn {
709
    my ($self, $table, $columns) = @_;
710
    
cleanup
Yuki Kimoto authored on 2011-04-02
711
    # Create column clause
712
    my @column;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
713
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
714
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
715
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
716
    
717
    return join (', ', @column);
718
}
719

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
750
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
751
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
752
    
753
    # Register filter
754
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
755
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
756
    
cleanup
Yuki Kimoto authored on 2011-04-02
757
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
758
}
packaging one directory
yuki-kimoto authored on 2009-11-16
759

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

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

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

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

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
905
sub separator {
906
    my $self = shift;
907
    
908
    if (@_) {
909
        my $separator = $_[0] || '';
910
        croak qq{Separator must be "." or "__" or "-" } . _subname
911
          unless $separator eq '.' || $separator eq '__'
912
              || $separator eq '-';
913
        
914
        $self->{separator} = $separator;
915
    
916
        return $self;
917
    }
918
    return $self->{separator} ||= '.';
919
}
920

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
921
sub setup_model {
922
    my $self = shift;
923
    
cleanup
Yuki Kimoto authored on 2011-04-02
924
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
925
    $self->each_column(
926
        sub {
927
            my ($self, $table, $column, $column_info) = @_;
928
            if (my $model = $self->models->{$table}) {
929
                push @{$model->columns}, $column;
930
            }
931
        }
932
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
933
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
934
}
935

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
936
sub available_data_type {
937
    my $self = shift;
938
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
939
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
940
    foreach my $i (-1000 .. 1000) {
941
         my $type_info = $self->dbh->type_info($i);
942
         my $data_type = $type_info->{DATA_TYPE};
943
         my $type_name = $type_info->{TYPE_NAME};
944
         $data_types .= "$data_type ($type_name)\n"
945
           if defined $data_type;
946
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
947
    return "Data Type maybe equal to Type Name" unless $data_types;
948
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
949
    return $data_types;
950
}
951

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
952
sub available_type_name {
953
    my $self = shift;
954
    
955
    # Type Names
956
    my $type_names = {};
957
    $self->each_column(sub {
958
        my ($self, $table, $column, $column_info) = @_;
959
        $type_names->{$column_info->{TYPE_NAME}} = 1
960
          if $column_info->{TYPE_NAME};
961
    });
962
    my @output = sort keys %$type_names;
963
    unshift @output, "Type Name";
964
    return join "\n", @output;
965
}
966

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
967
sub type_rule {
968
    my $self = shift;
969
    
970
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
971
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
972
        
973
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
974
        foreach my $i (1 .. 2) {
975
            my $into = "into$i";
976
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
977
            $self->{type_rule} = $type_rule;
978
            $self->{"_$into"} = {};
979
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
980
                croak qq{type name of $into section must be lower case}
981
                  if $type_name =~ /[A-Z]/;
982
            }
983
            $self->each_column(sub {
984
                my ($dbi, $table, $column, $column_info) = @_;
985
                
986
                my $type_name = lc $column_info->{TYPE_NAME};
987
                if ($type_rule->{$into} &&
988
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
989
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
990
                    return unless exists $type_rule->{$into}->{$type_name};
991
                    if  (defined $filter && ref $filter ne 'CODE') 
992
                    {
993
                        my $fname = $filter;
994
                        croak qq{Filter "$fname" is not registered" } . _subname
995
                          unless exists $self->filters->{$fname};
996
                        
997
                        $filter = $self->filters->{$fname};
998
                    }
999

            
1000
                    $self->{"_$into"}{$table}{$column} = $filter;
1001
                }
1002
            });
1003
        }
1004

            
1005
        # From
1006
        foreach my $i (1 .. 2) {
1007
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1008
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1009
                croak qq{data type of from$i section must be lower case or number}
1010
                  if $data_type =~ /[A-Z]/;
1011
                my $fname = $type_rule->{"from$i"}{$data_type};
1012
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1013
                    croak qq{Filter "$fname" is not registered" } . _subname
1014
                      unless exists $self->filters->{$fname};
1015
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1016
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1017
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1018
            }
1019
        }
1020
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1021
        return $self;
1022
    }
1023
    
1024
    return $self->{type_rule} || {};
1025
}
1026

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1103
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1104
    my ($self, $param, $opt) = @_;
1105
    
cleanup
Yuki Kimoto authored on 2011-04-02
1106
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1107
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1108
    $tag = "set $tag" unless $opt->{no_set};
1109

            
cleanup
Yuki Kimoto authored on 2011-04-02
1110
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1111
}
1112

            
cleanup
Yuki Kimoto authored on 2011-01-25
1113
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1114
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1115
    
1116
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1117
    return DBIx::Custom::Where->new(
1118
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1119
        safety_character => $self->safety_character,
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1120
        quote => $self->_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1121
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1122
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1123
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1124

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1194
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1195
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1196
    
cleanup
Yuki Kimoto authored on 2011-04-02
1197
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1198
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1199
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1200
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1201
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1202
        
1203
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1204
        my $value;
1205
        if(ref $params->{$column} eq 'ARRAY') {
1206
            my $i = $count->{$column} || 0;
1207
            $i += $not_exists->{$column} || 0;
1208
            my $found;
1209
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1210
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1211
                    $not_exists->{$column}++;
1212
                }
1213
                else  {
1214
                    $value = $params->{$column}->[$k];
1215
                    $found = 1;
1216
                    last
1217
                }
1218
            }
1219
            next unless $found;
1220
        }
1221
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1222
        
cleanup
Yuki Kimoto authored on 2011-01-12
1223
        # Filter
1224
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1225
        $value = $f->($value) if $f;
1226
        
1227
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1228
        foreach my $i (1 .. 2) {
1229
            my $type_filter = $type_filters->{$i};
1230
            my $tf = $type_filter->{$column};
1231
            $value = $tf->($value) if $tf;
1232
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1233
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1234
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1235
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1236
        
1237
        # Count up 
1238
        $count->{$column}++;
1239
    }
1240
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1241
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1242
}
1243

            
cleanup
Yuki Kimoto authored on 2011-06-08
1244
sub _create_param_from_id {
1245
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1246
    
cleanup
Yuki Kimoto authored on 2011-06-08
1247
    # Create parameter
1248
    my $param = {};
1249
    if ($id) {
1250
        $id = [$id] unless ref $id;
1251
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1252
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1253
          unless !ref $id || ref $id eq 'ARRAY';
1254
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1255
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1256
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1257
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1258
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1259
        }
1260
    }
1261
    
cleanup
Yuki Kimoto authored on 2011-06-08
1262
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1263
}
1264

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1265
sub _connect {
1266
    my $self = shift;
1267
    
1268
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1269
    my $dsn = $self->data_source;
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1270
    warn "data_source is DEPRECATED! use dsn instead\n"
1271
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1272
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1273
    croak qq{"dsn" must be specified } . _subname
1274
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1275
    my $user        = $self->user;
1276
    my $password    = $self->password;
1277
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1278
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1279
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1280
    
1281
    # Connect
1282
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1283
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1284
        $user,
1285
        $password,
1286
        {
1287
            %{$self->default_dbi_option},
1288
            %$dbi_option
1289
        }
1290
    )};
1291
    
1292
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1293
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1294
    
1295
    return $dbh;
1296
}
1297

            
cleanup
yuki-kimoto authored on 2010-10-17
1298
sub _croak {
1299
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1300
    
1301
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1302
    $append ||= "";
1303
    
1304
    # Verbose
1305
    if ($Carp::Verbose) { croak $error }
1306
    
1307
    # Not verbose
1308
    else {
1309
        
1310
        # Remove line and module infromation
1311
        my $at_pos = rindex($error, ' at ');
1312
        $error = substr($error, 0, $at_pos);
1313
        $error =~ s/\s+$//;
1314
        croak "$error$append";
1315
    }
1316
}
1317

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1318
sub _need_tables {
1319
    my ($self, $tree, $need_tables, $tables) = @_;
1320
    
cleanup
Yuki Kimoto authored on 2011-04-02
1321
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1322
    foreach my $table (@$tables) {
1323
        if ($tree->{$table}) {
1324
            $need_tables->{$table} = 1;
1325
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1326
        }
1327
    }
1328
}
1329

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1372
sub _quote {
1373
    my $self = shift;
1374
    
1375
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1376
         : defined $self->quote ? $self->quote
1377
         : '';
1378
}
1379

            
cleanup
Yuki Kimoto authored on 2011-04-02
1380
sub _remove_duplicate_table {
1381
    my ($self, $tables, $main_table) = @_;
1382
    
1383
    # Remove duplicate table
1384
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1385
    delete $tables{$main_table} if $main_table;
1386
    
1387
    return [keys %tables, $main_table ? $main_table : ()];
1388
}
1389

            
cleanup
Yuki Kimoto authored on 2011-04-02
1390
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1391
    my ($self, $source) = @_;
1392
    
cleanup
Yuki Kimoto authored on 2011-04-02
1393
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1394
    my $tables = [];
1395
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1396
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1397
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1398
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1399
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1400
    while ($source =~ /$table_re/g) {
1401
        push @$tables, $1;
1402
    }
1403
    
1404
    return $tables;
1405
}
1406

            
cleanup
Yuki Kimoto authored on 2011-04-02
1407
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1408
    my ($self, $where) = @_;
1409
    
cleanup
Yuki Kimoto authored on 2011-04-02
1410
    my $obj;
1411
    
1412
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1413
    if (ref $where eq 'HASH') {
1414
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1415
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1416
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1417
            my $column_quote = "$q$column$q";
1418
            $column_quote =~ s/\./$q.$q/;
1419
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1420
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1421
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1422
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1423
    
1424
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1425
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1426
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1427
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1428
    
1429
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1430
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1431
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1432
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1433
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1434
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1435
            clause => $where->[0],
1436
            param  => $where->[1]
1437
        );
1438
    }
1439
    
cleanup
Yuki Kimoto authored on 2011-04-02
1440
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1441
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1442
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1443
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1444
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1445
    
cleanup
Yuki Kimoto authored on 2011-04-02
1446
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1447
}
1448

            
cleanup
Yuki Kimoto authored on 2011-06-13
1449
# DEPRECATED!
1450
sub apply_filter {
1451
    my $self = shift;
1452
    
1453
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1454
         "use type_rule method and DBIx::Custom::Result filter method, " .
1455
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1456
    
1457
    return $self->_apply_filter(@_);
1458
}
1459

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1467
    # Arguments
1468
    my $primary_keys = delete $args{primary_key};
1469
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1470
    my $where = delete $args{where};
1471
    my $param = delete $args{param};
1472
    
1473
    # Check arguments
1474
    foreach my $name (keys %args) {
1475
        croak qq{"$name" is wrong option } . _subname
1476
          unless $SELECT_AT_ARGS{$name};
1477
    }
1478
    
1479
    # Table
1480
    croak qq{"table" option must be specified } . _subname
1481
      unless $args{table};
1482
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1483
    
1484
    # Create where parameter
1485
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1486
    
1487
    return $self->select(where => $where_param, %args);
1488
}
1489

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1490
# DEPRECATED!
1491
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1492
sub delete_at {
1493
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1494

            
1495
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1496
    
1497
    # Arguments
1498
    my $primary_keys = delete $args{primary_key};
1499
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1500
    my $where = delete $args{where};
1501
    
1502
    # Check arguments
1503
    foreach my $name (keys %args) {
1504
        croak qq{"$name" is wrong option } . _subname
1505
          unless $DELETE_AT_ARGS{$name};
1506
    }
1507
    
1508
    # Create where parameter
1509
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1510
    
1511
    return $self->delete(where => $where_param, %args);
1512
}
1513

            
cleanup
Yuki Kimoto authored on 2011-06-08
1514
# DEPRECATED!
1515
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1516
sub update_at {
1517
    my $self = shift;
1518

            
1519
    warn "update_at is DEPRECATED! use update and id option instead";
1520
    
1521
    # Arguments
1522
    my $param;
1523
    $param = shift if @_ % 2;
1524
    my %args = @_;
1525
    my $primary_keys = delete $args{primary_key};
1526
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1527
    my $where = delete $args{where};
1528
    my $p = delete $args{param} || {};
1529
    $param  ||= $p;
1530
    
1531
    # Check arguments
1532
    foreach my $name (keys %args) {
1533
        croak qq{"$name" is wrong option } . _subname
1534
          unless $UPDATE_AT_ARGS{$name};
1535
    }
1536
    
1537
    # Create where parameter
1538
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1539
    
1540
    return $self->update(where => $where_param, param => $param, %args);
1541
}
1542

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1543
# DEPRECATED!
1544
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1545
sub insert_at {
1546
    my $self = shift;
1547
    
1548
    warn "insert_at is DEPRECATED! use insert and id option instead";
1549
    
1550
    # Arguments
1551
    my $param;
1552
    $param = shift if @_ % 2;
1553
    my %args = @_;
1554
    my $primary_key = delete $args{primary_key};
1555
    $primary_key = [$primary_key] unless ref $primary_key;
1556
    my $where = delete $args{where};
1557
    my $p = delete $args{param} || {};
1558
    $param  ||= $p;
1559
    
1560
    # Check arguments
1561
    foreach my $name (keys %args) {
1562
        croak qq{"$name" is wrong option } . _subname
1563
          unless $INSERT_AT_ARGS{$name};
1564
    }
1565
    
1566
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1567
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1568
    $param = $self->merge_param($where_param, $param);
1569
    
1570
    return $self->insert(param => $param, %args);
1571
}
1572

            
added warnings
Yuki Kimoto authored on 2011-06-07
1573
# DEPRECATED!
1574
sub register_tag {
1575
    warn "register_tag is DEPRECATED!";
1576
    shift->query_builder->register_tag(@_)
1577
}
1578

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1579
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1580
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1581
has dbi_options => sub { {} };
1582
has filter_check  => 1;
1583
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1584

            
cleanup
Yuki Kimoto authored on 2011-01-25
1585
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1586
sub default_bind_filter {
1587
    my $self = shift;
1588
    
cleanup
Yuki Kimoto authored on 2011-06-13
1589
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1590
    
cleanup
Yuki Kimoto authored on 2011-01-12
1591
    if (@_) {
1592
        my $fname = $_[0];
1593
        
1594
        if (@_ && !$fname) {
1595
            $self->{default_out_filter} = undef;
1596
        }
1597
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1598
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1599
              unless exists $self->filters->{$fname};
1600
        
1601
            $self->{default_out_filter} = $self->filters->{$fname};
1602
        }
1603
        return $self;
1604
    }
1605
    
1606
    return $self->{default_out_filter};
1607
}
1608

            
cleanup
Yuki Kimoto authored on 2011-01-25
1609
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1610
sub default_fetch_filter {
1611
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1612

            
cleanup
Yuki Kimoto authored on 2011-06-13
1613
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1614
    
1615
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1616
        my $fname = $_[0];
1617

            
cleanup
Yuki Kimoto authored on 2011-01-12
1618
        if (@_ && !$fname) {
1619
            $self->{default_in_filter} = undef;
1620
        }
1621
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1622
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1623
              unless exists $self->filters->{$fname};
1624
        
1625
            $self->{default_in_filter} = $self->filters->{$fname};
1626
        }
1627
        
1628
        return $self;
1629
    }
1630
    
many changed
Yuki Kimoto authored on 2011-01-23
1631
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1632
}
1633

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1634
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1635
sub insert_param_tag {
1636
    warn "insert_param_tag is DEPRECATED! " .
1637
         "use insert_param instead!";
1638
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1639
}
1640

            
cleanup
Yuki Kimoto authored on 2011-01-25
1641
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1642
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1643
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1644
    return shift->query_builder->register_tag_processor(@_);
1645
}
1646

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1647
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1648
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1649
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1650
         "use update_param instead";
1651
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1652
}
cleanup
Yuki Kimoto authored on 2011-03-08
1653
# DEPRECATED!
1654
sub _push_relation {
1655
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1656
    
1657
    if (keys %{$relation || {}}) {
1658
        push @$sql, $need_where ? 'where' : 'and';
1659
        foreach my $rcolumn (keys %$relation) {
1660
            my $table1 = (split (/\./, $rcolumn))[0];
1661
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1662
            push @$tables, ($table1, $table2);
1663
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1664
        }
1665
    }
1666
    pop @$sql if $sql->[-1] eq 'and';    
1667
}
1668

            
1669
# DEPRECATED!
1670
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1671
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1672
    
1673
    if (keys %{$relation || {}}) {
1674
        foreach my $rcolumn (keys %$relation) {
1675
            my $table1 = (split (/\./, $rcolumn))[0];
1676
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1677
            my $table1_exists;
1678
            my $table2_exists;
1679
            foreach my $table (@$tables) {
1680
                $table1_exists = 1 if $table eq $table1;
1681
                $table2_exists = 1 if $table eq $table2;
1682
            }
1683
            unshift @$tables, $table1 unless $table1_exists;
1684
            unshift @$tables, $table2 unless $table2_exists;
1685
        }
1686
    }
1687
}
1688

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1691
=head1 NAME
1692

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

            
1695
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1696

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1697
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1698
    
1699
    # Connect
1700
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1701
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1702
        user => 'ken',
1703
        password => '!LFKD%$&',
1704
        dbi_option => {mysql_enable_utf8 => 1}
1705
    );
cleanup
yuki-kimoto authored on 2010-08-05
1706

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1707
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1708
    $dbi->insert(
1709
        table  => 'book',
1710
        param  => {title => 'Perl', author => 'Ken'}
1711
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1712
    
1713
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1714
    $dbi->update(
1715
        table  => 'book', 
1716
        param  => {title => 'Perl', author => 'Ken'}, 
1717
        where  => {id => 5},
1718
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1719
    
1720
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1721
    $dbi->delete(
1722
        table  => 'book',
1723
        where  => {author => 'Ken'},
1724
    );
cleanup
yuki-kimoto authored on 2010-08-05
1725

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1733
    # Select, more complex
1734
    my $result = $dbi->select(
1735
        table  => 'book',
1736
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1737
            {book => [qw/title author/]},
1738
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1739
        ],
1740
        where  => {'book.author' => 'Ken'},
1741
        join => ['left outer join company on book.company_id = company.id'],
1742
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1743
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1744
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1745
    # Fetch
1746
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1747
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1748
    }
1749
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1750
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1751
    while (my $row = $result->fetch_hash) {
1752
        
1753
    }
1754
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1755
    # Execute SQL with parameter.
1756
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1757
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1758
        param  => {author => 'ken', title => '%Perl%'}
1759
    );
1760
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1761
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1762

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

            
1765
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1766

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1776
=item *
1777

            
1778
Filter when data is send or receive.
1779

            
1780
=item *
1781

            
1782
Data filtering system
1783

            
1784
=item *
1785

            
1786
Model support.
1787

            
1788
=item *
1789

            
1790
Generate where clause dinamically.
1791

            
1792
=item *
1793

            
1794
Generate join clause dinamically.
1795

            
1796
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1797

            
1798
=head1 GUIDE
1799

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

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

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

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

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

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

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

            
1816
This is L<DBIx::Connector> example. Please pass
1817
C<default_dbi_option> to L<DBIx::Connector>.
1818

            
1819
    my $connector = DBIx::Connector->new(
1820
        "dbi:mysql:database=$DATABASE",
1821
        $USER,
1822
        $PASSWORD,
1823
        DBIx::Custom->new->default_dbi_option
1824
    );
1825
    
1826
    my $dbi = DBIx::Custom->new(connector => $connector);
1827

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

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

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

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

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

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

            
1843
=head2 C<default_dbi_option>
1844

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1851
    {
1852
        RaiseError => 1,
1853
        PrintError => 0,
1854
        AutoCommit => 1,
1855
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1856

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1927
    print $dbi->available_data_type;
1928

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

            
1932
=head2 C<available_type_name> EXPERIMENTAL
1933

            
1934
    print $dbi->available_type_name;
1935

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

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

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

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

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

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

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

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

            
1953
Create column clause. The follwoing column clause is created.
1954

            
1955
    book.author as "book.author",
1956
    book.title as "book.title"
1957

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1960
    # Separator is double underbar
1961
    $dbi->separator('__');
1962
    
1963
    book.author as "book__author",
1964
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1965

            
cleanup
Yuki Kimoto authored on 2011-06-13
1966
    # Separator is hyphen
1967
    $dbi->separator('-');
1968
    
1969
    book.author as "book-author",
1970
    book.title as "book-title"
1971
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1972
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1973

            
update pod
Yuki Kimoto authored on 2011-03-13
1974
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1975
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1976
        user => 'ken',
1977
        password => '!LFKD%$&',
1978
        dbi_option => {mysql_enable_utf8 => 1}
1979
    );
1980

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1989
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1990
        table => 'book',
1991
        primary_key => 'id',
1992
        join => [
1993
            'inner join company on book.comparny_id = company.id'
1994
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1995
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1996
            publish_date => {
1997
                out => 'tp_to_date',
1998
                in => 'date_to_tp',
1999
                end => 'tp_to_displaydate'
2000
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
2001
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2002
    );
2003

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

            
2007
   $dbi->model('book')->select(...);
2008

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

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

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

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

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

            
2025
    my $dbh = $dbi->dbh;
2026

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

            
2030
=head2 C<each_column>
2031

            
2032
    $dbi->each_column(
2033
        sub {
2034
            my ($dbi, $table, $column, $column_info) = @_;
2035
            
2036
            my $type = $column_info->{TYPE_NAME};
2037
            
2038
            if ($type eq 'DATE') {
2039
                # ...
2040
            }
2041
        }
2042
    );
2043

            
2044
Iterate all column informations of all table from database.
2045
Argument is callback when one column is found.
2046
Callback receive four arguments, dbi object, table name,
2047
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2048

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

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

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

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

            
2062
    select * from where title = ? and author like ?;
2063

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

            
2066
=over 4
2067

            
2068
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2069
    
2070
    filter => {
2071
        title  => sub { uc $_[0] }
2072
        author => sub { uc $_[0] }
2073
    }
update pod
Yuki Kimoto authored on 2011-03-13
2074

            
updated pod
Yuki Kimoto authored on 2011-06-09
2075
    # Filter name
2076
    filter => {
2077
        title  => 'upper_case',
2078
        author => 'upper_case'
2079
    }
2080
        
2081
    # At once
2082
    filter => [
2083
        [qw/title author/]  => sub { uc $_[0] }
2084
    ]
2085

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

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

            
2093
    query => 1
2094

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2097
=item C<table>
2098
    
2099
    table => 'author'
2100
    table => ['author', 'book']
2101

            
2102
Table names for filtering.
2103

            
2104
Filtering by C<apply_filter> is off in C<execute> method,
2105
because we don't know what filter is applied.
2106

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

            
2109
Specify database data type.
2110

            
2111
    type => [image => DBI::SQL_BLOB]
2112
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2113

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

            
2116
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2117

            
2118
C<type> option is also available
2119
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2120

            
2121
=item C<type_rule_off> EXPERIMENTAL
2122

            
2123
    type_rule_off => 1
2124

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2125
Turn C<into1> and C<into2> type rule off.
2126

            
2127
=item C<type_rule1_off> EXPERIMENTAL
2128

            
2129
    type_rule1_off => 1
2130

            
2131
Turn C<into1> type rule off.
2132

            
2133
=item C<type_rule2_off> EXPERIMENTAL
2134

            
2135
    type_rule2_off => 1
2136

            
2137
Turn C<into2> type rule off.
update document
yuki-kimoto authored on 2009-11-19
2138

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2149
=over 4
2150

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

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

            
2155
=item C<filter>
2156

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2161
    id => 4
2162
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2163

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2195
Same as C<execute> method's C<type> option.
2196

            
2197
=item C<type_rule_off> EXPERIMENTAL
2198

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2201
=item C<type_rule1_off> EXPERIMENTAL
2202

            
2203
    type_rule1_off => 1
2204

            
2205
Same as C<execute> method's C<type_rule1_off> option.
2206

            
2207
=item C<type_rule2_off> EXPERIMENTAL
2208

            
2209
    type_rule2_off => 1
2210

            
2211
Same as C<execute> method's C<type_rule2_off> option.
2212

            
updated pod
Yuki Kimoto authored on 2011-06-08
2213
=back
update pod
Yuki Kimoto authored on 2011-03-13
2214

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2222
=head2 C<insert>
2223

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

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

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

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

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

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

            
2236
=item C<filter>
2237

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

            
2240
=item C<id>
2241

            
updated document
Yuki Kimoto authored on 2011-06-09
2242
    id => 4
2243
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2244

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

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

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

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

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

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

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

            
2269
=item C<param>
2270

            
2271
    param => {title => 'Perl', author => 'Ken'}
2272

            
2273
Insert data.
2274

            
2275
If C<insert> method's arguments is odd numbers,
2276
first argument is received as C<param>.
2277

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

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

            
2282
Same as C<execute> method's C<query> option.
2283

            
2284
=item C<table>
2285

            
2286
    table => 'book'
2287

            
2288
Table name.
2289

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

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

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

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2298
=item C<type_rule1_off> EXPERIMENTAL
2299

            
2300
    type_rule1_off => 1
2301

            
2302
Same as C<execute> method's C<type_rule1_off> option.
2303

            
2304
=item C<type_rule2_off> EXPERIMENTAL
2305

            
2306
    type_rule2_off => 1
2307

            
2308
Same as C<execute> method's C<type_rule2_off> option.
2309

            
update pod
Yuki Kimoto authored on 2011-03-13
2310
=back
2311

            
2312
=over 4
2313

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2329
    lib / MyModel.pm
2330
        / MyModel / book.pm
2331
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2332

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

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

            
2337
    package MyModel;
2338
    
2339
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2340
    
2341
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2342

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2347
    package MyModel::book;
2348
    
2349
    use base 'MyModel';
2350
    
2351
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2352

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2355
    package MyModel::company;
2356
    
2357
    use base 'MyModel';
2358
    
2359
    1;
2360
    
2361
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2362

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

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

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

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

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

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

            
2376
$param:
2377

            
2378
    {key1 => [1, 1], key2 => 2}
2379

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

            
2382
    $dbi->method(
2383
        update_or_insert => sub {
2384
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2385
            
2386
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2387
        },
2388
        find_or_create   => sub {
2389
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2390
            
2391
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2392
        }
2393
    );
2394

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

            
2397
    $dbi->update_or_insert;
2398
    $dbi->find_or_create;
2399

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

            
2402
    $dbi->model('book')->method(
2403
        insert => sub { ... },
2404
        update => sub { ... }
2405
    );
2406
    
2407
    my $model = $dbi->model('book');
2408

            
2409
Set and get a L<DBIx::Custom::Model> object,
2410

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

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

            
2415
Create column clause for myself. The follwoing column clause is created.
2416

            
2417
    book.author as author,
2418
    book.title as title
2419

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2422
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2423
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2424
        user => 'ken',
2425
        password => '!LFKD%$&',
2426
        dbi_option => {mysql_enable_utf8 => 1}
2427
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2428

            
2429
Create a new L<DBIx::Custom> object.
2430

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

            
2433
    my $not_exists = $dbi->not_exists;
2434

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2438
=head2 C<register_filter>
2439

            
update pod
Yuki Kimoto authored on 2011-03-13
2440
    $dbi->register_filter(
2441
        # Time::Piece object to database DATE format
2442
        tp_to_date => sub {
2443
            my $tp = shift;
2444
            return $tp->strftime('%Y-%m-%d');
2445
        },
2446
        # database DATE format to Time::Piece object
2447
        date_to_tp => sub {
2448
           my $date = shift;
2449
           return Time::Piece->strptime($date, '%Y-%m-%d');
2450
        }
2451
    );
cleanup
yuki-kimoto authored on 2010-10-17
2452
    
update pod
Yuki Kimoto authored on 2011-03-13
2453
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2454

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

            
2457
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2458
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2459
            date => sub { ... },
2460
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2461
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2462
        into2 => {
2463
            date => sub { ... },
2464
            datetime => sub { ... }
2465
        },
2466
        from1 => {
2467
            # DATE
2468
            9 => sub { ... },
2469
            # DATETIME or TIMESTAMP
2470
            11 => sub { ... },
2471
        }
2472
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2473
            # DATE
2474
            9 => sub { ... },
2475
            # DATETIME or TIMESTAMP
2476
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2477
        }
2478
    );
2479

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2483
In C<into1> and C<into2> you can specify
2484
type name as same as type name defined
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2485
by create table, such as C<DATETIME> or C<DATE>.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2486

            
2487
C<into2> is executed after C<into1>.
cleanup
Yuki Kimoto authored on 2011-06-13
2488

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2489
Note that type name and data type don't contain upper case.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2490
If these contain upper case charactor, you convert it to lower case.
2491

            
2492
Type rule of C<into1> and C<into2> is enabled on the following
2493
column name.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2494

            
cleanup
Yuki Kimoto authored on 2011-06-13
2495
=over 4
2496

            
2497
=item 1. column name
2498

            
2499
    issue_date
2500
    issue_datetime
2501

            
2502
=item 2. table name and column name, separator is dot
2503

            
2504
    book.issue_date
2505
    book.issue_datetime
2506

            
2507
=back
2508

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

            
2511
    print $dbi->available_type_name;
2512

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2513
In C<from1> and C<from2> you data type, not type name.
2514
C<from2> is executed after C<from1>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2515
You get all data type by C<available_data_type>.
2516

            
2517
    print $dbi->available_data_type;
2518

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2519
You can also specify multiple types at once.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2520

            
2521
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2522
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2523
            [qw/DATE DATETIME/] => sub { ... },
2524
        ],
2525
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2526

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2529
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2530
        table  => 'book',
2531
        column => ['author', 'title'],
2532
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2533
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2534
    
updated document
Yuki Kimoto authored on 2011-06-09
2535
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2536

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

            
2539
=over 4
2540

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2545
Append statement to last of SQL.
2546
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2547
=item C<column>
2548
    
updated document
Yuki Kimoto authored on 2011-06-09
2549
    column => 'author'
2550
    column => ['author', 'title']
2551

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2560
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2561
        {book => [qw/author title/]},
2562
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2563
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2564

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

            
2567
    book.author as "book.author",
2568
    book.title as "book.title",
2569
    person.name as "person.name",
2570
    person.age as "person.age"
2571

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2574
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2575
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2576
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2577

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

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

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

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

            
2586
=item C<id>
2587

            
2588
    id => 4
2589
    id => [4, 5]
2590

            
2591
ID corresponding to C<primary_key>.
2592
You can select rows by C<id> and C<primary_key>.
2593

            
2594
    $dbi->select(
2595
        parimary_key => ['id1', 'id2'],
2596
        id => [4, 5],
2597
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2598
    );
2599

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2602
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2603
        where => {id1 => 4, id2 => 5},
2604
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2605
    );
2606
    
updated document
Yuki Kimoto authored on 2011-06-09
2607
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2608

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

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

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

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

            
2621
    prefix => 'SQL_CALC_FOUND_ROWS'
2622

            
2623
Prefix of column cluase
2624

            
2625
    select SQL_CALC_FOUND_ROWS title, author from book;
2626

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

            
2629
    join => [
2630
        'left outer join company on book.company_id = company_id',
2631
        'left outer join location on company.location_id = location.id'
2632
    ]
2633
        
2634
Join clause. If column cluase or where clause contain table name like "company.name",
2635
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2636

            
2637
    $dbi->select(
2638
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2639
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2640
        where => {'company.name' => 'Orange'},
2641
        join => [
2642
            'left outer join company on book.company_id = company.id',
2643
            'left outer join location on company.location_id = location.id'
2644
        ]
2645
    );
2646

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2650
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2651
    from book
2652
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2653
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2654

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2674
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2675

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

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2680
=item C<type_rule1_off> EXPERIMENTAL
2681

            
2682
    type_rule1_off => 1
2683

            
2684
Same as C<execute> method's C<type_rule1_off> option.
2685

            
2686
=item C<type_rule2_off> EXPERIMENTAL
2687

            
2688
    type_rule2_off => 1
2689

            
2690
Same as C<execute> method's C<type_rule2_off> option.
2691

            
updated document
Yuki Kimoto authored on 2011-06-09
2692
=item C<where>
2693
    
2694
    # Hash refrence
2695
    where => {author => 'Ken', 'title' => 'Perl'}
2696
    
2697
    # DBIx::Custom::Where object
2698
    where => $dbi->where(
2699
        clause => ['and', 'author = :author', 'title like :title'],
2700
        param  => {author => 'Ken', title => '%Perl%'}
2701
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2702

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2707
Where clause.
2708
    
improved pod
Yuki Kimoto authored on 2011-04-19
2709
=item C<wrap> EXPERIMENTAL
2710

            
2711
Wrap statement. This is array reference.
2712

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

            
2715
This option is for Oracle and SQL Server paging process.
2716

            
update pod
Yuki Kimoto authored on 2011-03-12
2717
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2718

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2727
=over 4
2728

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2739
    id => 4
2740
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2741

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2745
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2746
        {title => 'Perl', author => 'Ken'}
2747
        parimary_key => ['id1', 'id2'],
2748
        id => [4, 5],
2749
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2750
    );
update pod
Yuki Kimoto authored on 2011-03-13
2751

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2754
    $dbi->update(
2755
        {title => 'Perl', author => 'Ken'}
2756
        where => {id1 => 4, id2 => 5},
2757
        table => 'book'
2758
    );
update pod
Yuki Kimoto authored on 2011-03-13
2759

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2793
Same as C<execute> method's C<type> option.
2794

            
2795
=item C<type_rule_off> EXPERIMENTAL
2796

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2797
Same as C<execute> method's C<type_rule_off> option.
2798

            
2799
=item C<type_rule1_off> EXPERIMENTAL
2800

            
2801
    type_rule1_off => 1
2802

            
2803
Same as C<execute> method's C<type_rule1_off> option.
2804

            
2805
=item C<type_rule2_off> EXPERIMENTAL
2806

            
2807
    type_rule2_off => 1
2808

            
2809
Same as C<execute> method's C<type_rule2_off> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2810

            
updated pod
Yuki Kimoto authored on 2011-06-08
2811
=back
update pod
Yuki Kimoto authored on 2011-03-13
2812

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

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

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

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

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

            
2824
Create update parameter tag.
2825

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

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

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

            
2835
Create a new L<DBIx::Custom::Where> object.
2836

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2844
=head1 Parameter
2845

            
2846
Parameter start at ':'. This is replaced to place holoder
2847

            
2848
    $dbi->execute(
2849
        "select * from book where title = :title and author = :author"
2850
        param => {title => 'Perl', author => 'Ken'}
2851
    );
2852

            
2853
    "select * from book where title = ? and author = ?"
2854

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

            
2857
=head2 C<DBIX_CUSTOM_DEBUG>
2858

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

            
2862
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2863

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

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

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

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

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

            
2875
C<< <kimoto.yuki at gmail.com> >>
2876

            
2877
L<http://github.com/yuki-kimoto/DBIx-Custom>
2878

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2879
=head1 AUTHOR
2880

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

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

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

            
2887
This program is free software; you can redistribute it and/or modify it
2888
under the same terms as Perl itself.
2889

            
2890
=cut