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

            
cleanup
Yuki Kimoto authored on 2011-08-13
4
our $VERSION = '0.1714';
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/;
cleanup
Yuki Kimoto authored on 2011-08-13
18
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
19

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

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

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
67
sub available_datatype {
test cleanup
Yuki Kimoto authored on 2011-08-10
68
    my $self = shift;
69
    
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
70
    my $data_types = '';
71
    foreach my $i (-1000 .. 1000) {
72
         my $type_info = $self->dbh->type_info($i);
73
         my $data_type = $type_info->{DATA_TYPE};
74
         my $type_name = $type_info->{TYPE_NAME};
75
         $data_types .= "$data_type ($type_name)\n"
76
           if defined $data_type;
77
    }
78
    return "Data Type maybe equal to Type Name" unless $data_types;
79
    $data_types = "Data Type (Type name)\n" . $data_types;
80
    return $data_types;
81
}
82

            
83
sub available_typename {
84
    my $self = shift;
85
    
86
    # Type Names
87
    my $type_names = {};
88
    $self->each_column(sub {
89
        my ($self, $table, $column, $column_info) = @_;
90
        $type_names->{$column_info->{TYPE_NAME}} = 1
91
          if $column_info->{TYPE_NAME};
92
    });
93
    my @output = sort keys %$type_names;
94
    unshift @output, "Type Name";
95
    return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
96
}
97

            
added helper method
yuki-kimoto authored on 2010-10-17
98
our $AUTOLOAD;
99
sub AUTOLOAD {
100
    my $self = shift;
101

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
105
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
106
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
107
    if (my $method = $self->{_methods}->{$mname}) {
108
        return $self->$method(@_)
109
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
110
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
111
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
112
    }
113
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
114
        croak qq{Can't locate object method "$mname" via "$package" }
115
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
116
    }
added helper method
yuki-kimoto authored on 2010-10-17
117
}
118

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
119
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
120
    my ($self, $param) = @_;
121
    
122
    # Create set tag
123
    my @params;
124
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
125
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
        croak qq{"$column" is not safety column name } . _subname
127
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
128
        my $column_quote = $self->_q($column);
129
        $column_quote =~ s/\./$self->_q(".")/e;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
130
        push @params, ref $param->{$column} eq 'SCALAR'
131
          ? "$column_quote = " . ${$param->{$column}}
132
          : "$column_quote = :$column";
133

            
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
134
    }
135
    my $tag = join(', ', @params);
136
    
137
    return $tag;
138
}
139

            
cleanup
Yuki Kimoto authored on 2011-03-21
140
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
141
    my $self = shift;
142
    my $option = pop if ref $_[-1] eq 'HASH';
143
    my $real_table = shift;
144
    my $columns = shift;
145
    my $table = $option->{alias} || $real_table;
146
    
147
    # Columns
148
    unless ($columns) {
149
        $columns ||= $self->model($real_table)->columns;
150
    }
added helper method
yuki-kimoto authored on 2010-10-17
151
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
152
    # Separator
153
    my $separator = $self->separator;
154
    
cleanup
Yuki Kimoto authored on 2011-04-02
155
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
156
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
157
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
158
    push @column, $self->_q($table) . "." . $self->_q($_) .
159
      " as " . $self->_q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
160
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
161
    
162
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
163
}
164

            
packaging one directory
yuki-kimoto authored on 2009-11-16
165
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
166
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
167
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
168
    # Connect
169
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
170
    
packaging one directory
yuki-kimoto authored on 2009-11-16
171
    return $self;
172
}
173

            
update pod
Yuki Kimoto authored on 2011-03-13
174
sub dbh {
175
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
176
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
177
    # Set
178
    if (@_) {
179
        $self->{dbh} = $_[0];
180
        
181
        return $self;
182
    }
183
    
184
    # Get
185
    else {
186
        # From Connction manager
187
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
188
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
189
              unless ref $connector && $connector->can('dbh');
190
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
191
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
192
        }
193
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
194
        # Connect
195
        $self->{dbh} ||= $self->_connect;
196
        
197
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
198
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
199
            my $driver = $self->{dbh}->{Driver}->{Name};
200
            my $quote = $driver eq 'mysql' ? '`' : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
201
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
202
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
203
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
204
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
205
    }
206
}
207

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

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
211
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
212
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
213
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
214
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
215
    my $where            = delete $args{where} || {};
216
    my $append           = delete $args{append};
217
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
218
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
219
    my $id = delete $args{id};
220
    my $primary_key = delete $args{primary_key};
221
    croak "update method primary_key option " .
222
          "must be specified when id is specified " . _subname
223
      if defined $id && !defined $primary_key;
224
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
225
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
226
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
227
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
228
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
229
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
230
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
231
        $where_clause = "where " . $where->[0];
232
        $where_param = $where->[1];
233
    }
234
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
235
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
236
        $where_param = keys %$where_param
237
                     ? $self->merge_param($where_param, $where->param)
238
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
239
        
240
        # String where
241
        $where_clause = $where->to_string;
242
    }
243
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
244
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
245
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
246

            
cleanup
Yuki Kimoto authored on 2011-04-02
247
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
248
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
249
    push @sql, "delete";
250
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
251
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
252
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
253
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
254
    
255
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
256
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
257
}
258

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

            
cleanup
Yuki Kimoto authored on 2011-08-13
261
sub DESTROY { }
added helper method
yuki-kimoto authored on 2010-10-17
262

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
263
sub create_model {
264
    my $self = shift;
265
    
cleanup
Yuki Kimoto authored on 2011-04-02
266
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
267
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
268
    $args->{dbi} = $self;
269
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
270
    my $model_name  = delete $args->{name};
271
    my $model_table = delete $args->{table};
272
    $model_name ||= $model_table;
273
    
cleanup
Yuki Kimoto authored on 2011-04-02
274
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
275
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
276
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
277
    $model->name($model_name) unless $model->name;
278
    $model->table($model_table) unless $model->table;
279
    
micro optimization
Yuki Kimoto authored on 2011-07-30
280
    # Apply filter(DEPRECATED logic)
281
    if ($model->{filter}) {
282
        my $filter = ref $model->filter eq 'HASH'
283
                   ? [%{$model->filter}]
284
                   : $model->filter;
285
        $filter ||= [];
286
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
287
          if @$filter;
288
        $self->_apply_filter($model->table, @$filter);
289
    }
290
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
291
    # Set model
292
    $self->model($model->name, $model);
293
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
294
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
295
}
296

            
297
sub each_column {
298
    my ($self, $cb) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
299

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
300
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
301
    
added SQL Server test
Yuki Kimoto authored on 2011-08-14
302
    my %tables;
303
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
304
    # Iterate all tables
305
    my $sth_tables = $self->dbh->table_info;
306
    while (my $table_info = $sth_tables->fetchrow_hashref) {
307
        # Table
308
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
309
        next if defined $re && $table =~ /$re/;
added SQL Server test
Yuki Kimoto authored on 2011-08-14
310
        $tables{$table}++;
311
    }
312

            
313
    # Iterate all tables
314
    my @tables = sort keys %tables;
315
    for (my $i = 0; $i < @tables; $i++) {
316
        my $table = $tables[$i];
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
317
        
318
        # Iterate all columns
319
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
320
        while (my $column_info = $sth_columns->fetchrow_hashref) {
321
            my $column = $column_info->{COLUMN_NAME};
322
            $self->$cb($table, $column, $column_info);
323
        }
324
    }
325
}
326

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
327
sub each_table {
328
    my ($self, $cb) = @_;
329
    
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
330
    my $re = $self->exclude_table;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
331
    
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
332
    # Iterate all tables
333
    my $sth_tables = $self->dbh->table_info;
334
    while (my $table_info = $sth_tables->fetchrow_hashref) {
335
        
336
        # Table
337
        my $table = $table_info->{TABLE_NAME};
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
338
        next if defined $re && $table =~ /$re/;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
339
        $self->$cb($table, $table_info);
340
    }
341
}
342

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
343
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
344
  allow_update_all bind_type column filter id join param prefix primary_key
345
  query relation table table_alias type type_rule_off type_rule1_off
346
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
347

            
348
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
349
    my $self = shift;
350
    my $query = shift;
351
    my $param;
352
    $param = shift if @_ % 2;
353
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
354
    
cleanup
Yuki Kimoto authored on 2011-04-02
355
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
356
    my $p = delete $args{param} || {};
357
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
358
    my $tables = delete $args{table} || [];
