DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3047 lines | 78.657kb
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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
4
our $VERSION = '0.1698';
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;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
17
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
18

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

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

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
137
sub dbh {
138
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
139
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
140
    # Set
141
    if (@_) {
142
        $self->{dbh} = $_[0];
143
        
144
        return $self;
145
    }
146
    
147
    # Get
148
    else {
149
        # From Connction manager
150
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
151
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
152
              unless ref $connector && $connector->can('dbh');
153
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
154
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
155
        }
156
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
157
        # Connect
158
        $self->{dbh} ||= $self->_connect;
159
        
160
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
161
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
162
            my $driver = $self->{dbh}->{Driver}->{Name};
163
            my $quote = $driver eq 'mysql' ? '`' : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
164
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
165
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
166
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
167
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
168
    }
169
}
170

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
177
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
178
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
179
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
180
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
181
    }
182
    
183
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
184
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
185
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
186
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
187
    my $where            = delete $args{where} || {};
188
    my $append           = delete $args{append};
189
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
190
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
191
    my $id = delete $args{id};
192
    my $primary_key = delete $args{primary_key};
193
    croak "update method primary_key option " .
194
          "must be specified when id is specified " . _subname
195
      if defined $id && !defined $primary_key;
196
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
197
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
198
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
199
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
200
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
201
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
202
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
203
        $where_clause = "where " . $where->[0];
204
        $where_param = $where->[1];
205
    }
206
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
207
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
208
        $where_param = keys %$where_param
209
                     ? $self->merge_param($where_param, $where->param)
210
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
211
        
212
        # String where
213
        $where_clause = $where->to_string;
214
    }
215
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
216
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
217
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
218

            
cleanup
Yuki Kimoto authored on 2011-04-02
219
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
220
    my @sql;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
221
    my $q = $self->_quote;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
222
    push @sql, "delete";
223
    push @sql, $prefix if defined $prefix;
224
    push @sql, "from $q$table$q $where_clause";
225
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
226
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
227
    
228
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
229
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
230
}
231

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

            
added helper method
yuki-kimoto authored on 2010-10-17
234
sub DESTROY { }
235

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
236
sub create_model {
237
    my $self = shift;
238
    
cleanup
Yuki Kimoto authored on 2011-04-02
239
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
240
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
241
    $args->{dbi} = $self;
242
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
243
    my $model_name  = delete $args->{name};
244
    my $model_table = delete $args->{table};
245
    $model_name ||= $model_table;
246
    
cleanup
Yuki Kimoto authored on 2011-04-02
247
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
248
    my $model = $model_class->new($args);
249
    $model->name($model_name) unless $model->name;
250
    $model->table($model_table) unless $model->table;
251
    
252
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
253
    my $filter = ref $model->filter eq 'HASH'
254
               ? [%{$model->filter}]
255
               : $model->filter;
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
256
    warn "DBIx::Custom::Model filter method is DEPRECATED!"
257
      if @$filter;
cleanup
Yuki Kimoto authored on 2011-06-13
258
    $self->_apply_filter($model->table, @$filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
259

            
260
    # Set model
261
    $self->model($model->name, $model);
262
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
263
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
264
}
265

            
266
sub each_column {
267
    my ($self, $cb) = @_;
268
    
269
    # Iterate all tables
270
    my $sth_tables = $self->dbh->table_info;
271
    while (my $table_info = $sth_tables->fetchrow_hashref) {
272
        
273
        # Table
274
        my $table = $table_info->{TABLE_NAME};
275
        
276
        # Iterate all columns
277
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
278
        while (my $column_info = $sth_columns->fetchrow_hashref) {
279
            my $column = $column_info->{COLUMN_NAME};
280
            $self->$cb($table, $column, $column_info);
281
        }
282
    }
283
}
284

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

            
287
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
288
    my $self = shift;
289
    my $query = shift;
290
    my $param;
291
    $param = shift if @_ % 2;
292
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
293
    
cleanup
Yuki Kimoto authored on 2011-04-02
294
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
295
    my $p = delete $args{param} || {};
296
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
297
    my $tables = delete $args{table} || [];
298
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
299
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
300
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
301
    my $bind_type = delete $args{bind_type} || delete $args{type};
302
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
303
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
304
    my $type_rule_off_parts = {
305
        1 => delete $args{type_rule1_off},
306
        2 => delete $args{type_rule2_off}
307
    };
cleanup
Yuki Kimoto authored on 2011-06-09
308
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
309
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
310
    
cleanup
Yuki Kimoto authored on 2011-03-09
311
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
312
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
313
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
314
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
315
    }
316
    
cleanup
Yuki Kimoto authored on 2011-04-02
317
    # Create query
updated pod
Yuki Kimoto authored on 2011-06-21
318
    $query = $self->_create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
319
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
320
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
321
    
cleanup
Yuki Kimoto authored on 2011-04-02
322
    # Tables
323
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
324
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
325
    $tables = $self->_remove_duplicate_table($tables, $main_table);
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
326
    if (my $q = $self->_quote) {
cleanup
Yuki Kimoto authored on 2011-04-02
327
        $_ =~ s/$q//g for @$tables;
328
    }
cleanup
Yuki Kimoto authored on 2011-04-02
329
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
330
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
331
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
332
    unless ($type_rule_off) {
333
        foreach my $name (keys %$param) {
334
            my $table;
335
            my $column;
336
            if ($name =~ /(?:(.+)\.)?(.+)/) {
337
                $table = $1;
338
                $column = $2;
339
            }
340
            $table ||= $main_table;
341
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
342
            foreach my $i (1 .. 2) {
343
                unless ($type_rule_off_parts->{$i}) {
344
                    my $into = $self->{"_into$i"} || {};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
345
                    
346
                    my $alias = $table;
347
                    $table = $table_alias->{$alias}
348
                      if defined $alias && $table_alias->{$alias};
349
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
350
                    if (defined $table && $into->{$table} &&
351
                        (my $rule = $into->{$table}->{$column}))
352
                    {
353
                        $type_filters->{$i}->{$column} = $rule;
354
                        $type_filters->{$i}->{"$table.$column"} = $rule;
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
355
                        $type_filters->{$i}->{"$alias.$column"} = $rule if $alias ne $table;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
356
                    }
357
                }
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
358
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
359
        }
360
    }
cleanup
Yuki Kimoto authored on 2011-04-02
361
    
362
    # Applied filter
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
363
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
364
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
365
        $applied_filter = {
366
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
367
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
368
        }
369
    }
cleanup
Yuki Kimoto authored on 2011-04-02
370
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
371
    
cleanup
Yuki Kimoto authored on 2011-04-02
372
    # Replace filter name to code
