DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3078 lines | 79.461kb
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 last_sql ...
Yuki Kimoto authored on 2011-07-11
4
our $VERSION = '0.1701';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
236
sub DESTROY { }
237

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

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

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

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

            
289
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
290
    my $self = shift;
291
    my $query = shift;
292
    my $param;
293
    $param = shift if @_ % 2;
294
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
295
    
cleanup
Yuki Kimoto authored on 2011-04-02
296
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
297
    my $p = delete $args{param} || {};
298
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
299
    my $tables = delete $args{table} || [];
300
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
301
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
302
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
303
    my $bind_type = delete $args{bind_type} || delete $args{type};
304
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
305
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
306
    my $type_rule_off_parts = {
307
        1 => delete $args{type_rule1_off},
308
        2 => delete $args{type_rule2_off}
309
    };
cleanup
Yuki Kimoto authored on 2011-06-09
310
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
311
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
312
    
cleanup
Yuki Kimoto authored on 2011-03-09
313
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
314
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
315
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
316
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
317
    }
318
    
cleanup
Yuki Kimoto authored on 2011-04-02
319
    # Create query
updated pod
Yuki Kimoto authored on 2011-06-21
320
    $query = $self->_create_query($query) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
321
    
322
    # Save query
323
    $self->last_sql($query->sql);
324

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

            
464
        return $result;
465
    }
cleanup
Yuki Kimoto authored on 2011-04-02
466
    
467
    # Not select statement
468
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
469
}
470

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

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

            
494
    # Check arguments
495
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
496
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
497
          unless $INSERT_ARGS{$name};
498
    }
499

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
500
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
501
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
502
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
503
        $param = $self->merge_param($id_param, $param);
504
    }
505

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
542
sub include_model {
543
    my ($self, $name_space, $model_infos) = @_;
544
    
cleanup
Yuki Kimoto authored on 2011-04-02
545
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
546
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
547
    
548
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
549
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
550

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

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
742
sub order {
743
    my $self = shift;
744
    return DBIx::Custom::Order->new(@_);
745
}
746

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

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

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

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

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

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

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

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

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

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

            
997
                    $self->{"_$into"}{$table}{$column} = $filter;
998
                }
999
            });
1000
        }
1001

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1107
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1108
}
1109

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1122
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1123
    
updated pod
Yuki Kimoto authored on 2011-06-21
1124
    my ($self, $source) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1125
    
updated pod
Yuki Kimoto authored on 2011-06-21
1126
    # Cache
1127
    my $cache = $self->cache;
1128
    
1129
    # Query
1130
    my $query;
1131
    
1132
    # Get cached query
1133
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1134
        
updated pod
Yuki Kimoto authored on 2011-06-21
1135
        # Get query
1136
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1137
        
updated pod
Yuki Kimoto authored on 2011-06-21
1138
        # Create query
1139
        if ($q) {
1140
            $query = DBIx::Custom::Query->new($q);
1141
            $query->filters($self->filters);
cleanup
Yuki Kimoto authored on 2011-06-13
1142
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1143
    }
1144
    
1145
    # Create query