359
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
360
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
361
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
362
    my $bind_type = delete $args{bind_type} || delete $args{type};
363
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
364
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
365
    my $type_rule_off_parts = {
366
        1 => delete $args{type_rule1_off},
367
        2 => delete $args{type_rule2_off}
368
    };
cleanup
Yuki Kimoto authored on 2011-06-09
369
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
370
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
371
    
cleanup
Yuki Kimoto authored on 2011-03-09
372
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
373
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
374
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
375
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
376
    }
377
    
cleanup
Yuki Kimoto authored on 2011-04-02
378
    # Create query
updated pod
Yuki Kimoto authored on 2011-06-21
379
    $query = $self->_create_query($query) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
380
    
381
    # Save query
382
    $self->last_sql($query->sql);
383

            
cleanup
Yuki Kimoto authored on 2011-06-09
384
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
385
    
386
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
387
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
388
    
cleanup
Yuki Kimoto authored on 2011-04-02
389
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
390
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
391
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
392
    
micro optimization
Yuki Kimoto authored on 2011-07-30
393
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
394
    $tables = $self->_remove_duplicate_table($tables, $main_table)
395
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
396
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
397
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
398
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
399
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
400
        foreach my $i (1, 2) {
401
            unless ($type_rule_off_parts->{$i}) {
402
                $type_filters->{$i} = {};
403
                foreach my $alias (keys %$table_alias) {
404
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
405
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
406
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
407
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
408
                    }
409
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
410
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
411
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
412
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
413
        }
414
    }
cleanup
Yuki Kimoto authored on 2011-04-02
415
    
micro optimization
Yuki Kimoto authored on 2011-07-30
416
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
417
    if ($self->{filter}{on}) {
418
        my $applied_filter = {};
419
        foreach my $table (@$tables) {
420
            $applied_filter = {
421
                %$applied_filter,
422
                %{$self->{filter}{out}->{$table} || {}}
423
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
424
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
425
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
426
    }
427
    
cleanup
Yuki Kimoto authored on 2011-04-02
428
    # Replace filter name to code
429
    foreach my $column (keys %$filter) {
430
        my $name = $filter->{$column};
431
        if (!defined $name) {
432
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
433
        }
cleanup
Yuki Kimoto authored on 2011-04-02
434
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
435
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
436
            unless exists $self->filters->{$name};
437
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
438
        }
439
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
440
    
cleanup
Yuki Kimoto authored on 2011-04-02
441
    # Create bind values
442
    my $bind = $self->_create_bind_values(
443
        $param,
444
        $query->columns,
445
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
446
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
447
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
448
    );
cleanup
yuki-kimoto authored on 2010-10-17
449
    
450
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
451
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
452
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
453
    eval {
454
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
455
            my $bind_type = $bind->[$i]->{bind_type};
456
            $sth->bind_param(
457
                $i + 1,
458
                $bind->[$i]->{value},
459
                $bind_type ? $bind_type : ()
460
            );
cleanup
Yuki Kimoto authored on 2011-03-21
461
        }
462
        $affected = $sth->execute;
463
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
464
    
micro optimization
Yuki Kimoto authored on 2011-07-30
465
    $self->_croak($@, qq{. Following SQL is executed.\n}
466
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
467
    
improved debug message
Yuki Kimoto authored on 2011-05-23
468
    # DEBUG message
469
    if (DEBUG) {
470
        print STDERR "SQL:\n" . $query->sql . "\n";
471
        my @output;
472
        foreach my $b (@$bind) {
473
            my $value = $b->{value};
474
            $value = 'undef' unless defined $value;
475
            $value = encode(DEBUG_ENCODING(), $value)
476
              if utf8::is_utf8($value);
477
            push @output, $value;
478
        }
479
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
480
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
481
    
cleanup
Yuki Kimoto authored on 2011-04-02
482
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
483
    if ($sth->{NUM_OF_FIELDS}) {
484
        
micro optimization
Yuki Kimoto authored on 2011-07-30
485
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
486
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
487
        if ($self->{filter}{on}) {
488
            $filter->{in}  = {};
489
            $filter->{end} = {};
490
            push @$tables, $main_table if $main_table;
491
            foreach my $table (@$tables) {
492
                foreach my $way (qw/in end/) {
493
                    $filter->{$way} = {
494
                        %{$filter->{$way}},
495
                        %{$self->{filter}{$way}{$table} || {}}
496
                    };
497
                }
cleanup
Yuki Kimoto authored on 2011-04-02
498
            }
cleanup
Yuki Kimoto authored on 2011-01-12
499
        }
500
        
501
        # Result
502
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
503
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
504
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
505
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
506
            filter => $filter->{in} || {},
507
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
508
            type_rule => {
509
                from1 => $self->type_rule->{from1},
510
                from2 => $self->type_rule->{from2}
511
            },
cleanup
yuki-kimoto authored on 2010-10-17
512
        );
513

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

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
542
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
543
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
544
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
545
        $param = $self->merge_param($id_param, $param);
546
    }
547

            
cleanup
Yuki Kimoto authored on 2011-04-02
548
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
549
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
550
    push @sql, "insert";
551
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
552
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
553
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
554
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
555
    
556
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
557
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
558
}
559

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
560
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
561
    my ($self, $param) = @_;
562
    
cleanup
Yuki Kimoto authored on 2011-04-02
563
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
564
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
565
    my @columns;
566
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
567
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
568
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
569
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
570
        my $column_quote = $self->_q($column);
571
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
572
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
573
        push @placeholders, ref $param->{$column} eq 'SCALAR'
574
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
575
    }
576
    
cleanup
Yuki Kimoto authored on 2011-04-02
577
    return '(' . join(', ', @columns) . ') ' . 'values ' .
578
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
579
}
580

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
581
sub include_model {
582
    my ($self, $name_space, $model_infos) = @_;
583
    
cleanup
Yuki Kimoto authored on 2011-04-02
584
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
585
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
586
    
587
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
588
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
589

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
646
sub map_param {
647
    my $self = shift;
648
    my $param = shift;
649
    my %map = @_;
650
    
651
    # Mapping
652
    my $map_param = {};
653
    foreach my $key (keys %map) {
654
        my $value_cb;
655
        my $condition;
656
        my $map_key;
657
        
658
        # Get mapping information
659
        if (ref $map{$key} eq 'ARRAY') {
660
            foreach my $some (@{$map{$key}}) {
661
                $map_key = $some unless ref $some;
662
                $condition = $some->{if} if ref $some eq 'HASH';
663
                $value_cb = $some if ref $some eq 'CODE';
664
            }
665
        }
666
        else {
667
            $map_key = $map{$key};
668
        }
669
        $value_cb ||= sub { $_[0] };
670
        $condition ||= sub { defined $_[0] && length $_[0] };
671

            
672
        # Map parameter
673
        my $value;
674
        if (ref $condition eq 'CODE') {
675
            $map_param->{$map_key} = $value_cb->($param->{$key})
676
              if $condition->($param->{$key});
677
        }
678
        elsif ($condition eq 'exists') {
679
            $map_param->{$map_key} = $value_cb->($param->{$key})
680
              if exists $param->{$key};
681
        }
682
        else { croak qq/Condition must be code reference or "exists" / . _subname }
683
    }
684
    
685
    return $map_param;
686
}
687

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
688
sub merge_param {
689
    my ($self, @params) = @_;
690
    
cleanup
Yuki Kimoto authored on 2011-04-02
691
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
692
    my $merge = {};
693
    foreach my $param (@params) {
694
        foreach my $column (keys %$param) {
695
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
696
            
697
            if (exists $merge->{$column}) {
698
                $merge->{$column} = [$merge->{$column}]
699
                  unless ref $merge->{$column} eq 'ARRAY';
700
                push @{$merge->{$column}},
701
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
702
            }
703
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
704
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
705
            }
706
        }
707
    }
708
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
709
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
710
}
711

            
cleanup
Yuki Kimoto authored on 2011-03-21
712
sub method {
713
    my $self = shift;
714
    
cleanup
Yuki Kimoto authored on 2011-04-02
715
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
716
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
717
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
718
    
719
    return $self;
720
}
721

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
722
sub model {
723
    my ($self, $name, $model) = @_;
724
    
cleanup
Yuki Kimoto authored on 2011-04-02
725
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
726
    if ($model) {
727
        $self->models->{$name} = $model;
728
        return $self;
729
    }
730
    
731
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
732
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
733
      unless $self->models->{$name};
734
    
cleanup
Yuki Kimoto authored on 2011-04-02
735
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
736
    return $self->models->{$name};
737
}
738

            
cleanup
Yuki Kimoto authored on 2011-03-21
739
sub mycolumn {
740
    my ($self, $table, $columns) = @_;
741
    
cleanup
Yuki Kimoto authored on 2011-04-02
742
    # Create column clause
743
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
744
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
745
    push @column, $self->_q($table) . "." . $self->_q($_) .
746
      " as " . $self->_q($_)
747
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
748
    
749
    return join (', ', @column);
750
}
751

            
added dbi_options attribute
kimoto authored on 2010-12-20
752
sub new {
753
    my $self = shift->SUPER::new(@_);
754
    
cleanup
Yuki Kimoto authored on 2011-04-02
755
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
756
    my @attrs = keys %$self;
757
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
758
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
759
          unless $self->can($attr);
760
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
761

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
762
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
763
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
764
        '?'     => \&DBIx::Custom::Tag::placeholder,
765
        '='     => \&DBIx::Custom::Tag::equal,
766
        '<>'    => \&DBIx::Custom::Tag::not_equal,
767
        '>'     => \&DBIx::Custom::Tag::greater_than,
768
        '<'     => \&DBIx::Custom::Tag::lower_than,
769
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
770
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
771
        'like'  => \&DBIx::Custom::Tag::like,
772
        'in'    => \&DBIx::Custom::Tag::in,
773
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
774
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
775
    };