373
    foreach my $column (keys %$filter) {
374
        my $name = $filter->{$column};
375
        if (!defined $name) {
376
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
377
        }
cleanup
Yuki Kimoto authored on 2011-04-02
378
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
379
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
380
            unless exists $self->filters->{$name};
381
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
382
        }
383
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
384
    
cleanup
Yuki Kimoto authored on 2011-04-02
385
    # Create bind values
386
    my $bind = $self->_create_bind_values(
387
        $param,
388
        $query->columns,
389
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
390
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
391
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
392
    );
cleanup
yuki-kimoto authored on 2010-10-17
393
    
394
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
395
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
396
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
397
    eval {
398
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
399
            my $bind_type = $bind->[$i]->{bind_type};
400
            $sth->bind_param(
401
                $i + 1,
402
                $bind->[$i]->{value},
403
                $bind_type ? $bind_type : ()
404
            );
cleanup
Yuki Kimoto authored on 2011-03-21
405
        }
406
        $affected = $sth->execute;
407
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
408
    
409
    if ($@) {
410
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
411
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
412
    }
cleanup
yuki-kimoto authored on 2010-10-17
413
    
improved debug message
Yuki Kimoto authored on 2011-05-23
414
    # DEBUG message
415
    if (DEBUG) {
416
        print STDERR "SQL:\n" . $query->sql . "\n";
417
        my @output;
418
        foreach my $b (@$bind) {
419
            my $value = $b->{value};
420
            $value = 'undef' unless defined $value;
421
            $value = encode(DEBUG_ENCODING(), $value)
422
              if utf8::is_utf8($value);
423
            push @output, $value;
424
        }
425
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
426
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
427
    
cleanup
Yuki Kimoto authored on 2011-04-02
428
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
429
    if ($sth->{NUM_OF_FIELDS}) {
430
        
cleanup
Yuki Kimoto authored on 2011-04-02
431
        # Filter
432
        my $filter = {};
433
        $filter->{in}  = {};
434
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
435
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
436
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
437
            foreach my $way (qw/in end/) {
438
                $filter->{$way} = {
439
                    %{$filter->{$way}},
440
                    %{$self->{filter}{$way}{$table} || {}}
441
                };
442
            }
cleanup
Yuki Kimoto authored on 2011-01-12
443
        }
444
        
445
        # Result
446
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
447
            sth => $sth,
448
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
449
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
450
            filter => $filter->{in} || {},
451
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
452
            type_rule => {
453
                from1 => $self->type_rule->{from1},
454
                from2 => $self->type_rule->{from2}
455
            },
cleanup
yuki-kimoto authored on 2010-10-17
456
        );
457

            
458
        return $result;
459
    }
cleanup
Yuki Kimoto authored on 2011-04-02
460
    
461
    # Not select statement
462
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
463
}
464

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

            
cleanup
yuki-kimoto authored on 2010-10-17
467
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
468
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
469
    
cleanup
yuki-kimoto authored on 2010-10-17
470
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
471
    my $param;
472
    $param = shift if @_ % 2;
473
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
474
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
475
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
476
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
477
    my $p = delete $args{param} || {};
478
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
479
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
480
    my $id = delete $args{id};
481
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
482
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
483
          "must be specified when id is specified " . _subname
484
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
485
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
486
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
487

            
488
    # Check arguments
489
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
490
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
491
          unless $INSERT_ARGS{$name};
492
    }
493

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
494
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
495
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
496
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
497
        $param = $self->merge_param($id_param, $param);
498
    }
499

            
cleanup
Yuki Kimoto authored on 2011-04-02
500
    # Reserved word quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
501
    my $q = $self->_quote;
cleanup
yuki-kimoto authored on 2010-10-17
502
    
cleanup
Yuki Kimoto authored on 2011-04-02
503
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
504
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
505
    push @sql, "insert";
506
    push @sql, $prefix if defined $prefix;
507
    push @sql, "into $q$table$q " . $self->insert_param($param);
508
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
509
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
510
    
511
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
512
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
513
}
514

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
515
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
516
    my ($self, $param) = @_;
517
    
cleanup
Yuki Kimoto authored on 2011-04-02
518
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
519
    my $safety = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
520
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
521
    my @columns;
522
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
523
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
524
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
525
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
526
        my $column_quote = "$q$column$q";
527
        $column_quote =~ s/\./$q.$q/;
528
        push @columns, $column_quote;
529
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
530
    }
531
    
cleanup
Yuki Kimoto authored on 2011-04-02
532
    return '(' . join(', ', @columns) . ') ' . 'values ' .
533
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
534
}
535

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
536
sub include_model {
537
    my ($self, $name_space, $model_infos) = @_;
538
    
cleanup
Yuki Kimoto authored on 2011-04-02
539
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
540
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
541
    
542
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
543
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
544

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
545
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
546
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
547
          if $name_space =~ /[^\w:]/;
548
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
549
        croak qq{Name space module "$name_space.pm" is needed. $@ }
550
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
551
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
552
        
553
        # Search model modules
554
        my $path = $INC{"$name_space.pm"};
555
        $path =~ s/\.pm$//;
556
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
557
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
558
        $model_infos = [];
559
        while (my $module = readdir $dh) {
560
            push @$model_infos, $module
561
              if $module =~ s/\.pm$//;
562
        }
563
        close $dh;
564
    }
565
    
cleanup
Yuki Kimoto authored on 2011-04-02
566
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
567
    foreach my $model_info (@$model_infos) {
568
        
cleanup
Yuki Kimoto authored on 2011-04-02
569
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
570
        my $model_class;
571
        my $model_name;
572
        my $model_table;
573
        if (ref $model_info eq 'HASH') {
574
            $model_class = $model_info->{class};
575
            $model_name  = $model_info->{name};
576
            $model_table = $model_info->{table};
577
            
578
            $model_name  ||= $model_class;
579
            $model_table ||= $model_name;
580
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
581
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
582
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
583
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
584
          if $mclass =~ /[^\w:]/;
585
        unless ($mclass->can('isa')) {
586
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
587
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
588
        }
589
        
cleanup
Yuki Kimoto authored on 2011-04-02
590
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
591
        my $args = {};
592
        $args->{model_class} = $mclass if $mclass;
593
        $args->{name}        = $model_name if $model_name;
594
        $args->{table}       = $model_table if $model_table;
595
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
596
    }
597
    
598
    return $self;
599
}
600

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
601
sub map_param {
602
    my $self = shift;
603
    my $param = shift;
604
    my %map = @_;
605
    
606
    # Mapping
607
    my $map_param = {};
608
    foreach my $key (keys %map) {
609
        my $value_cb;
610
        my $condition;
611
        my $map_key;
612
        
613
        # Get mapping information
614
        if (ref $map{$key} eq 'ARRAY') {
615
            foreach my $some (@{$map{$key}}) {
616
                $map_key = $some unless ref $some;
617
                $condition = $some->{if} if ref $some eq 'HASH';
618
                $value_cb = $some if ref $some eq 'CODE';
619
            }
620
        }
621
        else {
622
            $map_key = $map{$key};
623
        }
624
        $value_cb ||= sub { $_[0] };
625
        $condition ||= sub { defined $_[0] && length $_[0] };
626

            
627
        # Map parameter
628
        my $value;
629
        if (ref $condition eq 'CODE') {
630
            $map_param->{$map_key} = $value_cb->($param->{$key})
631
              if $condition->($param->{$key});
632
        }
633
        elsif ($condition eq 'exists') {
634
            $map_param->{$map_key} = $value_cb->($param->{$key})
635
              if exists $param->{$key};
636
        }
637
        else { croak qq/Condition must be code reference or "exists" / . _subname }
638
    }
639
    
640
    return $map_param;
641
}
642

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

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

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

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

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

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
736
sub order {
737
    my $self = shift;
738
    return DBIx::Custom::Order->new(@_);
739
}
740

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

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

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

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

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

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

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

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

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

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

            
988
                    $self->{"_$into"}{$table}{$column} = $filter;