1146
    unless ($query) {
1147

            
1148
        # Create query
1149
        my $builder = $self->query_builder;
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
1150
        $builder->{_tag_parse} = $self->tag_parse;
updated pod
Yuki Kimoto authored on 2011-06-21
1151
        $query = $builder->build_query($source);
1152

            
1153
        # Remove reserved word quote
1154
        if (my $q = $self->_quote) {
1155
            $_ =~ s/$q//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1156
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1157

            
1158
        # Save query to cache
1159
        $self->cache_method->(
1160
            $self, $source,
1161
            {
1162
                sql     => $query->sql, 
1163
                columns => $query->columns,
1164
                tables  => $query->tables
1165
            }
1166
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1167
    }
1168
    
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1169
    # Save sql
1170
    $self->last_sql($query->sql);
1171
    
updated pod
Yuki Kimoto authored on 2011-06-21
1172
    # Prepare statement handle
1173
    my $sth;
1174
    eval { $sth = $self->dbh->prepare($query->{sql})};
1175
    
1176
    if ($@) {
1177
        $self->_croak($@, qq{. Following SQL is executed.\n}
1178
                        . qq{$query->{sql}\n} . _subname);
1179
    }
1180
    
1181
    # Set statement handle
1182
    $query->sth($sth);
1183
    
1184
    # Set filters
1185
    $query->filters($self->filters);
1186
    
1187
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1188
}
1189

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

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

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

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

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

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

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

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

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

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

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

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

            
1511
# DEPRECATED!
1512
sub create_query {
1513
    warn "create_query is DEPRECATED! use query option of each method";
1514
    shift->_create_query(@_);
1515
}
1516

            
cleanup
Yuki Kimoto authored on 2011-06-13
1517
# DEPRECATED!
1518
sub apply_filter {
1519
    my $self = shift;
1520
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1521
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1522
    return $self->_apply_filter(@_);
1523
}
1524

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1525
# DEPRECATED!
1526
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1527
sub select_at {
1528
    my ($self, %args) = @_;
1529

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1532
    # Arguments
1533
    my $primary_keys = delete $args{primary_key};
1534
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1535
    my $where = delete $args{where};
1536
    my $param = delete $args{param};
1537
    
1538
    # Check arguments
1539
    foreach my $name (keys %args) {
1540
        croak qq{"$name" is wrong option } . _subname
1541
          unless $SELECT_AT_ARGS{$name};
1542
    }
1543
    
1544
    # Table
1545
    croak qq{"table" option must be specified } . _subname
1546
      unless $args{table};
1547
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1548
    
1549
    # Create where parameter
1550
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1551
    
1552
    return $self->select(where => $where_param, %args);
1553
}
1554

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1555
# DEPRECATED!
1556
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1557
sub delete_at {
1558
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1559

            
1560
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1561
    
1562
    # Arguments
1563
    my $primary_keys = delete $args{primary_key};
1564
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1565
    my $where = delete $args{where};
1566
    
1567
    # Check arguments
1568
    foreach my $name (keys %args) {
1569
        croak qq{"$name" is wrong option } . _subname
1570
          unless $DELETE_AT_ARGS{$name};
1571
    }
1572
    
1573
    # Create where parameter
1574
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1575
    
1576
    return $self->delete(where => $where_param, %args);
1577
}
1578

            
cleanup
Yuki Kimoto authored on 2011-06-08
1579
# DEPRECATED!
1580
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1581
sub update_at {
1582
    my $self = shift;
1583

            
1584
    warn "update_at is DEPRECATED! use update and id option instead";
1585
    
1586
    # Arguments
1587
    my $param;
1588
    $param = shift if @_ % 2;
1589
    my %args = @_;
1590
    my $primary_keys = delete $args{primary_key};
1591
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1592
    my $where = delete $args{where};
1593
    my $p = delete $args{param} || {};
1594
    $param  ||= $p;
1595
    
1596
    # Check arguments
1597
    foreach my $name (keys %args) {
1598
        croak qq{"$name" is wrong option } . _subname
1599
          unless $UPDATE_AT_ARGS{$name};
1600
    }
1601
    
1602
    # Create where parameter
1603
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1604
    
1605
    return $self->update(where => $where_param, param => $param, %args);
1606
}
1607

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1608
# DEPRECATED!
1609
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1610
sub insert_at {
1611
    my $self = shift;
1612
    
1613
    warn "insert_at is DEPRECATED! use insert and id option instead";
1614
    
1615
    # Arguments
1616
    my $param;
1617
    $param = shift if @_ % 2;
1618
    my %args = @_;
1619
    my $primary_key = delete $args{primary_key};
1620
    $primary_key = [$primary_key] unless ref $primary_key;
1621
    my $where = delete $args{where};
1622
    my $p = delete $args{param} || {};
1623
    $param  ||= $p;
1624
    
1625
    # Check arguments
1626
    foreach my $name (keys %args) {
1627
        croak qq{"$name" is wrong option } . _subname
1628
          unless $INSERT_AT_ARGS{$name};
1629
    }
1630
    
1631
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1632
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1633
    $param = $self->merge_param($where_param, $param);
1634
    
1635
    return $self->insert(param => $param, %args);
1636
}
1637

            
added warnings
Yuki Kimoto authored on 2011-06-07
1638
# DEPRECATED!
1639
sub register_tag {
1640
    warn "register_tag is DEPRECATED!";
1641
    shift->query_builder->register_tag(@_)
1642
}
1643

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1644
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1645
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1646
has dbi_options => sub { {} };
1647
has filter_check  => 1;
1648
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1649

            
cleanup
Yuki Kimoto authored on 2011-01-25
1650
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1651
sub default_bind_filter {
1652
    my $self = shift;
1653
    
cleanup
Yuki Kimoto authored on 2011-06-13
1654
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1655
    
cleanup
Yuki Kimoto authored on 2011-01-12
1656
    if (@_) {
1657
        my $fname = $_[0];
1658
        
1659
        if (@_ && !$fname) {
1660
            $self->{default_out_filter} = undef;
1661
        }
1662
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1663
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1664
              unless exists $self->filters->{$fname};
1665
        
1666
            $self->{default_out_filter} = $self->filters->{$fname};
1667
        }
1668
        return $self;
1669
    }
1670
    
1671
    return $self->{default_out_filter};
1672
}
1673

            
cleanup
Yuki Kimoto authored on 2011-01-25
1674
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1675
sub default_fetch_filter {
1676
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1677

            
cleanup
Yuki Kimoto authored on 2011-06-13
1678
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1679
    
1680
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1681
        my $fname = $_[0];
1682

            
cleanup
Yuki Kimoto authored on 2011-01-12
1683
        if (@_ && !$fname) {
1684
            $self->{default_in_filter} = undef;
1685
        }
1686
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1687
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1688
              unless exists $self->filters->{$fname};
1689
        
1690
            $self->{default_in_filter} = $self->filters->{$fname};
1691
        }