776
    
777
    return $self;
778
}
779

            
780
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
781
sub not_exists { $not_exists }
782

            
783
sub order {
784
    my $self = shift;
785
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
786
}
787

            
cleanup
yuki-kimoto authored on 2010-10-17
788
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
789
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
790
    
791
    # Register filter
792
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
793
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
794
    
cleanup
Yuki Kimoto authored on 2011-04-02
795
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
796
}
packaging one directory
yuki-kimoto authored on 2009-11-16
797

            
798
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
799
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
800

            
refactoring select
yuki-kimoto authored on 2010-04-28
801
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
802
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
803
    my $tables = ref $table eq 'ARRAY' ? $table
804
               : defined $table ? [$table]
805
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
806
    my $columns   = delete $args{column};
807
    my $where     = delete $args{where} || {};
808
    my $append    = delete $args{append};
809
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
810
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
811
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
812
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
813
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
814
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
815
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
816
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
817
      if keys %$param;
818
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
819
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
820
    my $id = delete $args{id};
821
    my $primary_key = delete $args{primary_key};
822
    croak "update method primary_key option " .
823
          "must be specified when id is specified " . _subname
824
      if defined $id && !defined $primary_key;
825
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
826
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
827
    
cleanup
Yuki Kimoto authored on 2011-03-09
828
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
829
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
830
    
cleanup
Yuki Kimoto authored on 2011-04-02
831
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
832
    my @sql;
833
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
834
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
835
    # Prefix
836
    push @sql, $prefix if defined $prefix;
837
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
838
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
839
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
840
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
841
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
842
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
843
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
844
            }
845
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
846
                if (@$column == 3 && $column->[1] eq 'as') {
847
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
848
                    splice @$column, 1, 1;
849
                }
850
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
851
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
852
            }
cleanup
Yuki Kimoto authored on 2011-04-02
853
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
854
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
855
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
856
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
857
    }
858
    else { push @sql, '*' }
859
    
860
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
861
    push @sql, 'from';
862
    if ($relation) {
863
        my $found = {};
864
        foreach my $table (@$tables) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
865
            push @sql, ($self->_q($table), ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
866
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
867
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
868
    }
cleanup
Yuki Kimoto authored on 2011-03-30
869
    else {
870
        my $main_table = $tables->[-1] || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
871
        push @sql, $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
872
    }
873
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
874
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
875
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
876

            
cleanup
Yuki Kimoto authored on 2011-04-02
877
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
878
    unshift @$tables,
879
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
880
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
881
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
882
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
883
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
884
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
885
        $where_clause = "where " . $where->[0];
886
        $where_param = $where->[1];
887
    }
888
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
889
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
890
        $where_param = keys %$where_param
891
                     ? $self->merge_param($where_param, $where->param)
892
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
893
        
894
        # String where
895
        $where_clause = $where->to_string;
896
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
897
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
898
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
899
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
900
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
901
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
902
    # Push join
903
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
904
    
cleanup
Yuki Kimoto authored on 2011-03-09
905
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
906
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
907
    
cleanup
Yuki Kimoto authored on 2011-03-08
908
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
909
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
910
    
cleanup
Yuki Kimoto authored on 2011-04-02
911
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
912
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
913
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
914
    # Wrap
915
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
916
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
917
          unless ref $wrap eq 'ARRAY';
918
        unshift @sql, $wrap->[0];
919
        push @sql, $wrap->[1];
920
    }
921
    
cleanup
Yuki Kimoto authored on 2011-01-27
922
    # SQL
923
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
924
    
925
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
926
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
927
    
928
    return $result;
929
}
930

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
931
sub setup_model {
932
    my $self = shift;
933
    
cleanup
Yuki Kimoto authored on 2011-04-02
934
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
935
    $self->each_column(
936
        sub {
937
            my ($self, $table, $column, $column_info) = @_;
938
            if (my $model = $self->models->{$table}) {
939
                push @{$model->columns}, $column;
940
            }
941
        }
942
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
943
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
944
}
945

            
update pod
Yuki Kimoto authored on 2011-08-10
946
sub show_datatype {
947
    my ($self, $table) = @_;
948
    croak "Table name must be specified" unless defined $table;
949
    print "$table\n";
950
    
951
    my $result = $self->select(table => $table, where => "'0' <> '0'");
952
    my $sth = $result->sth;
953

            
954
    my $columns = $sth->{NAME};
955
    my $data_types = $sth->{TYPE};
956
    
957
    for (my $i = 0; $i < @$columns; $i++) {
958
        my $column = $columns->[$i];
959
        my $data_type = $data_types->[$i];
960
        print "$column: $data_type\n";
961
    }
962
}
963

            
964
sub show_typename {
965
    my ($self, $t) = @_;
966
    croak "Table name must be specified" unless defined $t;
967
    print "$t\n";
968
    
969
    $self->each_column(sub {
970
        my ($self, $table, $column, $infos) = @_;
971
        return unless $table eq $t;
972
        my $typename = $infos->{TYPE_NAME};
973
        print "$column: $typename\n";
974
    });
975
    
976
    return $self;
977
}
978

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1012
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1013
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1014
                }
1015
            });
1016
        }
1017

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1040
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1041
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1042

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1113
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1114
}
1115

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
1116
sub where { DBIx::Custom::Where->new(dbi => shift, @_) }
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1117

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

            
1144
        # Create query
1145
        my $builder = $self->query_builder;
1146
        $query = $builder->build_query($source);
1147

            
1148
        # Remove reserved word quote
1149
        if (my $q = $self->_quote) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1150
            $q = quotemeta($q);
