DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3074 lines | 79.31kb
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') {
817
                croak "Format must be [COLUMN, as => ALIAS] " . _subname
818
                  unless @$column == 3 && $column->[1] eq 'as';
819
                $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
820
            }
cleanup
Yuki Kimoto authored on 2011-04-02
821
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
822
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
823
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
824
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
825
    }
826
    else { push @sql, '*' }
827
    
828
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
829
    push @sql, 'from';
830
    if ($relation) {
831
        my $found = {};
832
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
833
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
834
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
835
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
836
    }
cleanup
Yuki Kimoto authored on 2011-03-30
837
    else {
838
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
839
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
840
    }
841
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
842
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
843
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
844

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

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

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

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

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

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

            
994
                    $self->{"_$into"}{$table}{$column} = $filter;
995
                }
996
            });
997
        }
998

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1104
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1105
}
1106

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1753
=head1 NAME
1754

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

            
1757
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1758

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

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

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

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

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

            
1815
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1816

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

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

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

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

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

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

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

            
1832
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1833

            
1834
=head1 GUIDE
1835

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1879
=head2 C<default_dbi_option>
1880

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

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

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

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

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

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

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

            
1902
    my $last_sql = $dbi->last_sql;
1903
    $dbi = $dbi->last_sql($last_sql);
1904

            
1905
Get last successed SQL executed by C<execute> method.
1906

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1914
=head2 C<password>
1915

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1954
    my $tag_parse = $dbi->tag_parse(0);
1955
    $dbi = $dbi->tag_parse;
1956

            
1957
Enable DEPRECATED tag parsing functionality, default to 1.
1958
If you want to disable tag parsing functionality, set to 0.
1959

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

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

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

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

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

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

            
1975
    print $dbi->available_data_type;
1976

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

            
1980
=head2 C<available_type_name> EXPERIMENTAL
1981

            
1982
    print $dbi->available_type_name;
1983

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

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

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

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

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

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

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

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

            
2001
Create column clause. The follwoing column clause is created.
2002

            
2003
    book.author as "book.author",
2004
    book.title as "book.title"
2005

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

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

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

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

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

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

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

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

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

            
2048
   $dbi->model('book')->select(...);
2049

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

            
2052
    my $dbh = $dbi->dbh;
2053

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

            
2057
=head2 C<each_column>
2058

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

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

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

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

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

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

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

            
2096
    select * from where title = ? and author like ?;
2097

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

            
2100
=over 4
2101

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

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

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

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

            
2127
    query => 1
2128

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

            
2132
    my $sql = $query->sql;
2133
    my $columns = $query->columns;
updated document
Yuki Kimoto authored on 2011-06-09
2134

            
updated pod
Yuki Kimoto authored on 2011-06-09
2135
=item C<table>
2136
    
2137
    table => 'author'
2138

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

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

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

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

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

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

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

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

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

            
2164
    table_alias => {user => 'hiker'}
2165

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

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

            
2172
    type_rule_off => 1
2173

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

            
2176
=item C<type_rule1_off> EXPERIMENTAL
2177

            
2178
    type_rule1_off => 1
2179

            
2180
Turn C<into1> type rule off.
2181

            
2182
=item C<type_rule2_off> EXPERIMENTAL
2183

            
2184
    type_rule2_off => 1
2185

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2198
=over 4
2199

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

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

            
2204
=item C<filter>
2205

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2210
    id => 4
2211
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2212

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

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

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

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

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

            
2228
    prefix => 'some'
2229

            
2230
prefix before table name section.
2231

            
2232
    delete some from book
2233

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2242
Table name.
2243

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

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

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

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

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

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

            
2256
=item C<type_rule_off> EXPERIMENTAL
2257

            
2258
Same as C<execute> method's C<type_rule_off> option.
2259

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

            
2262
    type_rule1_off => 1