1692
        
1693
        return $self;
1694
    }
1695
    
many changed
Yuki Kimoto authored on 2011-01-23
1696
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1697
}
1698

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1699
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1700
sub insert_param_tag {
1701
    warn "insert_param_tag is DEPRECATED! " .
1702
         "use insert_param instead!";
1703
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1704
}
1705

            
cleanup
Yuki Kimoto authored on 2011-01-25
1706
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1707
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1708
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1709
    return shift->query_builder->register_tag_processor(@_);
1710
}
1711

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1712
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1713
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1714
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1715
         "use update_param instead";
1716
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1717
}
cleanup
Yuki Kimoto authored on 2011-03-08
1718
# DEPRECATED!
1719
sub _push_relation {
1720
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1721
    
1722
    if (keys %{$relation || {}}) {
1723
        push @$sql, $need_where ? 'where' : 'and';
1724
        foreach my $rcolumn (keys %$relation) {
1725
            my $table1 = (split (/\./, $rcolumn))[0];
1726
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1727
            push @$tables, ($table1, $table2);
1728
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1729
        }
1730
    }
1731
    pop @$sql if $sql->[-1] eq 'and';    
1732
}
1733

            
1734
# DEPRECATED!
1735
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1736
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1737
    
1738
    if (keys %{$relation || {}}) {
1739
        foreach my $rcolumn (keys %$relation) {
1740
            my $table1 = (split (/\./, $rcolumn))[0];
1741
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1742
            my $table1_exists;
1743
            my $table2_exists;
1744
            foreach my $table (@$tables) {
1745
                $table1_exists = 1 if $table eq $table1;
1746
                $table2_exists = 1 if $table eq $table2;
1747
            }
1748
            unshift @$tables, $table1 unless $table1_exists;
1749
            unshift @$tables, $table2 unless $table2_exists;
1750
        }
1751
    }
1752
}
1753

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1756
=head1 NAME
1757

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

            
1760
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1761

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1762
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1763
    
1764
    # Connect
1765
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1766
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1767
        user => 'ken',
1768
        password => '!LFKD%$&',
1769
        dbi_option => {mysql_enable_utf8 => 1}
1770
    );
cleanup
yuki-kimoto authored on 2010-08-05
1771

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1772
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1773
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1774
    
1775
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1776
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1777
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1778
    
1779
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1780
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1781

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

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

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

            
1818
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1819

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

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

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

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

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

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

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

            
1835
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1836

            
1837
=head1 GUIDE
1838

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

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

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

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

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

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

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

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

            
1858
    my $connector = DBIx::Connector->new(
1859
        "dbi:mysql:database=$DATABASE",
1860
        $USER,
1861
        $PASSWORD,
1862
        DBIx::Custom->new->default_dbi_option
1863
    );