1151
            $_ =~ s/[$q]//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1152
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1153

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

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

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

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

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

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

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1322
sub _push_join {
1323
    my ($self, $sql, $join, $join_tables) = @_;
1324
    
cleanup
Yuki Kimoto authored on 2011-04-02
1325
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1326
    return unless @$join;
1327
    
cleanup
Yuki Kimoto authored on 2011-04-02
1328
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1329
    my $tree = {};
1330
    for (my $i = 0; $i < @$join; $i++) {
1331
        
cleanup
Yuki Kimoto authored on 2011-07-28
1332
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1333
        my $join_clause;;
1334
        my $option;
1335
        if (ref $join->[$i] eq 'HASH') {
1336
            $join_clause = $join->[$i]->{clause};
1337
            $option = {table => $join->[$i]->{table}};
1338
        }
1339
        else {
1340
            $join_clause = $join->[$i];
1341
            $option = {};
1342
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1343

            
1344
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1345
        my $table1;
1346
        my $table2;
1347
        if (my $table = $option->{table}) {
1348
            $table1 = $table->[0];
1349
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1350
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1351
        else {
1352
            my $q = $self->_quote;
1353
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1354
            $j_clause =~ s/'.+?'//g;
1355
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1356
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1357
            my $c = $self->safety_character;
1358
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1359
            if ($j_clause =~ $join_re) {
1360
                $table1 = $1;
1361
                $table2 = $2;
1362
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1363
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1364
        croak qq{join clause must have two table name after "on" keyword. } .
1365
              qq{"$join_clause" is passed }  . _subname
1366
          unless defined $table1 && defined $table2;
1367
        croak qq{right side table of "$join_clause" must be unique }
1368
            . _subname
1369
          if exists $tree->{$table2};
1370
        croak qq{Same table "$table1" is specified} . _subname
1371
          if $table1 eq $table2;
1372
        $tree->{$table2}
1373
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1374
    }
1375
    
cleanup
Yuki Kimoto authored on 2011-04-02
1376
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1377
    my $need_tables = {};
1378
    $self->_need_tables($tree, $need_tables, $join_tables);
1379
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1380
    
1381
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1382
    foreach my $need_table (@need_tables) {
1383
        push @$sql, $tree->{$need_table}{join};
1384
    }
1385
}
cleanup
Yuki Kimoto authored on 2011-03-08
1386

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1387
sub _quote {
1388
    my $self = shift;
1389
    
1390
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1391
         : defined $self->quote ? $self->quote
1392
         : '';
1393
}
1394

            
cleanup
Yuki Kimoto authored on 2011-07-29
1395
sub _q {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1396
    my ($self, $value) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1397
    
1398
    my $quote = $self->_quote;
1399
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1400
    my $p;
1401
    if (defined $quote && length $quote > 1) {
1402
        $p = substr($quote, 1, 1);
1403
    }
1404
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1405
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1406
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1407
}
1408

            
cleanup
Yuki Kimoto authored on 2011-04-02
1409
sub _remove_duplicate_table {
1410
    my ($self, $tables, $main_table) = @_;
1411
    
1412
    # Remove duplicate table
1413
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1414
    delete $tables{$main_table} if $main_table;
1415
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1416
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1417
    if (my $q = $self->_quote) {
1418
        $q = quotemeta($q);
1419
        $_ =~ s/[$q]//g for @$new_tables;
1420
    }
1421

            
1422
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1423
}
1424

            
cleanup
Yuki Kimoto authored on 2011-04-02
1425
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1426
    my ($self, $source) = @_;
1427
    
cleanup
Yuki Kimoto authored on 2011-04-02
1428
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1429
    my $tables = [];
1430
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1431
    my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1432
    my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1433
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)");
1434
    my $table_re = $q ? qr/(?:^|[^$safety_character])$quoted_safety_character_re?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1435
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1436
    while ($source =~ /$table_re/g) {
1437
        push @$tables, $1;
1438
    }
1439
    
1440
    return $tables;
1441
}
1442

            
cleanup
Yuki Kimoto authored on 2011-04-02
1443
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1444
    my ($self, $where) = @_;
1445
    
cleanup
Yuki Kimoto authored on 2011-04-02
1446
    my $obj;
1447
    
1448
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1449
    if (ref $where eq 'HASH') {
1450
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1451
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1452
        foreach my $column (keys %$where) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1453
            my $column_quote = $self->_q($column);
1454
            $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1455
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1456
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1457
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1458
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1459
    
1460
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1461
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1462
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1463
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1464
    
updated pod
Yuki Kimoto authored on 2011-06-21
1465
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1466
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1467
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1468
            clause => $where->[0],
1469
            param  => $where->[1]
1470
        );
1471
    }
1472
    
cleanup
Yuki Kimoto authored on 2011-04-02
1473
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1474
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1475
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1476
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1477
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1478
    
cleanup
Yuki Kimoto authored on 2011-04-02
1479
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1480
}
1481

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

            
1485
    # Initialize filters
1486
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1487
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1488
    $self->{filter}{out} ||= {};
1489
    $self->{filter}{in} ||= {};
1490
    $self->{filter}{end} ||= {};
1491
    
1492
    # Usage
1493
    my $usage = "Usage: \$dbi->apply_filter(" .
1494
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1495
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1496
    
1497
    # Apply filter
1498
    for (my $i = 0; $i < @cinfos; $i += 2) {
1499
        
1500
        # Column
1501
        my $column = $cinfos[$i];
1502
        if (ref $column eq 'ARRAY') {
1503
            foreach my $c (@$column) {
1504
                push @cinfos, $c, $cinfos[$i + 1];
1505
            }
1506
            next;
1507
        }
1508
        
1509
        # Filter infomation
1510
        my $finfo = $cinfos[$i + 1] || {};
1511
        croak "$usage (table: $table) " . _subname
1512
          unless  ref $finfo eq 'HASH';
1513
        foreach my $ftype (keys %$finfo) {
1514
            croak "$usage (table: $table) " . _subname
1515
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1516
        }
1517
        
1518
        # Set filters
1519
        foreach my $way (qw/in out end/) {
1520
        
1521
            # Filter
1522
            my $filter = $finfo->{$way};
1523
            
1524
            # Filter state
1525
            my $state = !exists $finfo->{$way} ? 'not_exists'
1526
                      : !defined $filter        ? 'not_defined'
1527
                      : ref $filter eq 'CODE'   ? 'code'
1528
                      : 'name';
1529
            
1530
            # Filter is not exists
1531
            next if $state eq 'not_exists';
1532
            
1533
            # Check filter name
1534
            croak qq{Filter "$filter" is not registered } . _subname
1535
              if  $state eq 'name'
1536
               && ! exists $self->filters->{$filter};
1537
            
1538
            # Set filter
1539
            my $f = $state eq 'not_defined' ? undef
1540
                  : $state eq 'code'        ? $filter
1541
                  : $self->filters->{$filter};
1542
            $self->{filter}{$way}{$table}{$column} = $f;
1543
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1544
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1545
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1546
        }
1547
    }
1548
    
1549
    return $self;
1550
}
1551

            
1552
# DEPRECATED!
1553
sub create_query {
1554
    warn "create_query is DEPRECATED! use query option of each method";
1555
    shift->_create_query(@_);
1556
}
1557

            
cleanup
Yuki Kimoto authored on 2011-06-13
1558
# DEPRECATED!
1559
sub apply_filter {
1560
    my $self = shift;
1561
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1562
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1563
    return $self->_apply_filter(@_);
1564
}
1565

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1566
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1567
our %SELECT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1568
sub select_at {
1569
    my ($self, %args) = @_;
1570

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1573
    # Arguments
1574
    my $primary_keys = delete $args{primary_key};
1575
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1576
    my $where = delete $args{where};
1577
    my $param = delete $args{param};
1578
    
1579
    # Check arguments
1580
    foreach my $name (keys %args) {
1581
        croak qq{"$name" is wrong option } . _subname
1582
          unless $SELECT_AT_ARGS{$name};
1583
    }
1584
    
1585
    # Table
1586
    croak qq{"table" option must be specified } . _subname
1587
      unless $args{table};
1588
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1589
    
1590
    # Create where parameter
1591
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1592
    
1593
    return $self->select(where => $where_param, %args);
1594
}
1595

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1596
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1597
our %DELETE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1598
sub delete_at {
1599
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1600

            
1601
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1602
    
1603
    # Arguments
1604
    my $primary_keys = delete $args{primary_key};
1605
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1606
    my $where = delete $args{where};
1607
    
1608
    # Check arguments
1609
    foreach my $name (keys %args) {
1610
        croak qq{"$name" is wrong option } . _subname
1611
          unless $DELETE_AT_ARGS{$name};
1612
    }
1613
    
1614
    # Create where parameter
1615
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1616
    
1617
    return $self->delete(where => $where_param, %args);
1618
}
1619

            
cleanup
Yuki Kimoto authored on 2011-06-08
1620
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1621
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1622
sub update_at {
1623
    my $self = shift;
1624

            
1625
    warn "update_at is DEPRECATED! use update and id option instead";
1626
    
1627
    # Arguments
1628
    my $param;
1629
    $param = shift if @_ % 2;
1630
    my %args = @_;
1631
    my $primary_keys = delete $args{primary_key};
1632
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1633
    my $where = delete $args{where};
1634
    my $p = delete $args{param} || {};
1635
    $param  ||= $p;
1636
    
1637
    # Check arguments
1638
    foreach my $name (keys %args) {
1639
        croak qq{"$name" is wrong option } . _subname
1640
          unless $UPDATE_AT_ARGS{$name};
1641
    }
1642
    
1643
    # Create where parameter
1644
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1645
    
1646
    return $self->update(where => $where_param, param => $param, %args);
1647
}
1648

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1649
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1650
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1651
sub insert_at {
1652
    my $self = shift;
1653
    
1654
    warn "insert_at is DEPRECATED! use insert and id option instead";
1655
    
1656
    # Arguments
1657
    my $param;
1658
    $param = shift if @_ % 2;
1659
    my %args = @_;
1660
    my $primary_key = delete $args{primary_key};
1661
    $primary_key = [$primary_key] unless ref $primary_key;
1662
    my $where = delete $args{where};
1663
    my $p = delete $args{param} || {};
1664
    $param  ||= $p;
1665
    
1666
    # Check arguments
1667
    foreach my $name (keys %args) {
1668
        croak qq{"$name" is wrong option } . _subname
1669
          unless $INSERT_AT_ARGS{$name};
1670
    }
1671
    
1672
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1673
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1674
    $param = $self->merge_param($where_param, $param);
1675
    
1676
    return $self->insert(param => $param, %args);
1677
}
1678

            
added warnings
Yuki Kimoto authored on 2011-06-07
1679
# DEPRECATED!
1680
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1681
    my $self = shift;
