DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2920 lines | 73.509kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
4
our $VERSION = '0.1696';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
233
our %DELETE_ARGS = map { $_ => 1 } @COMMON_ARGS,
234
  qw/where append allow_delete_all where_param prefix/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
235

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
239
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
240
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
241
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
242
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
243
    }
244
    
245
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
246
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
247
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
248
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
249
    my $where            = delete $args{where} || {};
250
    my $append           = delete $args{append};
251
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
252
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
253
    my $id = delete $args{id};
254
    my $primary_key = delete $args{primary_key};
255
    croak "update method primary_key option " .
256
          "must be specified when id is specified " . _subname
257
      if defined $id && !defined $primary_key;
258
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
259
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
260
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
261
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
262
    $where = $self->_create_param_from_id($id, $primary_key) if defined $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;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
280
    push @sql, "delete";
281
    push @sql, $prefix if defined $prefix;
282
    push @sql, "from $q$table$q $where_clause";
283
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
284
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
285
    
286
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
287
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
288
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
289
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
290
        table => $table,
291
        %args
292
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
293
}
294

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

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

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

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

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

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

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

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

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

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

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
550
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
551
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
552
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
553
        $param = $self->merge_param($id_param, $param);
554
    }
555

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

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
765
our %SELECT_ARGS = map { $_ => 1 } @COMMON_ARGS,
766
  qw/column where relation join param where_param wrap prefix/;
refactoring select
yuki-kimoto authored on 2010-04-28
767

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

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

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

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

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

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

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

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

            
1003
                    $self->{"_$into"}{$table}{$column} = $filter;
1004
                }
1005
            });
1006
        }
1007

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

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1030
our %UPDATE_ARGS = map { $_ => 1 } @COMMON_ARGS,
1031
  qw/param where allow_update_all where_param prefix/;