989
                }
990
            });
991
        }
992

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1098
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1099
}
1100

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1113
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1114
    
updated pod
Yuki Kimoto authored on 2011-06-21
1115
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1116
    
updated pod
Yuki Kimoto authored on 2011-06-21
1117
    # Cache
1118
    my $cache = $self->cache;
1119
    
1120
    # Query
1121
    my $query;
1122
    
1123
    # Get cached query
1124
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1125
        
updated pod
Yuki Kimoto authored on 2011-06-21
1126
        # Get query
1127
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1128
        
updated pod
Yuki Kimoto authored on 2011-06-21
1129
        # Create query
1130
        if ($q) {
1131
            $query = DBIx::Custom::Query->new($q);
1132
            $query->filters($self->filters);
cleanup
Yuki Kimoto authored on 2011-06-13
1133
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1134
    }
1135
    
1136
    # Create query
1137
    unless ($query) {
1138

            
1139
        # Create query
1140
        my $builder = $self->query_builder;
1141
        $query = $builder->build_query($source);
1142

            
1143
        # Remove reserved word quote
1144
        if (my $q = $self->_quote) {
1145
            $_ =~ s/$q//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1146
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1147

            
1148
        # Save query to cache
1149
        $self->cache_method->(
1150
            $self, $source,
1151
            {
1152
                sql     => $query->sql, 
1153
                columns => $query->columns,
1154
                tables  => $query->tables
1155
            }
1156
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1157
    }
1158
    
updated pod
Yuki Kimoto authored on 2011-06-21
1159
    # Prepare statement handle
1160
    my $sth;
1161
    eval { $sth = $self->dbh->prepare($query->{sql})};
1162
    
1163
    if ($@) {
1164
        $self->_croak($@, qq{. Following SQL is executed.\n}
1165
                        . qq{$query->{sql}\n} . _subname);
1166
    }
1167
    
1168
    # Set statement handle
1169
    $query->sth($sth);
1170
    
1171
    # Set filters
1172
    $query->filters($self->filters);
1173
    
1174
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1175
}
1176

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

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

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

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

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1429
sub _apply_filter {
1430
    my ($self, $table, @cinfos) = @_;
1431

            
1432
    # Initialize filters
1433
    $self->{filter} ||= {};
1434
    $self->{filter}{out} ||= {};
1435
    $self->{filter}{in} ||= {};
1436
    $self->{filter}{end} ||= {};
1437
    
1438
    # Usage
1439
    my $usage = "Usage: \$dbi->apply_filter(" .
1440
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1441
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1442
    
1443
    # Apply filter
1444
    for (my $i = 0; $i < @cinfos; $i += 2) {
1445
        
1446
        # Column
1447
        my $column = $cinfos[$i];
1448
        if (ref $column eq 'ARRAY') {
1449
            foreach my $c (@$column) {
1450
                push @cinfos, $c, $cinfos[$i + 1];
1451
            }
1452
            next;
1453
        }
1454
        
1455
        # Filter infomation
1456
        my $finfo = $cinfos[$i + 1] || {};
1457
        croak "$usage (table: $table) " . _subname
1458
          unless  ref $finfo eq 'HASH';
1459
        foreach my $ftype (keys %$finfo) {
1460
            croak "$usage (table: $table) " . _subname
1461
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1462
        }
1463
        
1464
        # Set filters
1465
        foreach my $way (qw/in out end/) {
1466
        
1467
            # Filter
1468
            my $filter = $finfo->{$way};
1469
            
1470
            # Filter state
1471
            my $state = !exists $finfo->{$way} ? 'not_exists'
1472
                      : !defined $filter        ? 'not_defined'
1473
                      : ref $filter eq 'CODE'   ? 'code'
1474
                      : 'name';
1475
            
1476
            # Filter is not exists
1477
            next if $state eq 'not_exists';
1478
            
1479
            # Check filter name
1480
            croak qq{Filter "$filter" is not registered } . _subname
1481
              if  $state eq 'name'
1482
               && ! exists $self->filters->{$filter};
1483
            
1484
            # Set filter
1485
            my $f = $state eq 'not_defined' ? undef
1486
                  : $state eq 'code'        ? $filter
1487
                  : $self->filters->{$filter};
1488
            $self->{filter}{$way}{$table}{$column} = $f;
1489
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1490
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1491
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1492
        }
1493
    }
1494
    
1495
    return $self;
1496
}
1497

            
1498
# DEPRECATED!
1499
sub create_query {
1500
    warn "create_query is DEPRECATED! use query option of each method";
1501
    shift->_create_query(@_);
1502
}
1503

            
cleanup
Yuki Kimoto authored on 2011-06-13
1504
# DEPRECATED!
1505
sub apply_filter {
1506
    my $self = shift;
1507
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1508
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1509
    return $self->_apply_filter(@_);
1510
}
1511

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1512
# DEPRECATED!
1513
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1514
sub select_at {
1515
    my ($self, %args) = @_;
1516

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1519
    # Arguments
1520
    my $primary_keys = delete $args{primary_key};
1521
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1522
    my $where = delete $args{where};
1523
    my $param = delete $args{param};
1524
    
1525
    # Check arguments
1526
    foreach my $name (keys %args) {
1527
        croak qq{"$name" is wrong option } . _subname
1528
          unless $SELECT_AT_ARGS{$name};
1529
    }
1530
    
1531
    # Table
1532
    croak qq{"table" option must be specified } . _subname
1533
      unless $args{table};
1534
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1535
    
1536
    # Create where parameter
1537
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1538
    
1539
    return $self->select(where => $where_param, %args);
1540
}
1541

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1542
# DEPRECATED!
1543
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1544
sub delete_at {
1545
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1546

            
1547
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1548
    
1549
    # Arguments
1550
    my $primary_keys = delete $args{primary_key};
1551
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1552
    my $where = delete $args{where};
1553
    
1554
    # Check arguments
1555
    foreach my $name (keys %args) {
1556
        croak qq{"$name" is wrong option } . _subname
1557
          unless $DELETE_AT_ARGS{$name};
1558
    }
1559
    
1560
    # Create where parameter
1561
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1562
    
1563
    return $self->delete(where => $where_param, %args);
1564
}
1565

            
cleanup
Yuki Kimoto authored on 2011-06-08
1566
# DEPRECATED!
1567
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1568
sub update_at {
1569
    my $self = shift;
1570

            
1571
    warn "update_at is DEPRECATED! use update and id option instead";
1572
    
1573
    # Arguments
1574
    my $param;
1575
    $param = shift if @_ % 2;
1576
    my %args = @_;
1577
    my $primary_keys = delete $args{primary_key};
1578
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1579
    my $where = delete $args{where};
1580
    my $p = delete $args{param} || {};
1581
    $param  ||= $p;
1582
    
1583
    # Check arguments
1584
    foreach my $name (keys %args) {
1585
        croak qq{"$name" is wrong option } . _subname
1586
          unless $UPDATE_AT_ARGS{$name};
1587
    }
1588
    
1589
    # Create where parameter
1590
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1591
    
1592
    return $self->update(where => $where_param, param => $param, %args);
1593
}
1594

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1595
# DEPRECATED!
1596
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1597
sub insert_at {
1598
    my $self = shift;
1599
    
1600
    warn "insert_at is DEPRECATED! use insert and id option instead";
1601
    
1602
    # Arguments
1603
    my $param;
1604
    $param = shift if @_ % 2;
1605
    my %args = @_;
1606
    my $primary_key = delete $args{primary_key};
1607
    $primary_key = [$primary_key] unless ref $primary_key;
1608
    my $where = delete $args{where};
1609
    my $p = delete $args{param} || {};
1610
    $param  ||= $p;
1611
    
1612
    # Check arguments
1613
    foreach my $name (keys %args) {
1614
        croak qq{"$name" is wrong option } . _subname
1615
          unless $INSERT_AT_ARGS{$name};
1616
    }
1617
    
1618
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1619
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1620
    $param = $self->merge_param($where_param, $param);
1621
    
1622
    return $self->insert(param => $param, %args);
1623
}
1624

            
added warnings
Yuki Kimoto authored on 2011-06-07
1625
# DEPRECATED!
1626
sub register_tag {
1627
    warn "register_tag is DEPRECATED!";
1628
    shift->query_builder->register_tag(@_)
1629
}
1630

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1631
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1632
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1633
has dbi_options => sub { {} };
1634
has filter_check  => 1;
1635
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1636

            
cleanup
Yuki Kimoto authored on 2011-01-25
1637
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1638
sub default_bind_filter {
1639
    my $self = shift;
1640
    
cleanup
Yuki Kimoto authored on 2011-06-13
1641
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1642
    
cleanup
Yuki Kimoto authored on 2011-01-12
1643
    if (@_) {
1644
        my $fname = $_[0];
1645
        
1646
        if (@_ && !$fname) {
1647
            $self->{default_out_filter} = undef;
1648
        }
1649
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1650
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1651
              unless exists $self->filters->{$fname};
1652
        
1653
            $self->{default_out_filter} = $self->filters->{$fname};
1654
        }
1655
        return $self;
1656
    }
1657
    
1658
    return $self->{default_out_filter};
1659
}
1660

            
cleanup
Yuki Kimoto authored on 2011-01-25
1661
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1662
sub default_fetch_filter {
1663
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1664

            
cleanup
Yuki Kimoto authored on 2011-06-13
1665
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1666
    
1667
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1668
        my $fname = $_[0];
1669

            
cleanup
Yuki Kimoto authored on 2011-01-12
1670
        if (@_ && !$fname) {
1671
            $self->{default_in_filter} = undef;
1672
        }
1673
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1674
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1675
              unless exists $self->filters->{$fname};
1676
        
1677
            $self->{default_in_filter} = $self->filters->{$fname};
1678
        }