1682
    
added warnings
Yuki Kimoto authored on 2011-06-07
1683
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1684
    
1685
    # Merge tag
1686
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1687
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1688
    
1689
    return $self;
1690
}
1691

            
1692
# DEPRECATED!
1693
sub register_tag_processor {
1694
    my $self = shift;
1695
    warn "register_tag_processor is DEPRECATED!";
1696
    # Merge tag
1697
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1698
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1699
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1700
}
1701

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1702
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1703
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1704
has dbi_options => sub { {} };
1705
has filter_check  => 1;
1706
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1707

            
cleanup
Yuki Kimoto authored on 2011-01-25
1708
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1709
sub default_bind_filter {
1710
    my $self = shift;
1711
    
cleanup
Yuki Kimoto authored on 2011-06-13
1712
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1713
    
cleanup
Yuki Kimoto authored on 2011-01-12
1714
    if (@_) {
1715
        my $fname = $_[0];
1716
        
1717
        if (@_ && !$fname) {
1718
            $self->{default_out_filter} = undef;
1719
        }
1720
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1721
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1722
              unless exists $self->filters->{$fname};
1723
        
1724
            $self->{default_out_filter} = $self->filters->{$fname};
1725
        }
1726
        return $self;
1727
    }
1728
    
1729
    return $self->{default_out_filter};
1730
}
1731

            
cleanup
Yuki Kimoto authored on 2011-01-25
1732
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1733
sub default_fetch_filter {
1734
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1735

            
cleanup
Yuki Kimoto authored on 2011-06-13
1736
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1737
    
1738
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1739
        my $fname = $_[0];
1740

            
cleanup
Yuki Kimoto authored on 2011-01-12
1741
        if (@_ && !$fname) {
1742
            $self->{default_in_filter} = undef;
1743
        }
1744
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1745
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1746
              unless exists $self->filters->{$fname};
1747
        
1748
            $self->{default_in_filter} = $self->filters->{$fname};
1749
        }
1750
        
1751
        return $self;
1752
    }
1753
    
many changed
Yuki Kimoto authored on 2011-01-23
1754
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1755
}
1756

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1757
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1758
sub insert_param_tag {
1759
    warn "insert_param_tag is DEPRECATED! " .
1760
         "use insert_param instead!";
1761
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1762
}
1763

            
1764
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1765
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1766
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1767
         "use update_param instead";
1768
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1769
}
cleanup
Yuki Kimoto authored on 2011-03-08
1770
# DEPRECATED!
1771
sub _push_relation {
1772
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1773
    
1774
    if (keys %{$relation || {}}) {
1775
        push @$sql, $need_where ? 'where' : 'and';
1776
        foreach my $rcolumn (keys %$relation) {
1777
            my $table1 = (split (/\./, $rcolumn))[0];
1778
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1779
            push @$tables, ($table1, $table2);
1780
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1781
        }
1782
    }
1783
    pop @$sql if $sql->[-1] eq 'and';    
1784
}
1785

            
1786
# DEPRECATED!
1787
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1788
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1789
    
1790
    if (keys %{$relation || {}}) {
1791
        foreach my $rcolumn (keys %$relation) {
1792
            my $table1 = (split (/\./, $rcolumn))[0];
1793
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1794
            my $table1_exists;
1795
            my $table2_exists;
1796
            foreach my $table (@$tables) {
1797
                $table1_exists = 1 if $table eq $table1;
1798
                $table2_exists = 1 if $table eq $table2;
1799
            }
1800
            unshift @$tables, $table1 unless $table1_exists;
1801
            unshift @$tables, $table2 unless $table2_exists;
1802
        }
1803
    }
1804
}
1805

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1808
=head1 NAME
1809

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

            
1812
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1813

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1814
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1815
    
1816
    # Connect
1817
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1818
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1819
        user => 'ken',
1820
        password => '!LFKD%$&',
1821
        dbi_option => {mysql_enable_utf8 => 1}
1822
    );
cleanup
yuki-kimoto authored on 2010-08-05
1823

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1824
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1825
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1826
    
1827
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1828
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1829
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1830
    
1831
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1832
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1833

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1838
    # Select, more complex
1839
    my $result = $dbi->select(
1840
        table  => 'book',
1841
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1842
            {book => [qw/title author/]},
1843
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1844
        ],
1845
        where  => {'book.author' => 'Ken'},
1846
        join => ['left outer join company on book.company_id = company.id'],
1847
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1848
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1849
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1850
    # Fetch
1851
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1852
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1853
    }
1854
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1855
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1856
    while (my $row = $result->fetch_hash) {
1857
        
1858
    }
1859
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1860
    # Execute SQL with parameter.
1861
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1862
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1863
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1864
    );
1865
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1866
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1867

            
cleanup
Yuki Kimoto authored on 2011-07-29
1868
L<DBIx::Custom> is L<DBI> wrapper module to execute SQL easily.
updated pod
Yuki Kimoto authored on 2011-06-21
1869
This module have the following features.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1870

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

            
cleanup
Yuki Kimoto authored on 2011-07-29
1873
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1874

            
cleanup
Yuki Kimoto authored on 2011-07-29
1875
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1876

            
cleanup
Yuki Kimoto authored on 2011-07-29
1877
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1878

            
cleanup
Yuki Kimoto authored on 2011-07-29
1879
Create C<where> clause flexibly
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1880

            
cleanup
Yuki Kimoto authored on 2011-07-29
1881
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1882

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1883
Named place holder support
1884

            
1885
=item *
1886

            
cleanup
Yuki Kimoto authored on 2011-07-29
1887
Model support
1888

            
1889
=item *
1890

            
1891
Connection manager support
1892

            
1893
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1894

            
cleanup
Yuki Kimoto authored on 2011-07-30
1895
Choice your favorite relational database management system,
cleanup
Yuki Kimoto authored on 2011-07-29
1896
C<MySQL>, C<SQLite>, C<PostgreSQL>, C<Oracle>,
1897
C<Microsoft SQL Server>, C<Microsoft Access>, C<DB2> or anything, 
1898

            
1899
=item *
1900

            
1901
Filtering by data type or column name(EXPERIMENTAL)
1902

            
1903
=item *
1904

            
1905
Create C<order by> clause flexibly(EXPERIMENTAL)
1906

            
1907
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1908

            
cleanup
Yuki Kimoto authored on 2011-07-29
1909
=head1 DOCUMENTATIONS
pod fix
Yuki Kimoto authored on 2011-01-21
1910

            
cleanup
Yuki Kimoto authored on 2011-07-29
1911
L<DBIx::Custom::Guide> - How to use L<DBIx::Custom>
pod fix
Yuki Kimoto authored on 2011-01-21
1912

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1913
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
cleanup
Yuki Kimoto authored on 2011-07-29
1914
- Theare are various examples.
1915

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1916
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1917
L<DBIx::Custom::Result>,
1918
L<DBIx::Custom::Query>,
1919
L<DBIx::Custom::Where>,
1920
L<DBIx::Custom::Model>,
1921
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1922

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

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

            
1927
    my $connector = $dbi->connector;