2263

            
2264
Same as C<execute> method's C<type_rule1_off> option.
2265

            
2266
=item C<type_rule2_off> EXPERIMENTAL
2267

            
2268
    type_rule2_off => 1
2269

            
2270
Same as C<execute> method's C<type_rule2_off> option.
2271

            
updated pod
Yuki Kimoto authored on 2011-06-08
2272
=back
update pod
Yuki Kimoto authored on 2011-03-13
2273

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2281
=head2 C<insert>
2282

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

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

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

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

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

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

            
2296
=item C<filter>
2297

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

            
2300
=item C<id>
2301

            
updated document
Yuki Kimoto authored on 2011-06-09
2302
    id => 4
2303
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2304

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

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

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

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

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

            
2324
    prefix => 'or replace'
2325

            
2326
prefix before table name section
2327

            
2328
    insert or replace into book
2329

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

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

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

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

            
2339
Same as C<execute> method's C<query> option.
2340

            
2341
=item C<table>
2342

            
2343
    table => 'book'
2344

            
2345
Table name.
2346

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

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

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

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

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

            
2357
    type_rule1_off => 1
2358

            
2359
Same as C<execute> method's C<type_rule1_off> option.
2360

            
2361
=item C<type_rule2_off> EXPERIMENTAL
2362

            
2363
    type_rule2_off => 1
2364

            
2365
Same as C<execute> method's C<type_rule2_off> option.
2366

            
update pod
Yuki Kimoto authored on 2011-03-13
2367
=back
2368

            
2369
=over 4
2370

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2439
=over 4
2440

            
2441
=item Key mapping
2442

            
2443
    'id' => 'book.id'
2444

            
2445
This is only key mapping. Value is same as original one.
2446

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

            
2449
=item Key and value mapping
2450

            
2451
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2452

            
2453
This is key and value mapping. Frist element of array reference
2454
is mapped key name, second element is code reference to map the value.
2455

            
2456
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2457
      if value length is not zero.
2458

            
2459
=item Condition
2460

            
2461
    'price' => ['book.price', {if => 'exists'}]
2462
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2463
    'price' => ['book.price', {if => sub { defined shift }}]
2464

            
2465
If you need condition, you can sepecify it. this is code reference
2466
or 'exists'. By default, condition is the following one.
2467

            
2468
    sub { defined $_[0] && length $_[0] }
2469

            
2470
=back
2471

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

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

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

            
2478
    {key1 => [1, 1], key2 => 2}
2479

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

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

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

            
2497
    $dbi->update_or_insert;
2498
    $dbi->find_or_create;
2499

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

            
2502
    my $model = $dbi->model('book');
2503

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

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

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

            
2510
Create column clause for myself. The follwoing column clause is created.
2511

            
2512
    book.author as author,
2513
    book.title as title
2514

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

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

            
2524
Create a new L<DBIx::Custom> object.
2525

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

            
2528
    my $not_exists = $dbi->not_exists;
2529

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

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

            
2535
    my $order = $dbi->order;
2536

            
2537
Create a new L<DBIx::Custom::Order> object.
2538

            
cleanup
yuki-kimoto authored on 2010-10-17
2539
=head2 C<register_filter>
2540

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2596
=over 4
2597

            
2598
=item 1. column name
2599

            
2600
    issue_date
2601
    issue_datetime
2602

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

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

            
2607
    book.issue_date
2608
    book.issue_datetime
2609

            
2610
=back
2611

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

            
2614
    print $dbi->available_type_name;
2615

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

            
2620
    print $dbi->available_data_type;
2621

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

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

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

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

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

            
2642
=over 4
2643

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

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

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

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

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

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

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

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

            
2670
    book.author as "book.author",
2671
    book.title as "book.title",
2672
    person.name as "person.name",
2673
    person.age as "person.age"
2674

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2677
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2678
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2679
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2680

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

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

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

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

            
2689
=item C<id>
2690

            
2691
    id => 4
