DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2958 lines | 76.26kb
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;
cleanup
Yuki Kimoto authored on 2011-04-25
15
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
16
use Encode qw/encode encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
17

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
982
                    $self->{"_$into"}{$table}{$column} = $filter;
983
                }
984
            });
985
        }
986

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

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

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

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

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

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

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

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

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

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

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

            
1133
        # Create query
1134
        my $builder = $self->query_builder;
1135
        $query = $builder->build_query($source);
1136

            
1137
        # Remove reserved word quote
1138
        if (my $q = $self->_quote) {
1139
            $_ =~ s/$q//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1140
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1141

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

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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1349
sub _quote {
1350
    my $self = shift;
1351
    
1352
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1353
         : defined $self->quote ? $self->quote
1354
         : '';
1355
}
1356

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1423
# DEPRECATED!
1424
sub _apply_filter {
1425
    my ($self, $table, @cinfos) = @_;
1426

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

            
1493
# DEPRECATED!
1494
sub create_query {
1495
    warn "create_query is DEPRECATED! use query option of each method";
1496
    shift->_create_query(@_);
1497
}
1498

            
cleanup
Yuki Kimoto authored on 2011-06-13
1499
# DEPRECATED!
1500
sub apply_filter {
1501
    my $self = shift;
1502
    
1503
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1504
         "use type_rule method and DBIx::Custom::Result filter method, " .
1505
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1506
    
1507
    return $self->_apply_filter(@_);
1508
}
1509

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1741
=head1 NAME
1742

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

            
1745
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1746

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

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

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

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

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

            
1803
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1804

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

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

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

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

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

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

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

            
1820
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1821

            
1822
=head1 GUIDE
1823

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1867
=head2 C<default_dbi_option>
1868

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1895
=head2 C<password>
1896

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1948
    print $dbi->available_data_type;
1949

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

            
1953
=head2 C<available_type_name> EXPERIMENTAL
1954

            
1955
    print $dbi->available_type_name;
1956

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1966
    title = :title, author = :author
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
This is equal to C<update_param> exept that set is not added.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1969

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

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

            
1974
Create column clause. The follwoing column clause is created.
1975

            
1976
    book.author as "book.author",
1977
    book.title as "book.title"
1978

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

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

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

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

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

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

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

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

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

            
2021
   $dbi->model('book')->select(...);
2022

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

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

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

            
2030
=head2 C<each_column>
2031

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

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

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

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

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

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

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

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

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

            
2073
=over 4
2074

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

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

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

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

            
2100
    query => 1
2101

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

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

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

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

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

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

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

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

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

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

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

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

            
2137
    table_alias => {user => 'hiker'}
2138

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

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

            
2145
    type_rule_off => 1
2146

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

            
2149
=item C<type_rule1_off> EXPERIMENTAL
2150

            
2151
    type_rule1_off => 1
2152

            
2153
Turn C<into1> type rule off.
2154

            
2155
=item C<type_rule2_off> EXPERIMENTAL
2156

            
2157
    type_rule2_off => 1
2158

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2171
=over 4
2172

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

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

            
2177
=item C<filter>
2178

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

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

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

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

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

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

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

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

            
2201
    prefix => 'some'
2202

            
2203
prefix before table name section.
2204

            
2205
    delete some from book
2206

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2215
Table name.
2216

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

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

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

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

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

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

            
2229
=item C<type_rule_off> EXPERIMENTAL
2230

            
2231
Same as C<execute> method's C<type_rule_off> option.
2232

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

            
2235
    type_rule1_off => 1
2236

            
2237
Same as C<execute> method's C<type_rule1_off> option.
2238

            
2239
=item C<type_rule2_off> EXPERIMENTAL
2240

            
2241
    type_rule2_off => 1
2242

            
2243
Same as C<execute> method's C<type_rule2_off> option.
2244

            
updated pod
Yuki Kimoto authored on 2011-06-08
2245
=back
update pod
Yuki Kimoto authored on 2011-03-13
2246

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2254
=head2 C<insert>
2255

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

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

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

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

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

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

            
2269
=item C<filter>
2270

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

            
2273
=item C<id>
2274

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

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

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

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

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

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

            
2297
    prefix => 'or replace'
2298

            
2299
prefix before table name section
2300

            
2301
    insert or replace into book
2302

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

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

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

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

            
2312
Same as C<execute> method's C<query> option.
2313

            
2314
=item C<table>
2315

            
2316
    table => 'book'
2317

            
2318
Table name.
2319

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

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

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

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

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

            
2330
    type_rule1_off => 1
2331

            
2332
Same as C<execute> method's C<type_rule1_off> option.
2333

            
2334
=item C<type_rule2_off> EXPERIMENTAL
2335

            
2336
    type_rule2_off => 1
2337

            
2338
Same as C<execute> method's C<type_rule2_off> option.
2339

            
update pod
Yuki Kimoto authored on 2011-03-13
2340
=back
2341

            
2342
=over 4
2343

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2346
    my $insert_param = $dbi->insert_param({title => 'a', age => 2});
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
Create insert parameters.
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
    (title, author) values (title = :title, age = :age);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2351

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2412
=over 4
2413

            
2414
=item Key mapping
2415

            
2416
    'id' => 'book.id'
2417

            
2418
This is only key mapping. Value is same as original one.
2419

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

            
2422
=item Key and value mapping
2423

            
2424
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2425

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

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

            
2432
=item Condition
2433

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

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

            
2441
    sub { defined $_[0] && length $_[0] }
2442

            
2443
=back
2444

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

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

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

            
2451
    {key1 => [1, 1], key2 => 2}
2452

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

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

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

            
2470
    $dbi->update_or_insert;
2471
    $dbi->find_or_create;
2472

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

            
2475
    my $model = $dbi->model('book');
2476

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

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

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

            
2483
Create column clause for myself. The follwoing column clause is created.
2484

            
2485
    book.author as author,
2486
    book.title as title
2487

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

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

            
2497
Create a new L<DBIx::Custom> object.
2498

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

            
2501
    my $not_exists = $dbi->not_exists;
2502

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2506
=head2 C<register_filter>
2507

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2563
=over 4
2564

            
2565
=item 1. column name
2566

            
2567
    issue_date
2568
    issue_datetime
2569

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

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

            
2574
    book.issue_date
2575
    book.issue_datetime
2576

            
2577
=back
2578

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

            
2581
    print $dbi->available_type_name;
2582

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

            
2587
    print $dbi->available_data_type;
2588

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

            
2591
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2592
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2593
            [qw/DATE DATETIME/] => sub { ... },
2594
        ],
2595
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2596

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2599
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2600
        table  => 'book',
2601
        column => ['author', 'title'],
2602
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2603
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2604
    
updated document
Yuki Kimoto authored on 2011-06-09
2605
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2606

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

            
2609
=over 4
2610

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2615
Append statement to last of SQL.
2616
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2617
=item C<column>
2618
    
updated document
Yuki Kimoto authored on 2011-06-09
2619
    column => 'author'
2620
    column => ['author', 'title']
2621

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2630
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2631
        {book => [qw/author title/]},
2632
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2633
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2634

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

            
2637
    book.author as "book.author",
2638
    book.title as "book.title",
2639
    person.name as "person.name",
2640
    person.age as "person.age"
2641

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2644
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2645
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2646
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2647

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

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

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

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

            
2656
=item C<id>
2657

            
2658
    id => 4
2659
    id => [4, 5]
2660

            
2661
ID corresponding to C<primary_key>.
2662
You can select rows by C<id> and C<primary_key>.
2663

            
2664
    $dbi->select(
2665
        parimary_key => ['id1', 'id2'],
2666
        id => [4, 5],
2667
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2668
    );
2669

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2672
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2673
        where => {id1 => 4, id2 => 5},
2674
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2675
    );