1679
        
1680
        return $self;
1681
    }
1682
    
many changed
Yuki Kimoto authored on 2011-01-23
1683
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1684
}
1685

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1686
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1687
sub insert_param_tag {
1688
    warn "insert_param_tag is DEPRECATED! " .
1689
         "use insert_param instead!";
1690
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1691
}
1692

            
cleanup
Yuki Kimoto authored on 2011-01-25
1693
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1694
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1695
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1696
    return shift->query_builder->register_tag_processor(@_);
1697
}
1698

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1699
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1700
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1701
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1702
         "use update_param instead";
1703
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1704
}
cleanup
Yuki Kimoto authored on 2011-03-08
1705
# DEPRECATED!
1706
sub _push_relation {
1707
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1708
    
1709
    if (keys %{$relation || {}}) {
1710
        push @$sql, $need_where ? 'where' : 'and';
1711
        foreach my $rcolumn (keys %$relation) {
1712
            my $table1 = (split (/\./, $rcolumn))[0];
1713
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1714
            push @$tables, ($table1, $table2);
1715
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1716
        }
1717
    }
1718
    pop @$sql if $sql->[-1] eq 'and';    
1719
}
1720

            
1721
# DEPRECATED!
1722
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1723
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1724
    
1725
    if (keys %{$relation || {}}) {
1726
        foreach my $rcolumn (keys %$relation) {
1727
            my $table1 = (split (/\./, $rcolumn))[0];
1728
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1729
            my $table1_exists;
1730
            my $table2_exists;
1731
            foreach my $table (@$tables) {
1732
                $table1_exists = 1 if $table eq $table1;
1733
                $table2_exists = 1 if $table eq $table2;
1734
            }
1735
            unshift @$tables, $table1 unless $table1_exists;
1736
            unshift @$tables, $table2 unless $table2_exists;
1737
        }
1738
    }
1739
}
1740

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1743
=head1 NAME
1744

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1745
DBIx::Custom - Execute insert, update, delete, and select statement easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1746

            
1747
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1748

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1749
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1750
    
1751
    # Connect
1752
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1753
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1754
        user => 'ken',
1755
        password => '!LFKD%$&',
1756
        dbi_option => {mysql_enable_utf8 => 1}
1757
    );
cleanup
yuki-kimoto authored on 2010-08-05
1758

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1759
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1760
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1761
    
1762
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1763
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1764
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1765
    
1766
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1767
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1768

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1769
    # Select