cleanup
yuki-kimoto authored on 2010-10-17
1032

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1116
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1117
}
1118

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

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

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

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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1378
sub _quote {
1379
    my $self = shift;
1380
    
1381
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1382
         : defined $self->quote ? $self->quote
1383
         : '';
1384
}
1385

            
cleanup
Yuki Kimoto authored on 2011-04-02
1386
sub _remove_duplicate_table {
1387
    my ($self, $tables, $main_table) = @_;
1388
    
1389
    # Remove duplicate table
1390
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1391
    delete $tables{$main_table} if $main_table;
1392
    
1393
    return [keys %tables, $main_table ? $main_table : ()];
1394
}
1395

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

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1466
# DEPRECATED!
1467
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1468
sub select_at {
1469
    my ($self, %args) = @_;
1470

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

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

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1496
# DEPRECATED!
1497
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1498
sub delete_at {
1499
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1500

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1520
# DEPRECATED!
1521
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1522
sub update_at {
1523
    my $self = shift;
1524

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1579
# DEPRECATED!
1580
sub register_tag {
1581
    warn "register_tag is DEPRECATED!";
1582
    shift->query_builder->register_tag(@_)
1583
}
1584

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1585
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1586
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1587
has dbi_options => sub { {} };
1588
has filter_check  => 1;
1589
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1590

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1615
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1616
sub default_fetch_filter {
1617
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1618

            
cleanup
Yuki Kimoto authored on 2011-06-13
1619
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1620
    
1621
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1622
        my $fname = $_[0];
1623

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

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1640
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1641
sub insert_param_tag {
1642
    warn "insert_param_tag is DEPRECATED! " .
1643
         "use insert_param instead!";
1644
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1645
}
1646

            
cleanup
Yuki Kimoto authored on 2011-01-25
1647
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1648
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1649
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1650
    return shift->query_builder->register_tag_processor(@_);
1651
}
1652

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1697
=head1 NAME
1698

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

            
1701
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1702

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

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

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

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

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

            
1771
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1772

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1782
=item *
1783

            
1784
Filter when data is send or receive.
1785

            
1786
=item *
1787

            
1788
Data filtering system
1789

            
1790
=item *
1791

            
1792
Model support.
1793

            
1794
=item *
1795

            
1796
Generate where clause dinamically.
1797

            
1798
=item *
1799

            
1800
Generate join clause dinamically.
1801

            
1802
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1803

            
1804
=head1 GUIDE
1805

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

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

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

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

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

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

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

            
1822
This is L<DBIx::Connector> example. Please pass
1823
C<default_dbi_option> to L<DBIx::Connector>.
1824

            
1825
    my $connector = DBIx::Connector->new(
1826
        "dbi:mysql:database=$DATABASE",
1827
        $USER,
1828
        $PASSWORD,
1829
        DBIx::Custom->new->default_dbi_option
1830
    );
1831
    
1832
    my $dbi = DBIx::Custom->new(connector => $connector);
1833

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

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

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

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

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

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

            
1849
=head2 C<default_dbi_option>
1850

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1857
    {
1858
        RaiseError => 1,
1859
        PrintError => 0,
1860
        AutoCommit => 1,
1861
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1862

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1933
    print $dbi->available_data_type;
1934

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

            
1938
=head2 C<available_type_name> EXPERIMENTAL
1939

            
1940
    print $dbi->available_type_name;
1941

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

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

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

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

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

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

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

            
1959
Create column clause. The follwoing column clause is created.
1960

            
1961
    book.author as "book.author",
1962
    book.title as "book.title"
1963

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1966
    # Separator is double underbar
1967
    $dbi->separator('__');
1968
    
1969
    book.author as "book__author",
1970
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1971

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

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

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

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

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

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

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

            
2013
   $dbi->model('book')->select(...);
2014

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

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

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

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

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

            
2031
    my $dbh = $dbi->dbh;
2032

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

            
2036
=head2 C<each_column>
2037

            
2038
    $dbi->each_column(
2039
        sub {
2040
            my ($dbi, $table, $column, $column_info) = @_;
2041
            
2042
            my $type = $column_info->{TYPE_NAME};
2043
            
2044
            if ($type eq 'DATE') {
2045
                # ...
2046
            }
2047
        }
2048
    );
2049

            
2050
Iterate all column informations of all table from database.
2051
Argument is callback when one column is found.
2052
Callback receive four arguments, dbi object, table name,
2053
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2054

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

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

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

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

            
2068
    select * from where title = ? and author like ?;
2069

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

            
2072
=over 4
2073

            
2074
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2075
    
2076
    filter => {
2077
        title  => sub { uc $_[0] }
2078
        author => sub { uc $_[0] }
2079
    }
update pod
Yuki Kimoto authored on 2011-03-13
2080

            
updated pod
Yuki Kimoto authored on 2011-06-09
2081
    # Filter name
2082
    filter => {
2083
        title  => 'upper_case',
2084
        author => 'upper_case'
2085
    }
2086
        
2087
    # At once
2088
    filter => [
2089
        [qw/title author/]  => sub { uc $_[0] }
2090
    ]
2091

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

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

            
2099
    query => 1
2100

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2103
=item C<table>
2104
    
2105
    table => 'author'
2106
    table => ['author', 'book']
2107

            
2108
Table names for filtering.
2109

            
2110
Filtering by C<apply_filter> is off in C<execute> method,
2111
because we don't know what filter is applied.
2112

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

            
2115
Specify database data type.
2116

            
2117
    type => [image => DBI::SQL_BLOB]
2118
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2119

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

            
2122
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2123

            
2124
C<type> option is also available
2125
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2126

            
2127
=item C<type_rule_off> EXPERIMENTAL
2128

            
2129
    type_rule_off => 1
2130

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

            
2133
=item C<type_rule1_off> EXPERIMENTAL
2134

            
2135
    type_rule1_off => 1
2136

            
2137
Turn C<into1> type rule off.
2138

            
2139
=item C<type_rule2_off> EXPERIMENTAL
2140

            
2141
    type_rule2_off => 1
2142

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2155
=over 4
2156

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

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

            
2161
=item C<filter>
2162

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2167
    id => 4
2168
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2169

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2173
    $dbi->delete(
2174
        parimary_key => ['id1', 'id2'],
2175
        id => [4, 5],
2176
        table => 'book',
2177
    );
update pod
Yuki Kimoto authored on 2011-03-13
2178

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

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

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2183
=item C<prefix> EXPERIMENTAL
2184

            
2185
    prefix => 'some'
2186

            
2187
prefix before table name section.
2188

            
2189
    delete some from book
2190

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

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

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

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

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

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

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

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

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

            
2209
Same as C<execute> method's C<type> option.
2210

            
2211
=item C<type_rule_off> EXPERIMENTAL
2212

            
2213
Same as C<execute> method's C<type_rule_off> option.
2214

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

            
2217
    type_rule1_off => 1
2218

            
2219
Same as C<execute> method's C<type_rule1_off> option.
2220

            
2221
=item C<type_rule2_off> EXPERIMENTAL
2222

            
2223
    type_rule2_off => 1
2224

            
2225
Same as C<execute> method's C<type_rule2_off> option.
2226

            
updated pod
Yuki Kimoto authored on 2011-06-08
2227
=back
update pod
Yuki Kimoto authored on 2011-03-13
2228

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2236
=head2 C<insert>
2237

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

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

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

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

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

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

            
2250
=item C<filter>
2251

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

            
2254
=item C<id>
2255

            
updated document
Yuki Kimoto authored on 2011-06-09
2256
    id => 4
2257
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2258

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2262
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2263
        {title => 'Perl', author => 'Ken'}
2264
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2265
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2266
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2267
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2268

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

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

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2276
=item C<prefix> EXPERIMENTAL
2277

            
2278
    prefix => 'or replace'
2279

            
2280
prefix before table name section
2281

            
2282
    insert or replace into book
2283

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

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

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

            
2291
=item C<param>
2292

            
2293
    param => {title => 'Perl', author => 'Ken'}
2294

            
2295
Insert data.
2296

            
2297
If C<insert> method's arguments is odd numbers,
2298
first argument is received as C<param>.
2299

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

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

            
2304
Same as C<execute> method's C<query> option.
2305

            
2306
=item C<table>
2307

            
2308
    table => 'book'
2309

            
2310
Table name.
2311

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

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

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

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

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

            
2322
    type_rule1_off => 1
2323

            
2324
Same as C<execute> method's C<type_rule1_off> option.
2325

            
2326
=item C<type_rule2_off> EXPERIMENTAL
2327

            
2328
    type_rule2_off => 1
2329

            
2330
Same as C<execute> method's C<type_rule2_off> option.
2331

            
update pod
Yuki Kimoto authored on 2011-03-13
2332
=back
2333

            
2334
=over 4
2335

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2351
    lib / MyModel.pm
2352
        / MyModel / book.pm
2353
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2354

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

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

            
2359
    package MyModel;
2360
    
2361
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2362
    
2363
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2364

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2369
    package MyModel::book;
2370
    
2371
    use base 'MyModel';
2372
    
2373
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2374

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2377
    package MyModel::company;
2378
    
2379
    use base 'MyModel';
2380
    
2381
    1;
2382
    
2383
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2384

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

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

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

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

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

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

            
2398
$param:
2399

            
2400
    {key1 => [1, 1], key2 => 2}
2401

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

            
2404
    $dbi->method(
2405
        update_or_insert => sub {
2406
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2407
            
2408
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2409
        },
2410
        find_or_create   => sub {
2411
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2412
            
2413
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2414
        }
2415
    );
2416

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

            
2419
    $dbi->update_or_insert;
2420
    $dbi->find_or_create;
2421

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

            
2424
    $dbi->model('book')->method(
2425
        insert => sub { ... },
2426
        update => sub { ... }
2427
    );
2428
    
2429
    my $model = $dbi->model('book');
2430

            
2431
Set and get a L<DBIx::Custom::Model> object,
2432

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

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

            
2437
Create column clause for myself. The follwoing column clause is created.
2438

            
2439
    book.author as author,
2440
    book.title as title
2441

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2444
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2445
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2446
        user => 'ken',
2447
        password => '!LFKD%$&',
2448
        dbi_option => {mysql_enable_utf8 => 1}
2449
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2450

            
2451
Create a new L<DBIx::Custom> object.
2452

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

            
2455
    my $not_exists = $dbi->not_exists;
2456

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2460
=head2 C<register_filter>
2461

            
update pod
Yuki Kimoto authored on 2011-03-13
2462
    $dbi->register_filter(
2463
        # Time::Piece object to database DATE format
2464
        tp_to_date => sub {
2465
            my $tp = shift;
2466
            return $tp->strftime('%Y-%m-%d');
2467
        },
2468
        # database DATE format to Time::Piece object
2469
        date_to_tp => sub {
2470
           my $date = shift;
2471
           return Time::Piece->strptime($date, '%Y-%m-%d');
2472
        }
2473
    );
cleanup
yuki-kimoto authored on 2010-10-17
2474
    
update pod
Yuki Kimoto authored on 2011-03-13
2475
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2476

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

            
2479
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2480
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2481
            date => sub { ... },
2482
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2483
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2484
        into2 => {
2485
            date => sub { ... },
2486
            datetime => sub { ... }
2487
        },
2488
        from1 => {
2489
            # DATE
2490
            9 => sub { ... },
2491
            # DATETIME or TIMESTAMP
2492
            11 => sub { ... },
2493
        }
2494
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2495
            # DATE
2496
            9 => sub { ... },
2497
            # DATETIME or TIMESTAMP
2498
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2499
        }
2500
    );
2501

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2517
=over 4
2518

            
2519
=item 1. column name
2520

            
2521
    issue_date
2522
    issue_datetime
2523

            
2524
=item 2. table name and column name, separator is dot
2525

            
2526
    book.issue_date
2527
    book.issue_datetime
2528

            
2529
=back
2530

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

            
2533
    print $dbi->available_type_name;
2534

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

            
2539
    print $dbi->available_data_type;
2540

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

            
2543
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2544
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2545
            [qw/DATE DATETIME/] => sub { ... },
2546
        ],
2547
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2548

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2551
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2552
        table  => 'book',
2553
        column => ['author', 'title'],
2554
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2555
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2556
    
updated document
Yuki Kimoto authored on 2011-06-09
2557
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2558

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

            
2561
=over 4
2562

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2567
Append statement to last of SQL.
2568
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2569
=item C<column>
2570
    
updated document
Yuki Kimoto authored on 2011-06-09
2571
    column => 'author'
2572
    column => ['author', 'title']
2573

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2582
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2583
        {book => [qw/author title/]},
2584
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2585
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2586

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

            
2589
    book.author as "book.author",
2590
    book.title as "book.title",
2591
    person.name as "person.name",
2592
    person.age as "person.age"
2593

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2596
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2597
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2598
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2599

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

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

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

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

            
2608
=item C<id>
2609

            
2610
    id => 4
2611
    id => [4, 5]
2612

            
2613
ID corresponding to C<primary_key>.
2614
You can select rows by C<id> and C<primary_key>.
2615

            
2616
    $dbi->select(
2617
        parimary_key => ['id1', 'id2'],
2618
        id => [4, 5],
2619
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2620
    );
2621

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2624
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2625
        where => {id1 => 4, id2 => 5},
2626
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2627
    );