micro optimization
Yuki Kimoto authored on 2011-07-30
1928
    $dbi = $dbi->connector($connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1929

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1930
Connection manager object. if C<connector> is set, you can get C<dbh>
1931
through connection manager. Conection manager object must have C<dbh> mehtod.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1932

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

            
1936
    my $connector = DBIx::Connector->new(
1937
        "dbi:mysql:database=$DATABASE",
1938
        $USER,
1939
        $PASSWORD,
1940
        DBIx::Custom->new->default_dbi_option
1941
    );
1942
    
updated pod
Yuki Kimoto authored on 2011-06-21
1943
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1944

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

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

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

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

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

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

            
1960
=head2 C<default_dbi_option>
1961

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1968
    {
1969
        RaiseError => 1,
1970
        PrintError => 0,
1971
        AutoCommit => 1,
1972
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1973

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

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
1981
=head2 C<last_sql>
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1982

            
1983
    my $last_sql = $dbi->last_sql;
1984
    $dbi = $dbi->last_sql($last_sql);
1985

            
1986
Get last successed SQL executed by C<execute> method.
1987

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1995
=head2 C<password>
1996

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

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

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2004
    my $builder = $dbi->query_builder;
added commit method
yuki-kimoto authored on 2010-05-27
2005

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2006
Creat query builder. This is L<DBIx::Custom::QueryBuilder>.
cleanup
yuki-kimoto authored on 2010-08-05
2007

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2017
You can set quote pair.
2018

            
2019
    $dbi->quote('[]');
2020

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

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

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

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

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

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2036
=head2 C<separator>
2037

            
2038
    my $separator = $self->separator;
2039
    $dbi = $self->separator($separator);
2040

            
2041
Separator whichi join table and column.
2042
This is used by C<column> and C<mycolumn> method.
2043

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2044
=head2 C<exclude_table EXPERIMENTAL>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2045

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2046
    my $exclude_table = $self->exclude_table;
2047
    $dbi = $self->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2048

            
2049
Regex matching system table.
2050
this regex match is used by C<each_table> method and C<each_column> method
2051
System table is ignored.
2052
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2053
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2054
The performance is up.
2055

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

            
2058
    my $tag_parse = $dbi->tag_parse(0);
2059
    $dbi = $dbi->tag_parse;
2060

            
2061
Enable DEPRECATED tag parsing functionality, default to 1.
2062
If you want to disable tag parsing functionality, set to 0.
2063

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

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

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

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2077
=head2 C<available_datatype> EXPERIMENTAL
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2078

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2079
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2080

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2084
=head2 C<available_typename> EXPERIMENTAL
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2085

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2086
    print $dbi->available_typename;
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2087

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

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

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

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

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

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

            
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2101
=head2 C<column>
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2102

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

            
2105
Create column clause. The follwoing column clause is created.
2106

            
2107
    book.author as "book.author",
2108
    book.title as "book.title"
2109

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2110
You can change separator by C<separator> attribute.
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2111

            
cleanup
Yuki Kimoto authored on 2011-06-13
2112
    # Separator is double underbar
2113
    $dbi->separator('__');
2114
    
2115
    book.author as "book__author",
2116
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2117

            
cleanup
Yuki Kimoto authored on 2011-06-13
2118
    # Separator is hyphen
2119
    $dbi->separator('-');
2120
    
2121
    book.author as "book-author",
2122
    book.title as "book-title"
2123
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2124
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2125

            
update pod
Yuki Kimoto authored on 2011-03-13
2126
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2127
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2128
        user => 'ken',
2129
        password => '!LFKD%$&',
2130
        dbi_option => {mysql_enable_utf8 => 1}
2131
    );
2132

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2141
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2142
        table => 'book',
2143
        primary_key => 'id',
2144
        join => [
2145
            'inner join company on book.comparny_id = company.id'
2146
        ],
2147
    );
2148

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

            
2152
   $dbi->model('book')->select(...);
2153

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

            
2156
    my $dbh = $dbi->dbh;
2157

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

            
2161
=head2 C<each_column>
2162

            
2163
    $dbi->each_column(
2164
        sub {
2165
            my ($dbi, $table, $column, $column_info) = @_;
2166
            
2167
            my $type = $column_info->{TYPE_NAME};
2168
            
2169
            if ($type eq 'DATE') {
2170
                # ...
2171
            }
2172
        }
2173
    );
2174

            
2175
Iterate all column informations of all table from database.
2176
Argument is callback when one column is found.
2177
Callback receive four arguments, dbi object, table name,
2178
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2179

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2180
=head2 C<each_table>
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2181

            
2182
    $dbi->each_table(
2183
        sub {
2184
            my ($dbi, $table, $table_info) = @_;
2185
            
2186
            my $table_name = $table_info->{TABLE_NAME};
2187
        }
2188
    );
2189

            
2190
Iterate all table informationsfrom database.
2191
Argument is callback when one table is found.
2192
Callback receive three arguments, dbi object, table name,
2193
table information.
2194

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

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

            
2202
    my $result = $dbi->execute(
2203
      "select * from book where title = :book.title and author like :book.author",
2204
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2205
    );
2206

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2213
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2214
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2215
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2216
    select * from book where title = :title and author like :author
2217
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2218
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2219
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2220

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2221
You can specify operator with named placeholder
2222
 by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2223

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2224
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2225
    select * from book where :title{=} and :author{like}
2226
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2227
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2228
    select * from where title = ? and author like ?;
2229

            
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
2230
Note that colons in time format such as 12:13:15 is exeption,
2231
it is not parsed as named placeholder.
2232
If you want to use colon generally, you must escape it by C<\\>
2233

            
2234
    select * from where title = "aa\\:bb";
2235

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

            
2238
=over 4
2239

            
2240
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2241
    
2242
    filter => {
2243
        title  => sub { uc $_[0] }
2244
        author => sub { uc $_[0] }
2245
    }
update pod
Yuki Kimoto authored on 2011-03-13
2246

            
updated pod
Yuki Kimoto authored on 2011-06-09
2247
    # Filter name
2248
    filter => {
2249
        title  => 'upper_case',
2250
        author => 'upper_case'
2251
    }
2252
        
2253
    # At once
2254
    filter => [
2255
        [qw/title author/]  => sub { uc $_[0] }
2256
    ]
2257

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

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

            
2265
    query => 1
2266

            
2267
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
cleanup
Yuki Kimoto authored on 2011-07-30
2268
You can check SQL or get statment handle.
updated pod
Yuki Kimoto authored on 2011-06-21
2269

            
2270
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2271
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2272
    my $columns = $query->columns;
2273
    
2274
If you want to execute SQL fast, you can do the following way.
2275

            
2276
    my $query;
2277
    foreach my $row (@$rows) {
2278
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2279
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2280
    }
2281

            
2282
Statement handle is reused and SQL parsing is finished,
2283
so you can get more performance than normal way.
cleanup
Yuki Kimoto authored on 2011-07-30
2284

            
2285
If you want to execute SQL as possible as fast and don't need filtering.
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2286
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2287
    
2288
    my $query;
2289
    my $sth;
2290
    foreach my $row (@$rows) {
2291
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2292
      $sth ||= $query->sth;
2293
      $sth->execute(map { $row->{$_} } sort keys %$row);
2294
    }
2295

            
2296
Note that $row must be simple hash reference, such as
2297
{title => 'Perl', author => 'Ken'}.
2298
and don't forget to sort $row values by $row key asc order.
updated document
Yuki Kimoto authored on 2011-06-09
2299

            
updated pod
Yuki Kimoto authored on 2011-06-09
2300
=item C<table>
2301
    
2302
    table => 'author'
2303

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2311
    # Same