updated pod
Yuki Kimoto authored on 2011-06-21
1770
    my $result = $dbi->select(table  => 'book',
1771
      column => ['title', 'author'], where  => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1772

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1773
    # Select, more complex
1774
    my $result = $dbi->select(
1775
        table  => 'book',
1776
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1777
            {book => [qw/title author/]},
1778
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1779
        ],
1780
        where  => {'book.author' => 'Ken'},
1781
        join => ['left outer join company on book.company_id = company.id'],
1782
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1783
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1784
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1785
    # Fetch
1786
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1787
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1788
    }
1789
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1790
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1791
    while (my $row = $result->fetch_hash) {
1792
        
1793
    }
1794
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1795
    # Execute SQL with parameter.
1796
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1797
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1798
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1799
    );
1800
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1801
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1802

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

            
1805
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1806

            
updated pod
Yuki Kimoto authored on 2011-06-21
1807
L<DBIx::Custom> is the wrapper class of L<DBI> to execute SQL easily.
1808
This module have the following features.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1809

            
updated pod
Yuki Kimoto authored on 2011-06-21
1810
=over 4
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1811

            
updated pod
Yuki Kimoto authored on 2011-06-21
1812
=item * Execute INSERT, UPDATE, DELETE, SELECT statement easily
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1813

            
updated pod
Yuki Kimoto authored on 2011-06-21
1814
=item * You can specify bind values by hash reference
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1815

            
updated pod
Yuki Kimoto authored on 2011-06-21
1816
=item * Filtering by data type. and you can set filter to any column
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1817

            
updated pod
Yuki Kimoto authored on 2011-06-21
1818
=item * Creating where clause flexibly
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1819

            
updated pod
Yuki Kimoto authored on 2011-06-21
1820
=item * Support model
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1821

            
1822
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1823

            
1824
=head1 GUIDE
1825

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1839
Connection manager object. if connector is set, you can get C<dbh>
1840
through connection manager. conection manager object must have C<dbh> mehtod.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1841

            
1842
This is L<DBIx::Connector> example. Please pass
updated pod
Yuki Kimoto authored on 2011-06-21
1843
C<default_dbi_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1844

            
1845
    my $connector = DBIx::Connector->new(
1846
        "dbi:mysql:database=$DATABASE",
1847
        $USER,
1848
        $PASSWORD,
1849
        DBIx::Custom->new->default_dbi_option
1850
    );
1851
    
updated pod
Yuki Kimoto authored on 2011-06-21
1852
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1853

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1859
Data source name, used when C<connect> method is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1860

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1866
L<DBI> option, used when C<connect> method is executed.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1867
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1868

            
1869
=head2 C<default_dbi_option>
1870

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1874
L<DBI> default option, used when C<connect> method is executed,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1875
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1876

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1877
    {
1878
        RaiseError => 1,
1879
        PrintError => 0,
1880
        AutoCommit => 1,
1881
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1882

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1888
Filters, registered by C<register_filter> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1889

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1895
Models, included by C<include_model> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1896

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1902
Password, used when C<connect> method is executed.
update document
yuki-kimoto authored on 2010-01-30
1903

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1940
User name, used when C<connect> method is executed.
update pod
Yuki Kimoto authored on 2011-01-27
1941

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

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

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

            
1950
    print $dbi->available_data_type;
1951

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
1952
Get available data types. You can use these data types
updated pod
Yuki Kimoto authored on 2011-06-21
1953
in C<type rule>'s C<from1> and C<from2> section.
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
1954

            
1955
=head2 C<available_type_name> EXPERIMENTAL
1956

            
1957
    print $dbi->available_type_name;
1958

            
1959
Get available type names. You can use these type names in
updated pod
Yuki Kimoto authored on 2011-06-21
1960
C<type_rule>'s C<into1> and C<into2> section.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1961

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

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

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

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

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

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

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

            
1976
Create column clause. The follwoing column clause is created.
1977

            
1978
    book.author as "book.author",
1979
    book.title as "book.title"
1980

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1983
    # Separator is double underbar
1984
    $dbi->separator('__');
1985
    
1986
    book.author as "book__author",
1987
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1988

            
cleanup
Yuki Kimoto authored on 2011-06-13
1989
    # Separator is hyphen
1990
    $dbi->separator('-');
1991
    
1992
    book.author as "book-author",
1993
    book.title as "book-title"
1994
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1995
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1996

            
update pod
Yuki Kimoto authored on 2011-03-13
1997
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1998
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1999
        user => 'ken',
2000
        password => '!LFKD%$&',
2001
        dbi_option => {mysql_enable_utf8 => 1}
2002
    );
2003

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2012
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2013
        table => 'book',
2014
        primary_key => 'id',
2015
        join => [
2016
            'inner join company on book.comparny_id = company.id'
2017
        ],
2018
    );
2019

            
2020
Create L<DBIx::Custom::Model> object and initialize model.
updated pod
Yuki Kimoto authored on 2011-06-21
2021
the module is also used from C<model> method.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2022

            
2023
   $dbi->model('book')->select(...);
2024

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

            
2027
    my $dbh = $dbi->dbh;
2028

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2029
Get L<DBI> database handle. if C<connector> is set, you can get
updated pod
Yuki Kimoto authored on 2011-06-21
2030
database handle through C<connector> object.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2031

            
2032
=head2 C<each_column>
2033

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2053
    my $result = $dbi->execute(
updated pod
Yuki Kimoto authored on 2011-06-21
2054
      "select * from book where title = :title and author like :author",
2055
      {title => 'Perl', author => '%Ken%'}
2056
    );
2057

            
2058
    my $result = $dbi->execute(
2059
      "select * from book where title = :book.title and author like :book.author",
2060
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2061
    );
2062

            
updated pod
Yuki Kimoto authored on 2011-06-21
2063
Execute SQL. SQL can contain column parameter such as :author and :title.
2064
You can append table name to column name such as :book.title and :book.author.
2065
Second argunet is data, embedded into column parameter.
2066
Return value is L<DBIx::Custom::Result> object when select statement is executed,
2067
or the count of affected rows when insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2068

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

            
2071
    select * from where title = ? and author like ?;
2072

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

            
2075
=over 4
2076

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

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

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

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

            
2102
    query => 1
2103

            
2104
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
updated pod
Yuki Kimoto authored on 2011-06-21
2105
You can check executed SQL and columns order.
2106

            
2107
    my $sql = $query->sql;
2108
    my $columns = $query->columns;
updated document
Yuki Kimoto authored on 2011-06-09
2109

            
updated pod
Yuki Kimoto authored on 2011-06-09
2110
=item C<table>
2111
    
2112
    table => 'author'