2628
    
updated document
Yuki Kimoto authored on 2011-06-09
2629
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2630

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

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

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

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

            
2643
    prefix => 'SQL_CALC_FOUND_ROWS'
2644

            
2645
Prefix of column cluase
2646

            
2647
    select SQL_CALC_FOUND_ROWS title, author from book;
2648

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

            
2651
    join => [
2652
        'left outer join company on book.company_id = company_id',
2653
        'left outer join location on company.location_id = location.id'
2654
    ]
2655
        
2656
Join clause. If column cluase or where clause contain table name like "company.name",
2657
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2658

            
2659
    $dbi->select(
2660
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2661
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2662
        where => {'company.name' => 'Orange'},
2663
        join => [
2664
            'left outer join company on book.company_id = company.id',
2665
            'left outer join location on company.location_id = location.id'
2666
        ]
2667
    );
2668

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2672
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2673
    from book
2674
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2675
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2676

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2696
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2697

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

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

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

            
2704
    type_rule1_off => 1
2705

            
2706
Same as C<execute> method's C<type_rule1_off> option.
2707

            
2708
=item C<type_rule2_off> EXPERIMENTAL
2709

            
2710
    type_rule2_off => 1
2711

            
2712
Same as C<execute> method's C<type_rule2_off> option.
2713

            
updated document
Yuki Kimoto authored on 2011-06-09
2714
=item C<where>
2715
    