2312
    $dbi->execute(
2313
      "select * from book where title = :book.title and author = :book.author",
2314
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2315

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

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

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

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

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

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

            
2329
    table_alias => {user => 'hiker'}
2330

            
2331
Table alias. Key is real table name, value is alias table name.
2332
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2333
on alias table name.
2334

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

            
2337
    type_rule_off => 1
2338

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

            
2341
=item C<type_rule1_off> EXPERIMENTAL
2342

            
2343
    type_rule1_off => 1
2344

            
2345
Turn C<into1> type rule off.
2346

            
2347
=item C<type_rule2_off> EXPERIMENTAL
2348

            
2349
    type_rule2_off => 1
2350

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2363
=over 4
2364

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

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

            
2369
=item C<filter>
2370

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2375
    id => 4
2376
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2377

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2381
    $dbi->delete(
2382
        parimary_key => ['id1', 'id2'],
2383
        id => [4, 5],
2384
        table => 'book',
2385
    );
update pod
Yuki Kimoto authored on 2011-03-13
2386

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2391
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2392

            
2393
    prefix => 'some'
2394

            
2395
prefix before table name section.
2396

            
2397
    delete some from book
2398

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2407
Table name.
2408

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

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

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

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

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

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

            
2421
=item C<type_rule_off> EXPERIMENTAL
2422

            
2423
Same as C<execute> method's C<type_rule_off> option.
2424

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

            
2427
    type_rule1_off => 1
2428

            
2429
Same as C<execute> method's C<type_rule1_off> option.
2430

            
2431
=item C<type_rule2_off> EXPERIMENTAL
2432

            
2433
    type_rule2_off => 1
2434

            
2435
Same as C<execute> method's C<type_rule2_off> option.
2436

            
updated pod
Yuki Kimoto authored on 2011-06-08
2437
=back
update pod
Yuki Kimoto authored on 2011-03-13
2438

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2446
=head2 C<insert>
2447

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

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

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
2453
If you want to set constant value to row data, use scalar reference
2454
as parameter value.
2455

            
2456
    {date => \"NOW()"}
2457

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

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

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

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

            
2466
=item C<filter>
2467

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

            
2470
=item C<id>
2471

            
updated document
Yuki Kimoto authored on 2011-06-09
2472
    id => 4
2473
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2474

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2478
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2479
        {title => 'Perl', author => 'Ken'}
2480
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2481
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2482
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2483
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2484

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2492
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2493

            
2494
    prefix => 'or replace'
2495

            
2496
prefix before table name section
2497

            
2498
    insert or replace into book
2499

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

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

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

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

            
2509
Same as C<execute> method's C<query> option.
2510

            
2511
=item C<table>
2512

            
2513
    table => 'book'
2514

            
2515
Table name.
2516

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

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

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

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

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

            
2527
    type_rule1_off => 1
2528

            
2529
Same as C<execute> method's C<type_rule1_off> option.
2530

            
2531
=item C<type_rule2_off> EXPERIMENTAL
2532

            
2533
    type_rule2_off => 1
2534

            
2535
Same as C<execute> method's C<type_rule2_off> option.
2536

            
update pod
Yuki Kimoto authored on 2011-03-13
2537
=back
2538

            
2539
=over 4
2540

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2556
    lib / MyModel.pm
2557
        / MyModel / book.pm
2558
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2559

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

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

            
2564
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2565
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2566
    
2567
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2568

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2573
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2574
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2575
    
2576
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2577

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2580
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2581
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2582
    
2583
    1;
2584
    
updated pod
Yuki Kimoto authored on 2011-06-21
2585
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2586

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

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

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

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

            
2596
    my $map_param = $dbi->map_param(
2597
        {id => 1, authro => 'Ken', price => 1900},
2598
        'id' => 'book.id',
2599
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2600
        'price' => [
2601
            'book.price', {if => sub { length $_[0] }}
2602
        ]
2603
    );
2604

            
2605
Map paramters to other key and value. First argument is original
2606
parameter. this is hash reference. Rest argument is mapping.
2607
By default, Mapping is done if the value length is not zero.
2608

            
2609
=over 4
2610

            
2611
=item Key mapping
2612

            
2613
    'id' => 'book.id'
2614

            
2615
This is only key mapping. Value is same as original one.
2616

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

            
2619
=item Key and value mapping
2620

            
2621
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2622

            
2623
This is key and value mapping. Frist element of array reference
2624
is mapped key name, second element is code reference to map the value.
2625

            
2626
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2627
      if value length is not zero.
2628

            
2629
=item Condition
2630

            
2631
    'price' => ['book.price', {if => 'exists'}]
2632
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2633
    'price' => ['book.price', {if => sub { defined shift }}]
2634

            
2635
If you need condition, you can sepecify it. this is code reference
2636
or 'exists'. By default, condition is the following one.
2637

            
2638
    sub { defined $_[0] && length $_[0] }
2639

            
2640
=back
2641

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

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

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

            
2648
    {key1 => [1, 1], key2 => 2}
2649

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

            
2652
    $dbi->method(
2653
        update_or_insert => sub {
2654
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2655
            
2656
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2657
        },
2658
        find_or_create   => sub {
2659
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2660
            
2661
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2662
        }
2663
    );
2664

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

            
2667
    $dbi->update_or_insert;
2668
    $dbi->find_or_create;
2669

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

            
2672
    my $model = $dbi->model('book');
2673

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

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

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

            
2680
Create column clause for myself. The follwoing column clause is created.
2681

            
2682
    book.author as author,
2683
    book.title as title
2684

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2687
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2688
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2689
        user => 'ken',
2690
        password => '!LFKD%$&',
2691
        dbi_option => {mysql_enable_utf8 => 1}
2692
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2693

            
2694
Create a new L<DBIx::Custom> object.
2695

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

            
2698
    my $not_exists = $dbi->not_exists;
2699

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

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

            
2705
    my $order = $dbi->order;
2706

            
2707
Create a new L<DBIx::Custom::Order> object.
2708

            
cleanup
yuki-kimoto authored on 2010-10-17
2709
=head2 C<register_filter>
2710

            
update pod
Yuki Kimoto authored on 2011-03-13
2711
    $dbi->register_filter(
2712
        # Time::Piece object to database DATE format
2713
        tp_to_date => sub {
2714
            my $tp = shift;
2715
            return $tp->strftime('%Y-%m-%d');
2716
        },
2717
        # database DATE format to Time::Piece object
2718
        date_to_tp => sub {
2719
           my $date = shift;
2720
           return Time::Piece->strptime($date, '%Y-%m-%d');
2721
        }
2722
    );
cleanup
yuki-kimoto authored on 2010-10-17
2723
    
update pod
Yuki Kimoto authored on 2011-03-13
2724
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2725

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

            
2728
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2729
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2730
            date => sub { ... },
2731
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2732
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2733
        into2 => {
2734
            date => sub { ... },
2735
            datetime => sub { ... }
2736
        },
2737
        from1 => {
2738
            # DATE
2739
            9 => sub { ... },
2740
            # DATETIME or TIMESTAMP
2741
            11 => sub { ... },
2742
        }
2743
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2744
            # DATE
2745
            9 => sub { ... },
2746
            # DATETIME or TIMESTAMP
2747
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2748
        }
2749
    );
2750

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2766
=over 4
2767

            
2768
=item 1. column name
2769

            
2770
    issue_date
2771
    issue_datetime
2772

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

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

            
2777
    book.issue_date
2778
    book.issue_datetime
2779

            
2780
=back
2781

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2782
You get all type name used in database by C<available_typename>.
update pod
Yuki Kimoto authored on 2011-06-15
2783

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2784
    print $dbi->available_typename;
update pod
Yuki Kimoto authored on 2011-06-15
2785

            
updated pod
Yuki Kimoto authored on 2011-06-21
2786
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2787
C<from2> is executed after C<from1>.
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2788
You get all data type by C<available_datatype>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2789

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2790
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2791

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

            
2794
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2795
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2796
            [qw/DATE DATETIME/] => sub { ... },
2797
        ],
2798
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2799

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2802
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2803
        table  => 'book',
2804
        column => ['author', 'title'],
2805
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2806
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2807
    
updated document
Yuki Kimoto authored on 2011-06-09
2808
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2809

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

            
2812
=over 4
2813

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2818
Append statement to last of SQL.
2819
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2820
=item C<column>
2821
    
updated document
Yuki Kimoto authored on 2011-06-09
2822
    column => 'author'
2823
    column => ['author', 'title']
2824

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2831
You can specify hash of array reference.
updated pod
Yuki Kimoto authored on 2011-06-07
2832

            
updated document
Yuki Kimoto authored on 2011-06-09
2833
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2834
        {book => [qw/author title/]},
2835
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2836
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2837

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

            
2840
    book.author as "book.author",
2841
    book.title as "book.title",
2842
    person.name as "person.name",
2843
    person.age as "person.age"
2844

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

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

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

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

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

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

            
2860
=item C<id>
2861

            
2862
    id => 4
2863
    id => [4, 5]
2864

            
2865
ID corresponding to C<primary_key>.
2866
You can select rows by C<id> and C<primary_key>.
2867

            
2868
    $dbi->select(
2869
        parimary_key => ['id1', 'id2'],
2870
        id => [4, 5],
2871
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2872
    );
2873

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2876
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2877
        where => {id1 => 4, id2 => 5},
2878
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2879
    );
2880
    
updated document
Yuki Kimoto authored on 2011-06-09
2881
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2882

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

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2893
=itme C<prefix>
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2894

            
2895
    prefix => 'SQL_CALC_FOUND_ROWS'
2896

            
2897
Prefix of column cluase
2898

            
2899
    select SQL_CALC_FOUND_ROWS title, author from book;
2900

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

            
2903
    join => [
2904
        'left outer join company on book.company_id = company_id',
2905
        'left outer join location on company.location_id = location.id'
2906
    ]
2907
        