2113

            
updated pod
Yuki Kimoto authored on 2011-06-21
2114
If you want to omit table name in column name
2115
and enable C<into1> and C<into2> type filter,
2116
You must set C<table> option.
updated pod
Yuki Kimoto authored on 2011-06-09
2117

            
updated pod
Yuki Kimoto authored on 2011-06-21
2118
    $dbi->execute("select * from book where title = :title and author = :author",
2119
        {title => 'Perl', author => 'Ken', table => 'book');
updated pod
Yuki Kimoto authored on 2011-06-09
2120

            
updated pod
Yuki Kimoto authored on 2011-06-21
2121
    # Same
2122
    $dbi->execute(
2123
      "select * from book where title = :book.title and author = :book.author",
2124
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2125

            
updated pod
Yuki Kimoto authored on 2011-06-21
2126
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2127

            
updated pod
Yuki Kimoto authored on 2011-06-21
2128
Specify database bind data type.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2129

            
updated pod
Yuki Kimoto authored on 2011-06-21
2130
    bind_type => [image => DBI::SQL_BLOB]
2131
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2132

            
updated pod
Yuki Kimoto authored on 2011-06-21
2133
This is used to bind parameter by C<bind_param> of statment handle.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2134

            
updated pod
Yuki Kimoto authored on 2011-06-21
2135
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2136

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2137
=item C<table_alias> EXPERIMENTAL
2138

            
2139
    table_alias => {user => 'hiker'}
2140

            
2141
Table alias. Key is real table name, value is alias table name.
2142
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2143
on alias table name.
2144

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

            
2147
    type_rule_off => 1
2148

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

            
2151
=item C<type_rule1_off> EXPERIMENTAL
2152

            
2153
    type_rule1_off => 1
2154

            
2155
Turn C<into1> type rule off.
2156

            
2157
=item C<type_rule2_off> EXPERIMENTAL
2158

            
2159
    type_rule2_off => 1
2160

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2173
=over 4
2174

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

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

            
2179
=item C<filter>
2180

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2191
    $dbi->delete(
2192
        parimary_key => ['id1', 'id2'],
2193
        id => [4, 5],
2194
        table => 'book',
2195
    );
update pod
Yuki Kimoto authored on 2011-03-13
2196

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

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

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

            
2203
    prefix => 'some'
2204

            
2205
prefix before table name section.
2206

            
2207
    delete some from book
2208

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2217
Table name.
2218

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2227
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2228

            
updated pod
Yuki Kimoto authored on 2011-06-21
2229
Same as C<execute> method's C<bind_type> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2230

            
2231
=item C<type_rule_off> EXPERIMENTAL
2232

            
2233
Same as C<execute> method's C<type_rule_off> option.
2234

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

            
2237
    type_rule1_off => 1
2238

            
2239
Same as C<execute> method's C<type_rule1_off> option.
2240

            
2241
=item C<type_rule2_off> EXPERIMENTAL
2242

            
2243
    type_rule2_off => 1
2244

            
2245
Same as C<execute> method's C<type_rule2_off> option.
2246

            
updated pod
Yuki Kimoto authored on 2011-06-08
2247
=back
update pod
Yuki Kimoto authored on 2011-03-13
2248

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2253
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
2254
Options is same as C<delete>.
update pod
Yuki Kimoto authored on 2011-03-13
2255

            
cleanup
yuki-kimoto authored on 2010-10-17
2256
=head2 C<insert>
2257

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2260
Execute insert statement. First argument is row data. Return value is
2261
affected row count.
update pod
Yuki Kimoto authored on 2011-03-13
2262

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

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

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

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

            
2271
=item C<filter>
2272

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

            
2275
=item C<id>
2276

            
updated document
Yuki Kimoto authored on 2011-06-09
2277
    id => 4
2278
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2279

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2283
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2284
        {title => 'Perl', author => 'Ken'}
2285
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2286
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2287
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2288
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2289

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

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

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

            
2299
    prefix => 'or replace'
2300

            
2301
prefix before table name section
2302

            
2303
    insert or replace into book
2304

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

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

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

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

            
2314
Same as C<execute> method's C<query> option.
2315

            
2316
=item C<table>
2317

            
2318
    table => 'book'
2319

            
2320
Table name.
2321

            
updated pod
Yuki Kimoto authored on 2011-06-21
2322
=item C<bind_type>
cleanup
yuki-kimoto authored on 2010-10-17
2323

            
updated pod
Yuki Kimoto authored on 2011-06-21
2324
Same as C<execute> method's C<bind_type> option.
cleanup
yuki-kimoto authored on 2010-10-17
2325

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

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

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

            
2332
    type_rule1_off => 1
2333

            
2334
Same as C<execute> method's C<type_rule1_off> option.
2335

            
2336
=item C<type_rule2_off> EXPERIMENTAL
2337

            
2338
    type_rule2_off => 1
2339

            
2340
Same as C<execute> method's C<type_rule2_off> option.
2341

            
update pod
Yuki Kimoto authored on 2011-03-13
2342
=back
2343

            
2344
=over 4
2345

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2361
    lib / MyModel.pm
2362
        / MyModel / book.pm
2363
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2364

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

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

            
2369
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2370
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2371
    
2372
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2373

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2378
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2379
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2380
    
2381
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2382

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2385
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2386
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2387
    
2388
    1;
2389
    
updated pod
Yuki Kimoto authored on 2011-06-21
2390
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2391

            
updated pod
Yuki Kimoto authored on 2011-06-21
2392
You can get model object by C<model>.
update pod
Yuki Kimoto authored on 2011-03-13
2393

            
updated pod
Yuki Kimoto authored on 2011-06-21
2394
    my $book_model = $dbi->model('book');
update pod
Yuki Kimoto authored on 2011-03-13
2395
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2396

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
2399
=head2 C<map_param> EXPERIMENTAL
2400

            
2401
    my $map_param = $dbi->map_param(
2402
        {id => 1, authro => 'Ken', price => 1900},
2403
        'id' => 'book.id',
2404
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2405
        'price' => [
2406
            'book.price', {if => sub { length $_[0] }}
2407
        ]
2408
    );
2409

            
2410
Map paramters to other key and value. First argument is original
2411
parameter. this is hash reference. Rest argument is mapping.
2412
By default, Mapping is done if the value length is not zero.
2413

            
2414
=over 4
2415

            
2416
=item Key mapping
2417

            
2418
    'id' => 'book.id'
2419

            
2420
This is only key mapping. Value is same as original one.
2421

            
2422
    (id => 1) is mapped to ('book.id' => 1) if value length is not zero.
2423

            
2424
=item Key and value mapping
2425

            
2426
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2427

            
2428
This is key and value mapping. Frist element of array reference
2429
is mapped key name, second element is code reference to map the value.
2430

            
2431
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2432
      if value length is not zero.
2433

            
2434
=item Condition
2435

            
2436
    'price' => ['book.price', {if => 'exists'}]
2437
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2438
    'price' => ['book.price', {if => sub { defined shift }}]
2439

            
2440
If you need condition, you can sepecify it. this is code reference
2441
or 'exists'. By default, condition is the following one.
2442

            
2443
    sub { defined $_[0] && length $_[0] }
2444

            
2445
=back
2446

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

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

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

            
2453
    {key1 => [1, 1], key2 => 2}
2454

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

            
2457
    $dbi->method(
2458
        update_or_insert => sub {
2459
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2460
            
2461
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2462
        },
2463
        find_or_create   => sub {
2464
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2465
            
2466
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2467
        }
2468
    );
2469

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

            
2472
    $dbi->update_or_insert;
2473
    $dbi->find_or_create;
2474

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

            
2477
    my $model = $dbi->model('book');
2478

            
updated pod
Yuki Kimoto authored on 2011-06-21
2479
Get a L<DBIx::Custom::Model> object,
update pod
Yuki Kimoto authored on 2011-03-13
2480

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

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

            
2485
Create column clause for myself. The follwoing column clause is created.
2486

            
2487
    book.author as author,
2488
    book.title as title
2489

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2492
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2493
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2494
        user => 'ken',
2495
        password => '!LFKD%$&',
2496
        dbi_option => {mysql_enable_utf8 => 1}
2497
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2498

            
2499
Create a new L<DBIx::Custom> object.
2500

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

            
2503
    my $not_exists = $dbi->not_exists;
2504

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2508
=head2 C<order> EXPERIMENTAL
2509

            
2510
    my $order = $dbi->order;
2511

            
2512
Create a new L<DBIx::Custom::Order> object.
2513

            
cleanup
yuki-kimoto authored on 2010-10-17
2514
=head2 C<register_filter>
2515

            
update pod
Yuki Kimoto authored on 2011-03-13
2516
    $dbi->register_filter(
2517
        # Time::Piece object to database DATE format
2518
        tp_to_date => sub {
2519
            my $tp = shift;
2520
            return $tp->strftime('%Y-%m-%d');
2521
        },
2522
        # database DATE format to Time::Piece object
2523
        date_to_tp => sub {
2524
           my $date = shift;
2525
           return Time::Piece->strptime($date, '%Y-%m-%d');
2526
        }
2527
    );
cleanup
yuki-kimoto authored on 2010-10-17
2528
    
update pod
Yuki Kimoto authored on 2011-03-13
2529
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2530

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

            
2533
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2534
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2535
            date => sub { ... },
2536
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2537
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2538
        into2 => {
2539
            date => sub { ... },
2540
            datetime => sub { ... }
2541
        },
2542
        from1 => {
2543
            # DATE
2544
            9 => sub { ... },
2545
            # DATETIME or TIMESTAMP
2546
            11 => sub { ... },
2547
        }
2548
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2549
            # DATE
2550
            9 => sub { ... },
2551
            # DATETIME or TIMESTAMP
2552
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2553
        }
2554
    );