2676
    
updated document
Yuki Kimoto authored on 2011-06-09
2677
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2678

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

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

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

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

            
2691
    prefix => 'SQL_CALC_FOUND_ROWS'
2692

            
2693
Prefix of column cluase
2694

            
2695
    select SQL_CALC_FOUND_ROWS title, author from book;
2696

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

            
2699
    join => [
2700
        'left outer join company on book.company_id = company_id',
2701
        'left outer join location on company.location_id = location.id'
2702
    ]
2703
        
2704
Join clause. If column cluase or where clause contain table name like "company.name",
2705
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2706

            
2707
    $dbi->select(
2708
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2709
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2710
        where => {'company.name' => 'Orange'},
2711
        join => [
2712
            'left outer join company on book.company_id = company.id',
2713
            'left outer join location on company.location_id = location.id'
2714
        ]
2715
    );
2716

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2720
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2721
    from book
2722
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2723
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2724

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2744
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2745

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

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

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

            
2752
    type_rule1_off => 1
2753

            
2754
Same as C<execute> method's C<type_rule1_off> option.
2755

            
2756
=item C<type_rule2_off> EXPERIMENTAL
2757

            
2758
    type_rule2_off => 1
2759

            
2760
Same as C<execute> method's C<type_rule2_off> option.
2761

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2788
Where clause.
2789
    
improved pod
Yuki Kimoto authored on 2011-04-19
2790
=item C<wrap> EXPERIMENTAL
2791

            
2792
Wrap statement. This is array reference.
2793

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

            
2796
This option is for Oracle and SQL Server paging process.
2797

            
update pod
Yuki Kimoto authored on 2011-03-12
2798
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2799

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2808
=over 4
2809

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2820
    id => 4
2821
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2822

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2826
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2827
        {title => 'Perl', author => 'Ken'}
2828
        parimary_key => ['id1', 'id2'],
2829
        id => [4, 5],
2830
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2831
    );
update pod
Yuki Kimoto authored on 2011-03-13
2832

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2835
    $dbi->update(
2836
        {title => 'Perl', author => 'Ken'}
2837
        where => {id1 => 4, id2 => 5},
2838
        table => 'book'
2839
    );
update pod
Yuki Kimoto authored on 2011-03-13
2840

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

            
2843
    prefix => 'or replace'
2844

            
2845
prefix before table name section
2846

            
2847
    update or replace book
2848

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

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

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

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

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

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

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

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

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

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

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

            
2872
Same as C<execute> method's C<type> option.
2873

            
2874
=item C<type_rule_off> EXPERIMENTAL
2875

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

            
2878
=item C<type_rule1_off> EXPERIMENTAL
2879

            
2880
    type_rule1_off => 1
2881

            
2882
Same as C<execute> method's C<type_rule1_off> option.
2883

            
2884
=item C<type_rule2_off> EXPERIMENTAL
2885

            
2886
    type_rule2_off => 1
2887

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2890
=back
update pod
Yuki Kimoto authored on 2011-03-13
2891

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

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

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

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

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

            
2903
Create update parameter tag.
2904

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

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

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

            
2914
Create a new L<DBIx::Custom::Where> object.
2915

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

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

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

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

            
2925
=head2 C<DBIX_CUSTOM_DEBUG>
2926

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

            
2930
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2931

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

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

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

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

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

            
2943
C<< <kimoto.yuki at gmail.com> >>
2944

            
2945
L<http://github.com/yuki-kimoto/DBIx-Custom>
2946

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2947
=head1 AUTHOR
2948

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

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

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

            
2955
This program is free software; you can redistribute it and/or modify it
2956
under the same terms as Perl itself.
2957

            
2958
=cut