1864
    
updated pod
Yuki Kimoto authored on 2011-06-21
1865
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1866

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

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

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

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

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

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

            
1882
=head2 C<default_dbi_option>
1883

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1890
    {
1891
        RaiseError => 1,
1892
        PrintError => 0,
1893
        AutoCommit => 1,
1894
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1895

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

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

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

            
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1903
=head2 C<last_sql> EXPERIMENTAL
1904

            
1905
    my $last_sql = $dbi->last_sql;
1906
    $dbi = $dbi->last_sql($last_sql);
1907

            
1908
Get last successed SQL executed by C<execute> method.
1909

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1917
=head2 C<password>
1918

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
1955
=head2 C<tag_parse>
1956

            
1957
    my $tag_parse = $dbi->tag_parse(0);
1958
    $dbi = $dbi->tag_parse;
1959

            
1960
Enable DEPRECATED tag parsing functionality, default to 1.
1961
If you want to disable tag parsing functionality, set to 0.
1962

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

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

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

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

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

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

            
1978
    print $dbi->available_data_type;
1979

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

            
1983
=head2 C<available_type_name> EXPERIMENTAL
1984

            
1985
    print $dbi->available_type_name;
1986

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

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

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

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

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

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

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

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

            
2004
Create column clause. The follwoing column clause is created.
2005

            
2006
    book.author as "book.author",
2007
    book.title as "book.title"
2008

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2011
    # Separator is double underbar
2012
    $dbi->separator('__');
2013
    
2014
    book.author as "book__author",
2015
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2016

            
cleanup
Yuki Kimoto authored on 2011-06-13
2017
    # Separator is hyphen
2018
    $dbi->separator('-');
2019
    
2020
    book.author as "book-author",
2021
    book.title as "book-title"
2022
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2023
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2024

            
update pod
Yuki Kimoto authored on 2011-03-13
2025
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2026
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2027
        user => 'ken',
2028
        password => '!LFKD%$&',
2029
        dbi_option => {mysql_enable_utf8 => 1}
2030
    );
2031

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2040
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2041
        table => 'book',
2042
        primary_key => 'id',
2043
        join => [
2044
            'inner join company on book.comparny_id = company.id'
2045
        ],
2046
    );
2047

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

            
2051
   $dbi->model('book')->select(...);
2052

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

            
2055
    my $dbh = $dbi->dbh;
2056

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

            
2060
=head2 C<each_column>
2061

            
2062
    $dbi->each_column(
2063
        sub {
2064
            my ($dbi, $table, $column, $column_info) = @_;
2065
            
2066
            my $type = $column_info->{TYPE_NAME};
2067
            
2068
            if ($type eq 'DATE') {
2069
                # ...
2070
            }
2071
        }
2072
    );
2073

            
2074
Iterate all column informations of all table from database.
2075
Argument is callback when one column is found.
2076
Callback receive four arguments, dbi object, table name,
2077
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2078

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

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

            
2086
    my $result = $dbi->execute(
2087
      "select * from book where title = :book.title and author like :book.author",
2088
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2089
    );
2090

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

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

            
2099
    select * from where title = ? and author like ?;
2100

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

            
2103
=over 4
2104

            
2105
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2106
    
2107
    filter => {
2108
        title  => sub { uc $_[0] }
2109
        author => sub { uc $_[0] }
2110
    }
update pod
Yuki Kimoto authored on 2011-03-13
2111

            
updated pod
Yuki Kimoto authored on 2011-06-09
2112
    # Filter name
2113
    filter => {
2114
        title  => 'upper_case',
2115
        author => 'upper_case'
2116
    }
2117
        
2118
    # At once
2119
    filter => [
2120
        [qw/title author/]  => sub { uc $_[0] }
2121
    ]
2122

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

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

            
2130
    query => 1
2131

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

            
2135
    my $sql = $query->sql;
2136
    my $columns = $query->columns;
updated document
Yuki Kimoto authored on 2011-06-09
2137

            
updated pod
Yuki Kimoto authored on 2011-06-09
2138
=item C<table>
2139
    
2140
    table => 'author'
2141

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2149
    # Same