2692
    id => [4, 5]
2693

            
2694
ID corresponding to C<primary_key>.
2695
You can select rows by C<id> and C<primary_key>.
2696

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

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

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

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

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

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

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

            
2724
    prefix => 'SQL_CALC_FOUND_ROWS'
2725

            
2726
Prefix of column cluase
2727

            
2728
    select SQL_CALC_FOUND_ROWS title, author from book;
2729

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2753
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2754
    from book
2755
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2756
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2757

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2777
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2778

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

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

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

            
2785
    type_rule1_off => 1
2786

            
2787
Same as C<execute> method's C<type_rule1_off> option.
2788

            
2789
=item C<type_rule2_off> EXPERIMENTAL
2790

            
2791
    type_rule2_off => 1
2792

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2821
Where clause.
2822
    
improved pod
Yuki Kimoto authored on 2011-04-19
2823
=item C<wrap> EXPERIMENTAL
2824

            
2825
Wrap statement. This is array reference.
2826

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

            
2829
This option is for Oracle and SQL Server paging process.
2830

            
update pod
Yuki Kimoto authored on 2011-03-12
2831
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2832

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2841
=over 4
2842

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2849
Same as C<execute> method's C<filter> 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<id>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2852

            
updated document
Yuki Kimoto authored on 2011-06-09
2853
    id => 4
2854
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2855

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

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

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

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

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

            
2876
    prefix => 'or replace'
2877

            
2878
prefix before table name section
2879

            
2880
    update or replace book
2881

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

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

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

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

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

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

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

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

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

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

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

            
2905
Same as C<execute> method's C<type> option.
2906

            
2907
=item C<type_rule_off> EXPERIMENTAL
2908

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

            
2911
=item C<type_rule1_off> EXPERIMENTAL
2912

            
2913
    type_rule1_off => 1
2914

            
2915
Same as C<execute> method's C<type_rule1_off> option.
2916

            
2917
=item C<type_rule2_off> EXPERIMENTAL
2918

            
2919
    type_rule2_off => 1
2920

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2923
=back
update pod
Yuki Kimoto authored on 2011-03-13
2924

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

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

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

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

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

            
2936
Create update parameter tag.
2937

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

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

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

            
2947
Create a new L<DBIx::Custom::Where> object.
2948

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

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

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

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

            
2958
=head2 C<DBIX_CUSTOM_DEBUG>
2959

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

            
2963
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2964

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

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

            
2969
L<DBIx::Custom>
2970

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

            
3001
L<DBIx::Custom::Model>
3002

            
3003
    # Attribute method
3004
    filter # Removed at 2017/1/1
3005
    name # Removed at 2017/1/1
3006
    type # Removed at 2017/1/1
3007

            
3008
L<DBIx::Custom::Query>
3009
    
3010
    # Attribute method
3011
    default_filter # Removed at 2017/1/1
3012

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

            
3027
L<DBIx::Custom::Result>
3028
    
3029
    # Attribute method
3030
    filter_check # Removed at 2017/1/1
3031
    
3032
    # Methods
3033
    end_filter # Removed at 2017/1/1
3034
    remove_end_filter # Removed at 2017/1/1
3035
    remove_filter # Removed at 2017/1/1
3036
    default_filter # Removed at 2017/1/1
3037

            
3038
L<DBIx::Custom::Tag>
3039

            
3040
    This module is DEPRECATED! # Removed at 2017/1/1
3041

            
3042
=head1 BACKWORD COMPATIBLE POLICY
3043

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

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

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

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

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

            
3059
C<< <kimoto.yuki at gmail.com> >>
3060

            
3061
L<http://github.com/yuki-kimoto/DBIx-Custom>
3062

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3063
=head1 AUTHOR
3064

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

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

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

            
3071
This program is free software; you can redistribute it and/or modify it
3072
under the same terms as Perl itself.
3073

            
3074
=cut