2555

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2566
C<into2> is executed after C<into1>.
2567

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2568
Type rule of C<into1> and C<into2> is enabled on the following
2569
column name.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2570

            
cleanup
Yuki Kimoto authored on 2011-06-13
2571
=over 4
2572

            
2573
=item 1. column name
2574

            
2575
    issue_date
2576
    issue_datetime
2577

            
updated pod
Yuki Kimoto authored on 2011-06-21
2578
This need C<table> option in each method.
2579

            
cleanup
Yuki Kimoto authored on 2011-06-13
2580
=item 2. table name and column name, separator is dot
2581

            
2582
    book.issue_date
2583
    book.issue_datetime
2584

            
2585
=back
2586

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

            
2589
    print $dbi->available_type_name;
2590

            
updated pod
Yuki Kimoto authored on 2011-06-21
2591
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2592
C<from2> is executed after C<from1>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2593
You get all data type by C<available_data_type>.
2594

            
2595
    print $dbi->available_data_type;
2596

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

            
2599
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2600
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2601
            [qw/DATE DATETIME/] => sub { ... },
2602
        ],
2603
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2604

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2607
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2608
        table  => 'book',
2609
        column => ['author', 'title'],
2610
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2611
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2612
    
updated document
Yuki Kimoto authored on 2011-06-09
2613
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2614

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

            
2617
=over 4
2618

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2623
Append statement to last of SQL.
2624
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2625
=item C<column>
2626
    
updated document
Yuki Kimoto authored on 2011-06-09
2627
    column => 'author'
2628
    column => ['author', 'title']
2629

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2636
You can specify hash of array reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2637

            
updated document
Yuki Kimoto authored on 2011-06-09
2638
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2639
        {book => [qw/author title/]},
2640
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2641
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2642

            
updated pod
Yuki Kimoto authored on 2011-06-21
2643
This is expanded to the following one by using C<colomn> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2644

            
2645
    book.author as "book.author",
2646
    book.title as "book.title",
2647
    person.name as "person.name",
2648
    person.age as "person.age"
2649

            
updated pod
Yuki Kimoto authored on 2011-06-21
2650
You can specify array of array reference.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2651

            
updated document
Yuki Kimoto authored on 2011-06-09
2652
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2653
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2654
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2655

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

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

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

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

            
2664
=item C<id>
2665

            
2666
    id => 4
2667
    id => [4, 5]
2668

            
2669
ID corresponding to C<primary_key>.
2670
You can select rows by C<id> and C<primary_key>.
2671

            
2672
    $dbi->select(
2673
        parimary_key => ['id1', 'id2'],
2674
        id => [4, 5],
2675
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2676
    );
2677

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2680
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2681
        where => {id1 => 4, id2 => 5},
2682
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2683
    );
2684
    
updated document
Yuki Kimoto authored on 2011-06-09
2685
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2686

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

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

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

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

            
2699
    prefix => 'SQL_CALC_FOUND_ROWS'
2700

            
2701
Prefix of column cluase
2702

            
2703
    select SQL_CALC_FOUND_ROWS title, author from book;
2704

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

            
2707
    join => [
2708
        'left outer join company on book.company_id = company_id',
2709
        'left outer join location on company.location_id = location.id'
2710
    ]
2711
        
2712
Join clause. If column cluase or where clause contain table name like "company.name",
2713
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2714

            
2715
    $dbi->select(
2716
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2717
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2718
        where => {'company.name' => 'Orange'},
2719
        join => [
2720
            'left outer join company on book.company_id = company.id',
2721
            'left outer join location on company.location_id = location.id'
2722
        ]
2723
    );
2724

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2728
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2729
    from book
2730
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2731
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2732

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2744
=item C<bind_type>
updated pod
Yuki Kimoto authored on 2011-06-08
2745

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2752
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2753

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

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

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

            
2760
    type_rule1_off => 1
2761

            
2762
Same as C<execute> method's C<type_rule1_off> option.
2763

            
2764
=item C<type_rule2_off> EXPERIMENTAL
2765

            
2766
    type_rule2_off => 1