2150
    $dbi->execute(
2151
      "select * from book where title = :book.title and author = :book.author",
2152
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2153

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

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

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

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

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

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

            
2167
    table_alias => {user => 'hiker'}
2168

            
2169
Table alias. Key is real table name, value is alias table name.
2170
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2171
on alias table name.
2172

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

            
2175
    type_rule_off => 1
2176

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

            
2179
=item C<type_rule1_off> EXPERIMENTAL
2180

            
2181
    type_rule1_off => 1
2182

            
2183
Turn C<into1> type rule off.
2184

            
2185
=item C<type_rule2_off> EXPERIMENTAL
2186

            
2187
    type_rule2_off => 1
2188

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2201
=over 4
2202

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

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

            
2207
=item C<filter>
2208

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2213
    id => 4
2214
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2215

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2219
    $dbi->delete(
2220
        parimary_key => ['id1', 'id2'],
2221
        id => [4, 5],
2222
        table => 'book',
2223
    );
update pod
Yuki Kimoto authored on 2011-03-13
2224

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

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

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

            
2231
    prefix => 'some'
2232

            
2233
prefix before table name section.
2234

            
2235
    delete some from book
2236

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2245
Table name.
2246

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

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

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

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

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

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

            
2259
=item C<type_rule_off> EXPERIMENTAL
2260

            
2261
Same as C<execute> method's C<type_rule_off> option.
2262

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

            
2265
    type_rule1_off => 1
2266

            
2267
Same as C<execute> method's C<type_rule1_off> option.
2268

            
2269
=item C<type_rule2_off> EXPERIMENTAL
2270

            
2271
    type_rule2_off => 1
2272

            
2273
Same as C<execute> method's C<type_rule2_off> option.
2274

            
updated pod
Yuki Kimoto authored on 2011-06-08
2275
=back
update pod
Yuki Kimoto authored on 2011-03-13
2276

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2284
=head2 C<insert>
2285

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

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

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

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

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

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

            
2299
=item C<filter>
2300

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

            
2303
=item C<id>
2304

            
updated document
Yuki Kimoto authored on 2011-06-09
2305
    id => 4
2306
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2307

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2311
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2312
        {title => 'Perl', author => 'Ken'}
2313
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2314
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2315
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2316
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2317

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

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

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

            
2327
    prefix => 'or replace'
2328

            
2329
prefix before table name section
2330

            
2331
    insert or replace into book
2332

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

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

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

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

            
2342
Same as C<execute> method's C<query> option.
2343

            
2344
=item C<table>
2345

            
2346
    table => 'book'
2347

            
2348
Table name.
2349

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

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

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

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

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

            
2360
    type_rule1_off => 1
2361

            
2362
Same as C<execute> method's C<type_rule1_off> option.
2363

            
2364
=item C<type_rule2_off> EXPERIMENTAL
2365

            
2366
    type_rule2_off => 1
2367

            
2368
Same as C<execute> method's C<type_rule2_off> option.
2369

            
update pod
Yuki Kimoto authored on 2011-03-13
2370
=back
2371

            
2372
=over 4
2373

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2389
    lib / MyModel.pm
2390
        / MyModel / book.pm
2391
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2392

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

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

            
2397
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2398
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2399
    
2400
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2401

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2406
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2407
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2408
    
2409
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2410

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2413
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2414
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2415
    
2416
    1;
2417
    
updated pod
Yuki Kimoto authored on 2011-06-21
2418
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2419

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

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

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

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

            
2429
    my $map_param = $dbi->map_param(
2430
        {id => 1, authro => 'Ken', price => 1900},
2431
        'id' => 'book.id',
2432
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2433
        'price' => [
2434
            'book.price', {if => sub { length $_[0] }}
2435
        ]
2436
    );
2437

            
2438
Map paramters to other key and value. First argument is original
2439
parameter. this is hash reference. Rest argument is mapping.
2440
By default, Mapping is done if the value length is not zero.
2441

            
2442
=over 4
2443

            
2444
=item Key mapping
2445

            
2446
    'id' => 'book.id'
2447

            
2448
This is only key mapping. Value is same as original one.
2449

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

            
2452
=item Key and value mapping
2453

            
2454
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2455

            
2456
This is key and value mapping. Frist element of array reference
2457
is mapped key name, second element is code reference to map the value.
2458

            
2459
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2460
      if value length is not zero.
2461

            
2462
=item Condition
2463

            
2464
    'price' => ['book.price', {if => 'exists'}]
2465
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2466
    'price' => ['book.price', {if => sub { defined shift }}]
2467

            
2468
If you need condition, you can sepecify it. this is code reference
2469
or 'exists'. By default, condition is the following one.
2470

            
2471
    sub { defined $_[0] && length $_[0] }
2472

            
2473
=back
2474

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

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

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

            
2481
    {key1 => [1, 1], key2 => 2}
2482

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

            
2485
    $dbi->method(
2486
        update_or_insert => sub {
2487
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2488
            
2489
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2490
        },
2491
        find_or_create   => sub {
2492
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2493
            
2494
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2495
        }
2496
    );
2497

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

            
2500
    $dbi->update_or_insert;
2501
    $dbi->find_or_create;
2502

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

            
2505
    my $model = $dbi->model('book');
2506

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

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

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

            
2513
Create column clause for myself. The follwoing column clause is created.
2514

            
2515
    book.author as author,
2516
    book.title as title
2517

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2520
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2521
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2522
        user => 'ken',
2523
        password => '!LFKD%$&',
2524
        dbi_option => {mysql_enable_utf8 => 1}
2525
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2526

            
2527
Create a new L<DBIx::Custom> object.
2528

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

            
2531
    my $not_exists = $dbi->not_exists;
2532

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

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

            
2538
    my $order = $dbi->order;
2539

            
2540
Create a new L<DBIx::Custom::Order> object.
2541

            
cleanup
yuki-kimoto authored on 2010-10-17
2542
=head2 C<register_filter>
2543

            
update pod
Yuki Kimoto authored on 2011-03-13
2544
    $dbi->register_filter(
2545
        # Time::Piece object to database DATE format
2546
        tp_to_date => sub {
2547
            my $tp = shift;
2548
            return $tp->strftime('%Y-%m-%d');
2549
        },
2550
        # database DATE format to Time::Piece object
2551
        date_to_tp => sub {
2552
           my $date = shift;
2553
           return Time::Piece->strptime($date, '%Y-%m-%d');
2554
        }
2555
    );
cleanup
yuki-kimoto authored on 2010-10-17
2556
    
update pod
Yuki Kimoto authored on 2011-03-13
2557
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2558

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

            
2561
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2562
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2563
            date => sub { ... },
2564
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2565
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2566
        into2 => {
2567
            date => sub { ... },
2568
            datetime => sub { ... }
2569
        },
2570
        from1 => {
2571
            # DATE
2572
            9 => sub { ... },
2573
            # DATETIME or TIMESTAMP
2574
            11 => sub { ... },
2575
        }
2576
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2577
            # DATE
2578
            9 => sub { ... },
2579
            # DATETIME or TIMESTAMP
2580
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2581
        }