2716
    # Hash refrence
2717
    where => {author => 'Ken', 'title' => 'Perl'}
2718
    
2719
    # DBIx::Custom::Where object
2720
    where => $dbi->where(
2721
        clause => ['and', 'author = :author', 'title like :title'],
2722
        param  => {author => 'Ken', title => '%Perl%'}
2723
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2724

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2729
Where clause.
2730
    
improved pod
Yuki Kimoto authored on 2011-04-19
2731
=item C<wrap> EXPERIMENTAL
2732

            
2733
Wrap statement. This is array reference.
2734

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

            
2737
This option is for Oracle and SQL Server paging process.
2738

            
update pod
Yuki Kimoto authored on 2011-03-12
2739
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2740

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2749
=over 4
2750

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2761
    id => 4
2762
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2763

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2767
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2768
        {title => 'Perl', author => 'Ken'}
2769
        parimary_key => ['id1', 'id2'],
2770
        id => [4, 5],
2771
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2772
    );
update pod
Yuki Kimoto authored on 2011-03-13
2773

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2776
    $dbi->update(
2777
        {title => 'Perl', author => 'Ken'}
2778
        where => {id1 => 4, id2 => 5},
2779
        table => 'book'
2780
    );
update pod
Yuki Kimoto authored on 2011-03-13
2781

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

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

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

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

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

            
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2792
=item C<prefix> EXPERIMENTAL
2793

            
2794
    prefix => 'or replace'