2767

            
2768
Same as C<execute> method's C<type_rule2_off> option.
2769

            
updated document
Yuki Kimoto authored on 2011-06-09
2770
=item C<where>
2771
    
2772
    # Hash refrence
2773
    where => {author => 'Ken', 'title' => 'Perl'}
2774
    
2775
    # DBIx::Custom::Where object
2776
    where => $dbi->where(
2777
        clause => ['and', 'author = :author', 'title like :title'],
2778
        param  => {author => 'Ken', title => '%Perl%'}
2779
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2780
    
2781
    # Array reference 1 (array reference, hash referenc). same as above
2782
    where => [
2783
        ['and', 'author = :author', 'title like :title'],
2784
        {author => 'Ken', title => '%Perl%'}
2785
    ];    
2786
    
2787
    # Array reference 2 (String, hash reference)
2788
    where => [
2789
        'title like :title',
2790
        {title => '%Perl%'}
2791
    ]
2792
    
2793
    # String
2794
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
2795

            
updated document
Yuki Kimoto authored on 2011-06-09
2796
Where clause.
2797
    
improved pod
Yuki Kimoto authored on 2011-04-19
2798
=item C<wrap> EXPERIMENTAL
2799

            
2800
Wrap statement. This is array reference.
2801

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

            
2804
This option is for Oracle and SQL Server paging process.
2805

            
update pod
Yuki Kimoto authored on 2011-03-12
2806
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2807

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2812
Execute update statement. First argument is update data.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2813

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2816
=over 4
2817

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2828
    id => 4
2829
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2830

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2834
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2835
        {title => 'Perl', author => 'Ken'}
2836
        parimary_key => ['id1', 'id2'],
2837
        id => [4, 5],
2838
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2839
    );
update pod
Yuki Kimoto authored on 2011-03-13
2840

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2843
    $dbi->update(
2844
        {title => 'Perl', author => 'Ken'}
2845
        where => {id1 => 4, id2 => 5},
2846
        table => 'book'
2847
    );
update pod
Yuki Kimoto authored on 2011-03-13
2848

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

            
2851
    prefix => 'or replace'
2852

            
2853
prefix before table name section
2854

            
2855
    update or replace book
2856

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

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

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

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

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2878
=item C<bind_type>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2879

            
2880
Same as C<execute> method's C<type> option.
2881

            
2882
=item C<type_rule_off> EXPERIMENTAL
2883

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

            
2886
=item C<type_rule1_off> EXPERIMENTAL
2887

            
2888
    type_rule1_off => 1
2889

            
2890
Same as C<execute> method's C<type_rule1_off> option.
2891

            
2892
=item C<type_rule2_off> EXPERIMENTAL
2893

            
2894
    type_rule2_off => 1
2895

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2898
=back
update pod
Yuki Kimoto authored on 2011-03-13
2899

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2904
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
2905
Options is same as C<update> method.
update pod
Yuki Kimoto authored on 2011-03-13
2906

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

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

            
2911
Create update parameter tag.
2912

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

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

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

            
2922
Create a new L<DBIx::Custom::Where> object.
2923

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

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

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

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

            
2933
=head2 C<DBIX_CUSTOM_DEBUG>
2934

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

            
2938
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2939

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2942
=head1 DEPRECATED FUNCTIONALITIES
2943

            
2944
L<DBIx::Custom>
2945

            
2946
    # Attribute methods
2947
    data_source # Removed at 2017/1/1
2948
    dbi_options # Removed at 2017/1/1
2949
    filter_check # Removed at 2017/1/1
2950
    reserved_word_quote # Removed at 2017/1/1
2951
    
2952
    # Methods
2953
    create_query # Removed at 2017/1/1
2954
    apply_filter # Removed at 2017/1/1
2955
    select_at # Removed at 2017/1/1
2956
    delete_at # Removed at 2017/1/1
2957
    update_at # Removed at 2017/1/1
2958
    insert_at # Removed at 2017/1/1
2959
    register_tag # Removed at 2017/1/1
2960
    default_bind_filter # Removed at 2017/1/1
2961
    default_fetch_filter # Removed at 2017/1/1
2962
    insert_param_tag # Removed at 2017/1/1
2963
    register_tag_processor # Removed at 2017/1/1
2964
    update_param_tag # Removed at 2017/1/1
2965
    
2966
    # Options
2967
    select method relation option # Removed at 2017/1/1
2968
    select method param option # Removed at 2017/1/1
2969
    
2970
    # Others
2971
    execute("select * from {= title}"); # execute tag parsing functionality
2972
                                        # Removed at 2017/1/1
2973

            
2974
L<DBIx::Custom::Model>
2975

            
2976
    # Attribute method
2977
    filter # Removed at 2017/1/1
2978
    name # Removed at 2017/1/1
2979
    type # Removed at 2017/1/1
2980

            
2981
L<DBIx::Custom::Query>
2982
    
2983
    # Attribute method
2984
    default_filter # Removed at 2017/1/1
2985

            
2986
L<DBIx::Custom::QueryBuilder>
2987
    
2988
    # Attribute method
2989
    tags # Removed at 2017/1/1
2990
    tag_processors # Removed at 2017/1/1
2991
    
2992
    # Method
2993
    register_tag # Removed at 2017/1/1
2994
    register_tag_processor # Removed at 2017/1/1
2995
    
2996
    # Others
2997
    build_query("select * from {= title}"); # tag parsing functionality
2998
                                            # Removed at 2017/1/1
2999

            
3000
L<DBIx::Custom::Result>
3001
    
3002
    # Attribute method
3003
    filter_check # Removed at 2017/1/1
3004
    
3005
    # Methods
3006
    end_filter # Removed at 2017/1/1
3007
    remove_end_filter # Removed at 2017/1/1
3008
    remove_filter # Removed at 2017/1/1
3009
    default_filter # Removed at 2017/1/1
3010

            
3011
L<DBIx::Custom::Tag>
3012

            
3013
    This module is DEPRECATED! # Removed at 2017/1/1
3014

            
3015
=head1 BACKWORD COMPATIBLE POLICY
3016

            
3017
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3018
except for attribute method.
3019
You can check all DEPRECATED functionalities by document.
3020
DEPRECATED functionality is removed after five years,
3021
but if at least one person use the functionality and tell me that thing
3022
I extend one year each time you tell me it.
3023

            
3024
EXPERIMENTAL functionality will be changed without warnings.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3025

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3026
This policy is changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3027

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

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

            
3032
C<< <kimoto.yuki at gmail.com> >>
3033

            
3034
L<http://github.com/yuki-kimoto/DBIx-Custom>
3035

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3036
=head1 AUTHOR
3037

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

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

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

            
3044
This program is free software; you can redistribute it and/or modify it
3045
under the same terms as Perl itself.
3046

            
3047
=cut