2582
    );
2583

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2599
=over 4
2600

            
2601
=item 1. column name
2602

            
2603
    issue_date
2604
    issue_datetime
2605

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

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

            
2610
    book.issue_date
2611
    book.issue_datetime
2612

            
2613
=back
2614

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

            
2617
    print $dbi->available_type_name;
2618

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

            
2623
    print $dbi->available_data_type;
2624

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

            
2627
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2628
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2629
            [qw/DATE DATETIME/] => sub { ... },
2630
        ],
2631
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2632

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2635
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2636
        table  => 'book',
2637
        column => ['author', 'title'],
2638
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2639
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2640
    
updated document
Yuki Kimoto authored on 2011-06-09
2641
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2642

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

            
2645
=over 4
2646

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2651
Append statement to last of SQL.
2652
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2653
=item C<column>
2654
    
updated document
Yuki Kimoto authored on 2011-06-09
2655
    column => 'author'
2656
    column => ['author', 'title']
2657

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2666
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2667
        {book => [qw/author title/]},
2668
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2669
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2670

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

            
2673
    book.author as "book.author",
2674
    book.title as "book.title",
2675
    person.name as "person.name",
2676
    person.age as "person.age"
2677

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2678
You can specify array of array reference, first argument is
2679
column name, second argument is alias.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2680

            
updated document
Yuki Kimoto authored on 2011-06-09
2681
    column => [
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2682
        ['date(book.register_datetime)' => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2683
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2684

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2685
Alias is quoted properly and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2686

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

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

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

            
2693
=item C<id>
2694

            
2695
    id => 4
2696
    id => [4, 5]
2697

            
2698
ID corresponding to C<primary_key>.
2699
You can select rows by C<id> and C<primary_key>.
2700

            
2701
    $dbi->select(
2702
        parimary_key => ['id1', 'id2'],
2703
        id => [4, 5],
2704
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2705
    );
2706

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2709
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2710
        where => {id1 => 4, id2 => 5},
2711
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2712
    );
2713
    
updated document
Yuki Kimoto authored on 2011-06-09
2714
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2715

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

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

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

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

            
2728
    prefix => 'SQL_CALC_FOUND_ROWS'
2729

            
2730
Prefix of column cluase
2731

            
2732
    select SQL_CALC_FOUND_ROWS title, author from book;
2733

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

            
2736
    join => [
2737
        'left outer join company on book.company_id = company_id',
2738
        'left outer join location on company.location_id = location.id'
2739
    ]
2740
        
2741
Join clause. If column cluase or where clause contain table name like "company.name",
2742
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2743

            
2744
    $dbi->select(
2745
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2746
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2747
        where => {'company.name' => 'Orange'},
2748
        join => [
2749
            'left outer join company on book.company_id = company.id',
2750
            'left outer join location on company.location_id = location.id'
2751
        ]
2752
    );
2753

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2757
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2758
    from book
2759
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2760
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2761

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2781
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2782

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

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

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

            
2789
    type_rule1_off => 1
2790

            
2791
Same as C<execute> method's C<type_rule1_off> option.
2792

            
2793
=item C<type_rule2_off> EXPERIMENTAL
2794

            
2795
    type_rule2_off => 1
2796

            
2797
Same as C<execute> method's C<type_rule2_off> option.
2798

            
updated document
Yuki Kimoto authored on 2011-06-09
2799
=item C<where>
2800
    
2801
    # Hash refrence
2802
    where => {author => 'Ken', 'title' => 'Perl'}
2803
    
2804
    # DBIx::Custom::Where object
2805
    where => $dbi->where(
2806
        clause => ['and', 'author = :author', 'title like :title'],
2807
        param  => {author => 'Ken', title => '%Perl%'}
2808
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2809
    
2810
    # Array reference 1 (array reference, hash referenc). same as above
2811
    where => [
2812
        ['and', 'author = :author', 'title like :title'],
2813
        {author => 'Ken', title => '%Perl%'}
2814
    ];    
2815
    
2816
    # Array reference 2 (String, hash reference)
2817
    where => [
2818
        'title like :title',
2819
        {title => '%Perl%'}
2820
    ]
2821
    
2822
    # String
2823
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
2824

            
updated document
Yuki Kimoto authored on 2011-06-09
2825
Where clause.
2826
    
improved pod
Yuki Kimoto authored on 2011-04-19
2827
=item C<wrap> EXPERIMENTAL
2828

            
2829
Wrap statement. This is array reference.
2830

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

            
2833
This option is for Oracle and SQL Server paging process.
2834

            
update pod
Yuki Kimoto authored on 2011-03-12
2835
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2836

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2845
=over 4
2846

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2857
    id => 4
2858
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2859

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2863
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2864
        {title => 'Perl', author => 'Ken'}
2865
        parimary_key => ['id1', 'id2'],
2866
        id => [4, 5],
2867
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2868
    );
update pod
Yuki Kimoto authored on 2011-03-13
2869

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2872
    $dbi->update(
2873
        {title => 'Perl', author => 'Ken'}
2874
        where => {id1 => 4, id2 => 5},
2875
        table => 'book'
2876
    );
update pod
Yuki Kimoto authored on 2011-03-13
2877

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

            
2880
    prefix => 'or replace'
2881

            
2882
prefix before table name section
2883

            
2884
    update or replace book
2885

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

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

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

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

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

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

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

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

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

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

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

            
2909
Same as C<execute> method's C<type> option.
2910

            
2911
=item C<type_rule_off> EXPERIMENTAL
2912

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

            
2915
=item C<type_rule1_off> EXPERIMENTAL
2916

            
2917
    type_rule1_off => 1
2918

            
2919
Same as C<execute> method's C<type_rule1_off> option.
2920

            
2921
=item C<type_rule2_off> EXPERIMENTAL
2922

            
2923
    type_rule2_off => 1
2924

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2927
=back
update pod
Yuki Kimoto authored on 2011-03-13
2928

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

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

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

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

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

            
2940
Create update parameter tag.
2941

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

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

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

            
2951
Create a new L<DBIx::Custom::Where> object.
2952

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

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

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

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

            
2962
=head2 C<DBIX_CUSTOM_DEBUG>
2963

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

            
2967
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2968

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

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

            
2973
L<DBIx::Custom>
2974

            
2975
    # Attribute methods
2976
    data_source # Removed at 2017/1/1
2977
    dbi_options # Removed at 2017/1/1
2978
    filter_check # Removed at 2017/1/1
2979
    reserved_word_quote # Removed at 2017/1/1
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
2980
    cache_method # Removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2981
    
2982
    # Methods
2983
    create_query # Removed at 2017/1/1
2984
    apply_filter # Removed at 2017/1/1
2985
    select_at # Removed at 2017/1/1
2986
    delete_at # Removed at 2017/1/1
2987
    update_at # Removed at 2017/1/1
2988
    insert_at # Removed at 2017/1/1
2989
    register_tag # Removed at 2017/1/1
2990
    default_bind_filter # Removed at 2017/1/1
2991
    default_fetch_filter # Removed at 2017/1/1
2992
    insert_param_tag # Removed at 2017/1/1
2993
    register_tag_processor # Removed at 2017/1/1
2994
    update_param_tag # Removed at 2017/1/1
2995
    
2996
    # Options
2997
    select method relation option # Removed at 2017/1/1
2998
    select method param option # Removed at 2017/1/1
2999
    
3000
    # Others
3001
    execute("select * from {= title}"); # execute tag parsing functionality
3002
                                        # Removed at 2017/1/1
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
3003
    Query caching # Removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3004

            
3005
L<DBIx::Custom::Model>
3006

            
3007
    # Attribute method
3008
    filter # Removed at 2017/1/1
3009
    name # Removed at 2017/1/1
3010
    type # Removed at 2017/1/1
3011

            
3012
L<DBIx::Custom::Query>
3013
    
3014
    # Attribute method
3015
    default_filter # Removed at 2017/1/1
3016

            
3017
L<DBIx::Custom::QueryBuilder>
3018
    
3019
    # Attribute method
3020
    tags # Removed at 2017/1/1
3021
    tag_processors # Removed at 2017/1/1
3022
    
3023
    # Method
3024
    register_tag # Removed at 2017/1/1
3025
    register_tag_processor # Removed at 2017/1/1
3026
    
3027
    # Others
3028
    build_query("select * from {= title}"); # tag parsing functionality
3029
                                            # Removed at 2017/1/1
3030

            
3031
L<DBIx::Custom::Result>
3032
    
3033
    # Attribute method
3034
    filter_check # Removed at 2017/1/1
3035
    
3036
    # Methods
3037
    end_filter # Removed at 2017/1/1
3038
    remove_end_filter # Removed at 2017/1/1
3039
    remove_filter # Removed at 2017/1/1
3040
    default_filter # Removed at 2017/1/1
3041

            
3042
L<DBIx::Custom::Tag>
3043

            
3044
    This module is DEPRECATED! # Removed at 2017/1/1
3045

            
3046
=head1 BACKWORD COMPATIBLE POLICY
3047

            
3048
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3049
except for attribute method.
3050
You can check all DEPRECATED functionalities by document.
3051
DEPRECATED functionality is removed after five years,
3052
but if at least one person use the functionality and tell me that thing
3053
I extend one year each time you tell me it.
3054

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

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

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

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

            
3063
C<< <kimoto.yuki at gmail.com> >>
3064

            
3065
L<http://github.com/yuki-kimoto/DBIx-Custom>
3066

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3067
=head1 AUTHOR
3068

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

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

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

            
3075
This program is free software; you can redistribute it and/or modify it
3076
under the same terms as Perl itself.
3077

            
3078
=cut