2795

            
2796
prefix before table name section
2797

            
2798
    update or replace book
2799

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

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

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

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

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

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

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

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

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

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

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

            
2823
Same as C<execute> method's C<type> option.
2824

            
2825
=item C<type_rule_off> EXPERIMENTAL
2826

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

            
2829
=item C<type_rule1_off> EXPERIMENTAL
2830

            
2831
    type_rule1_off => 1
2832

            
2833
Same as C<execute> method's C<type_rule1_off> option.
2834

            
2835
=item C<type_rule2_off> EXPERIMENTAL
2836

            
2837
    type_rule2_off => 1
2838

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2841
=back
update pod
Yuki Kimoto authored on 2011-03-13
2842

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

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

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

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

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

            
2854
Create update parameter tag.
2855

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

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

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

            
2865
Create a new L<DBIx::Custom::Where> object.
2866

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2874
=head1 Parameter
2875

            
2876
Parameter start at ':'. This is replaced to place holoder
2877

            
2878
    $dbi->execute(
2879
        "select * from book where title = :title and author = :author"
2880
        param => {title => 'Perl', author => 'Ken'}
2881
    );
2882

            
2883
    "select * from book where title = ? and author = ?"
2884

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

            
2887
=head2 C<DBIX_CUSTOM_DEBUG>
2888

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

            
2892
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2893

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

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

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

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

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

            
2905
C<< <kimoto.yuki at gmail.com> >>
2906

            
2907
L<http://github.com/yuki-kimoto/DBIx-Custom>
2908

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2909
=head1 AUTHOR
2910

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

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

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

            
2917
This program is free software; you can redistribute it and/or modify it
2918
under the same terms as Perl itself.
2919

            
2920
=cut