2908
Join clause. If column cluase or where clause contain table name like "company.name",
2909
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2910

            
2911
    $dbi->select(
2912
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2913
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2914
        where => {'company.name' => 'Orange'},
2915
        join => [
2916
            'left outer join company on book.company_id = company.id',
2917
            'left outer join location on company.location_id = location.id'
2918
        ]
2919
    );
2920

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2924
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2925
    from book
2926
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2927
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2928

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
2929
You can specify two table by yourself. This is useful when join parser can't parse
cleanup
Yuki Kimoto authored on 2011-07-28
2930
the join clause correctly. This is EXPERIMENTAL.
added join new syntax
Yuki Kimoto authored on 2011-07-28
2931

            
2932
    $dbi->select(
2933
        table => 'book',
2934
        column => ['company.location_id as location_id'],
2935
        where => {'company.name' => 'Orange'},
2936
        join => [
2937
            {
2938
                clause => 'left outer join location on company.location_id = location.id',
2939
                table => ['company', 'location']
2940
            }
2941
        ]
2942
    );
2943

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-28
2957
Same as C<execute> method's C<bind_type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2958

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2963
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2964

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

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

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

            
2971
    type_rule1_off => 1
2972

            
2973
Same as C<execute> method's C<type_rule1_off> option.
2974

            
2975
=item C<type_rule2_off> EXPERIMENTAL
2976

            
2977
    type_rule2_off => 1
2978

            
2979
Same as C<execute> method's C<type_rule2_off> option.
2980

            
updated document
Yuki Kimoto authored on 2011-06-09
2981
=item C<where>
2982
    
2983
    # Hash refrence
2984
    where => {author => 'Ken', 'title' => 'Perl'}
2985
    
2986
    # DBIx::Custom::Where object
2987
    where => $dbi->where(
2988
        clause => ['and', 'author = :author', 'title like :title'],
2989
        param  => {author => 'Ken', title => '%Perl%'}
2990
    );
updated pod
Yuki Kimoto authored on 2011-06-21
2991
    
2992
    # Array reference 1 (array reference, hash referenc). same as above
2993
    where => [
2994
        ['and', 'author = :author', 'title like :title'],
2995
        {author => 'Ken', title => '%Perl%'}
2996
    ];    
2997
    
2998
    # Array reference 2 (String, hash reference)
2999
    where => [
3000
        'title like :title',
3001
        {title => '%Perl%'}
3002
    ]
3003
    
3004
    # String
3005
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3006

            
updated document
Yuki Kimoto authored on 2011-06-09
3007
Where clause.
3008
    
improved pod
Yuki Kimoto authored on 2011-04-19
3009
=item C<wrap> EXPERIMENTAL
3010

            
3011
Wrap statement. This is array reference.
3012

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

            
3015
This option is for Oracle and SQL Server paging process.
3016

            
update pod
Yuki Kimoto authored on 2011-03-12
3017
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3018

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

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

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
3023
Execute update statement. First argument is update row data.
3024

            
3025
If you want to set constant value to row data, use scalar reference
3026
as parameter value.
3027

            
3028
    {date => \"NOW()"}
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3029

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3032
=over 4
3033

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3044
    id => 4
3045
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3046

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3050
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3051
        {title => 'Perl', author => 'Ken'}
3052
        parimary_key => ['id1', 'id2'],
3053
        id => [4, 5],
3054
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3055
    );
update pod
Yuki Kimoto authored on 2011-03-13
3056

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3059
    $dbi->update(
3060
        {title => 'Perl', author => 'Ken'}
3061
        where => {id1 => 4, id2 => 5},
3062
        table => 'book'
3063
    );
update pod
Yuki Kimoto authored on 2011-03-13
3064

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
3065
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3066

            
3067
    prefix => 'or replace'
3068

            
3069
prefix before table name section
3070

            
3071
    update or replace book
3072

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-28
3096
Same as C<execute> method's C<bind_type> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3097

            
3098
=item C<type_rule_off> EXPERIMENTAL
3099

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

            
3102
=item C<type_rule1_off> EXPERIMENTAL
3103

            
3104
    type_rule1_off => 1
3105

            
3106
Same as C<execute> method's C<type_rule1_off> option.
3107

            
3108
=item C<type_rule2_off> EXPERIMENTAL
3109

            
3110
    type_rule2_off => 1
3111

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
3114
=back
update pod
Yuki Kimoto authored on 2011-03-13
3115

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

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

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

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

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

            
3127
Create update parameter tag.
3128

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

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

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

            
3138
Create a new L<DBIx::Custom::Where> object.
3139

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

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

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

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

            
3149
=head2 C<DBIX_CUSTOM_DEBUG>
3150

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

            
update pod
Yuki Kimoto authored on 2011-08-10
3154
=head2 C<show_datatype EXPERIMENTAL>
3155

            
3156
    $dbi->show_datatype($table);
3157

            
3158
Show data type of the columns of specified table.
3159

            
3160
    book
3161
    title: 5
3162
    issue_date: 91
3163

            
3164
This data type is used in C<type_rule>'s C<from1> and C<from2>.
3165

            
3166
=head2 C<show_typename EXPERIMENTAL>
3167

            
3168
    $dbi->show_typename($table);
3169

            
3170
Show type name of the columns of specified table.
3171

            
3172
    book
3173
    title: varchar
3174
    issue_date: date
3175

            
3176
This type name is used in C<type_rule>'s C<into1> and C<into2>.
3177

            
improved debug message
Yuki Kimoto authored on 2011-05-23
3178
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3179

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

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

            
3184
L<DBIx::Custom>
3185

            
3186
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3187
    data_source # will be removed at 2017/1/1
3188
    dbi_options # will be removed at 2017/1/1
3189
    filter_check # will be removed at 2017/1/1
3190
    reserved_word_quote # will be removed at 2017/1/1
3191
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3192
    
3193
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3194
    create_query # will be removed at 2017/1/1
3195
    apply_filter # will be removed at 2017/1/1
3196
    select_at # will be removed at 2017/1/1
3197
    delete_at # will be removed at 2017/1/1
3198
    update_at # will be removed at 2017/1/1
3199
    insert_at # will be removed at 2017/1/1
3200
    register_tag # will be removed at 2017/1/1
3201
    default_bind_filter # will be removed at 2017/1/1
3202
    default_fetch_filter # will be removed at 2017/1/1
3203
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3204
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3205
    register_tag_processor # will be removed at 2017/1/1
3206
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3207
    
3208
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3209
    select method relation option # will be removed at 2017/1/1
3210
    select method param option # will be removed at 2017/1/1
3211
    select method column option [COLUMN, as => ALIAS] format
3212
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3213
    
3214
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3215
    execute("select * from {= title}"); # execute method's
3216
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3217
                                        # will be removed at 2017/1/1
3218
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3219

            
3220
L<DBIx::Custom::Model>
3221

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3222
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3223
    filter # will be removed at 2017/1/1
3224
    name # will be removed at 2017/1/1
3225
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3226

            
3227
L<DBIx::Custom::Query>
3228
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3229
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3230
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3231
    table # will be removed at 2017/1/1
3232
    filters # will be removed at 2017/1/1
3233
    
3234
    # Methods
3235
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3236

            
3237
L<DBIx::Custom::QueryBuilder>
3238
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3239
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3240
    tags # will be removed at 2017/1/1
3241
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3242
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3243
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3244
    register_tag # will be removed at 2017/1/1
3245
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3246
    
3247
    # Others
3248
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3249
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3250

            
3251
L<DBIx::Custom::Result>
3252
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3253
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3254
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3255
    
3256
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3257
    end_filter # will be removed at 2017/1/1
3258
    remove_end_filter # will be removed at 2017/1/1
3259
    remove_filter # will be removed at 2017/1/1
3260
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3261

            
3262
L<DBIx::Custom::Tag>
3263

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3264
    This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3265

            
3266
=head1 BACKWORD COMPATIBLE POLICY
3267

            
3268
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3269
except for attribute method.
3270
You can check all DEPRECATED functionalities by document.
3271
DEPRECATED functionality is removed after five years,
3272
but if at least one person use the functionality and tell me that thing
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3273
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3274

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

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3277
This policy was changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3278

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

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

            
3283
C<< <kimoto.yuki at gmail.com> >>
3284

            
3285
L<http://github.com/yuki-kimoto/DBIx-Custom>
3286

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3287
=head1 AUTHOR
3288

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

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

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

            
3295
This program is free software; you can redistribute it and/or modify it
3296
under the same terms as Perl itself.
3297

            
3298
=cut