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

            
prepare oracle test
Yuki Kimoto authored on 2011-08-15
4
our $VERSION = '0.1716';
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) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
199
            my $driver = $self->_driver;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
200
            my $quote = $driver eq 'odbc' ? '[]'
201
                       :$driver eq 'mysql' ? '`'
202
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
203
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
204
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
205
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
206
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
207
    }
208
}
209

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

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

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

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

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

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

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

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
302
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
303
    
cleanup
Yuki Kimoto authored on 2011-08-15
304
    # Tables
added SQL Server test
Yuki Kimoto authored on 2011-08-14
305
    my %tables;
cleanup
Yuki Kimoto authored on 2011-08-15
306
    $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
307

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

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

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
338
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
339
  allow_update_all bind_type column filter id join param prefix primary_key
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
340
  query relation sqlfilter table table_alias type type_rule_off type_rule1_off
simplified arguments check
Yuki Kimoto authored on 2011-07-11
341
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
342

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
379
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
380
    
381
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
382
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
383
    
cleanup
Yuki Kimoto authored on 2011-04-02
384
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
385
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
386
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
387
    
micro optimization
Yuki Kimoto authored on 2011-07-30
388
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
389
    $tables = $self->_remove_duplicate_table($tables, $main_table)
390
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
391
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
392
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
393
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
394
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
395
        foreach my $i (1, 2) {
396
            unless ($type_rule_off_parts->{$i}) {
397
                $type_filters->{$i} = {};
398
                foreach my $alias (keys %$table_alias) {
399
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
400
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
401
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
402
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
403
                    }
404
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
405
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
406
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
407
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
408
        }
409
    }
cleanup
Yuki Kimoto authored on 2011-04-02
410
    
micro optimization
Yuki Kimoto authored on 2011-07-30
411
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
412
    if ($self->{filter}{on}) {
413
        my $applied_filter = {};
414
        foreach my $table (@$tables) {
415
            $applied_filter = {
416
                %$applied_filter,
417
                %{$self->{filter}{out}->{$table} || {}}
418
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
419
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
420
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
421
    }
422
    
cleanup
Yuki Kimoto authored on 2011-04-02
423
    # Replace filter name to code
424
    foreach my $column (keys %$filter) {
425
        my $name = $filter->{$column};
426
        if (!defined $name) {
427
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
428
        }
cleanup
Yuki Kimoto authored on 2011-04-02
429
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
430
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
431
            unless exists $self->filters->{$name};
432
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
433
        }
434
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
435
    
cleanup
Yuki Kimoto authored on 2011-04-02
436
    # Create bind values
437
    my $bind = $self->_create_bind_values(
438
        $param,
439
        $query->columns,
440
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
441
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
442
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
443
    );
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
444

            
cleanup
yuki-kimoto authored on 2010-10-17
445
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
446
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
447
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
448
    eval {
449
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
450
            my $bind_type = $bind->[$i]->{bind_type};
451
            $sth->bind_param(
452
                $i + 1,
453
                $bind->[$i]->{value},
454
                $bind_type ? $bind_type : ()
455
            );
cleanup
Yuki Kimoto authored on 2011-03-21
456
        }
457
        $affected = $sth->execute;
458
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
459
    
micro optimization
Yuki Kimoto authored on 2011-07-30
460
    $self->_croak($@, qq{. Following SQL is executed.\n}
461
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
462
    
improved debug message
Yuki Kimoto authored on 2011-05-23
463
    # DEBUG message
464
    if (DEBUG) {
465
        print STDERR "SQL:\n" . $query->sql . "\n";
466
        my @output;
467
        foreach my $b (@$bind) {
468
            my $value = $b->{value};
469
            $value = 'undef' unless defined $value;
470
            $value = encode(DEBUG_ENCODING(), $value)
471
              if utf8::is_utf8($value);
472
            push @output, $value;
473
        }
474
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
475
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
476
    
cleanup
Yuki Kimoto authored on 2011-04-02
477
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
478
    if ($sth->{NUM_OF_FIELDS}) {
479
        
micro optimization
Yuki Kimoto authored on 2011-07-30
480
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
481
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
482
        if ($self->{filter}{on}) {
483
            $filter->{in}  = {};
484
            $filter->{end} = {};
485
            push @$tables, $main_table if $main_table;
486
            foreach my $table (@$tables) {
487
                foreach my $way (qw/in end/) {
488
                    $filter->{$way} = {
489
                        %{$filter->{$way}},
490
                        %{$self->{filter}{$way}{$table} || {}}
491
                    };
492
                }
cleanup
Yuki Kimoto authored on 2011-04-02
493
            }
cleanup
Yuki Kimoto authored on 2011-01-12
494
        }
495
        
496
        # Result
497
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
498
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
499
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
500
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
501
            filter => $filter->{in} || {},
502
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
503
            type_rule => {
504
                from1 => $self->type_rule->{from1},
505
                from2 => $self->type_rule->{from2}
506
            },
cleanup
yuki-kimoto authored on 2010-10-17
507
        );
508

            
509
        return $result;
510
    }
cleanup
Yuki Kimoto authored on 2011-04-02
511
    
512
    # Not select statement
513
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
514
}
515

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
775
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
776
sub not_exists { $not_exists }
777

            
778
sub order {
779
    my $self = shift;
780
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
781
}
782

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

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

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

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

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

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

            
949
    my $columns = $sth->{NAME};
950
    my $data_types = $sth->{TYPE};
951
    
952
    for (my $i = 0; $i < @$columns; $i++) {
953
        my $column = $columns->[$i];
954
        my $data_type = $data_types->[$i];
955
        print "$column: $data_type\n";
956
    }
957
}
958

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
974
sub show_tables {
975
    my $self = shift;
976
    
977
    my %tables;
978
    $self->each_table(sub { $tables{$_[1]}++ });
979
    print join("\n", sort keys %tables) . "\n";
980
    return $self;
981
}
982

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1117
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1118
}
1119

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

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

            
1148
        # Create query
1149
        my $builder = $self->query_builder;
1150
        $query = $builder->build_query($source);
1151

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

            
1158
        # Save query to cache
1159
        $self->cache_method->(
1160
            $self, $source,
1161
            {
1162
                sql     => $query->sql, 
1163
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1164
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1165
            }
1166
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1167
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1168

            
1169
    # Filter SQL
1170
    if ($sqlfilter) {
1171
        my $sql = $query->sql;
1172
        $sql = $sqlfilter->($sql);
1173
        $query->sql($sql);
1174
    }
1175
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1176
    # Save sql
1177
    $self->last_sql($query->sql);
1178
    
updated pod
Yuki Kimoto authored on 2011-06-21
1179
    # Prepare statement handle
1180
    my $sth;
1181
    eval { $sth = $self->dbh->prepare($query->{sql})};
1182
    
1183
    if ($@) {
1184
        $self->_croak($@, qq{. Following SQL is executed.\n}
1185
                        . qq{$query->{sql}\n} . _subname);
1186
    }
1187
    
1188
    # Set statement handle
1189
    $query->sth($sth);
1190
    
1191
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1192
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1193
    
1194
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1195
}
1196

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

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

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

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

            
prepare oracle test
Yuki Kimoto authored on 2011-08-15
1321
sub _driver { lc shift->{dbh}->{Driver}->{Name} }
1322

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1323
sub _need_tables {
1324
    my ($self, $tree, $need_tables, $tables) = @_;
1325
    
cleanup
Yuki Kimoto authored on 2011-04-02
1326
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1327
    foreach my $table (@$tables) {
1328
        if ($tree->{$table}) {
1329
            $need_tables->{$table} = 1;
1330
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1331
        }
1332
    }
1333
}
1334

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1335
sub _push_join {
1336
    my ($self, $sql, $join, $join_tables) = @_;
1337
    
cleanup
Yuki Kimoto authored on 2011-04-02
1338
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1339
    return unless @$join;
1340
    
cleanup
Yuki Kimoto authored on 2011-04-02
1341
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1342
    my $tree = {};
1343
    for (my $i = 0; $i < @$join; $i++) {
1344
        
cleanup
Yuki Kimoto authored on 2011-07-28
1345
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1346
        my $join_clause;;
1347
        my $option;
1348
        if (ref $join->[$i] eq 'HASH') {
1349
            $join_clause = $join->[$i]->{clause};
1350
            $option = {table => $join->[$i]->{table}};
1351
        }
1352
        else {
1353
            $join_clause = $join->[$i];
1354
            $option = {};
1355
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1356

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1400
sub _quote {
1401
    my $self = shift;
1402
    
1403
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1404
         : defined $self->quote ? $self->quote
1405
         : '';
1406
}
1407

            
cleanup
Yuki Kimoto authored on 2011-07-29
1408
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1409
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1410
    
1411
    my $quote = $self->_quote;
1412
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1413
    my $p;
1414
    if (defined $quote && length $quote > 1) {
1415
        $p = substr($quote, 1, 1);
1416
    }
1417
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1418
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1419
    if ($quotemeta) {
1420
        $q = quotemeta($q);
1421
        $p = quotemeta($p);
1422
    }
1423
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1424
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1425
}
1426

            
cleanup
Yuki Kimoto authored on 2011-04-02
1427
sub _remove_duplicate_table {
1428
    my ($self, $tables, $main_table) = @_;
1429
    
1430
    # Remove duplicate table
1431
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1432
    delete $tables{$main_table} if $main_table;
1433
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1434
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1435
    if (my $q = $self->_quote) {
1436
        $q = quotemeta($q);
1437
        $_ =~ s/[$q]//g for @$new_tables;
1438
    }
1439

            
1440
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1441
}
1442

            
cleanup
Yuki Kimoto authored on 2011-04-02
1443
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1444
    my ($self, $source) = @_;
1445
    
cleanup
Yuki Kimoto authored on 2011-04-02
1446
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1447
    my $tables = [];
1448
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1449
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1450
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1451
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1452
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1453
    while ($source =~ /$table_re/g) {
1454
        push @$tables, $1;
1455
    }
1456
    
1457
    return $tables;
1458
}
1459

            
cleanup
Yuki Kimoto authored on 2011-04-02
1460
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1461
    my ($self, $where) = @_;
1462
    
cleanup
Yuki Kimoto authored on 2011-04-02
1463
    my $obj;
1464
    
1465
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1466
    if (ref $where eq 'HASH') {
1467
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1468
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1469
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1470
            my $table;
1471
            my $c;
1472
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1473
                $table = $1;
1474
                $c = $2;
1475
            }
1476
            
1477
            my $table_quote;
1478
            $table_quote = $self->_q($table) if defined $table;
1479
            my $column_quote = $self->_q($c);
1480
            $column_quote = $table_quote . '.' . $column_quote
1481
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1482
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1483
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1484
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1485
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1486
    
1487
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1488
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1489
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1490
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1491
    
updated pod
Yuki Kimoto authored on 2011-06-21
1492
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1493
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1494
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1495
            clause => $where->[0],
1496
            param  => $where->[1]
1497
        );
1498
    }
1499
    
cleanup
Yuki Kimoto authored on 2011-04-02
1500
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1501
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1502
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1503
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1504
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1505
    
cleanup
Yuki Kimoto authored on 2011-04-02
1506
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1507
}
1508

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

            
1512
    # Initialize filters
1513
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1514
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1515
    $self->{filter}{out} ||= {};
1516
    $self->{filter}{in} ||= {};
1517
    $self->{filter}{end} ||= {};
1518
    
1519
    # Usage
1520
    my $usage = "Usage: \$dbi->apply_filter(" .
1521
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1522
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1523
    
1524
    # Apply filter
1525
    for (my $i = 0; $i < @cinfos; $i += 2) {
1526
        
1527
        # Column
1528
        my $column = $cinfos[$i];
1529
        if (ref $column eq 'ARRAY') {
1530
            foreach my $c (@$column) {
1531
                push @cinfos, $c, $cinfos[$i + 1];
1532
            }
1533
            next;
1534
        }
1535
        
1536
        # Filter infomation
1537
        my $finfo = $cinfos[$i + 1] || {};
1538
        croak "$usage (table: $table) " . _subname
1539
          unless  ref $finfo eq 'HASH';
1540
        foreach my $ftype (keys %$finfo) {
1541
            croak "$usage (table: $table) " . _subname
1542
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1543
        }
1544
        
1545
        # Set filters
1546
        foreach my $way (qw/in out end/) {
1547
        
1548
            # Filter
1549
            my $filter = $finfo->{$way};
1550
            
1551
            # Filter state
1552
            my $state = !exists $finfo->{$way} ? 'not_exists'
1553
                      : !defined $filter        ? 'not_defined'
1554
                      : ref $filter eq 'CODE'   ? 'code'
1555
                      : 'name';
1556
            
1557
            # Filter is not exists
1558
            next if $state eq 'not_exists';
1559
            
1560
            # Check filter name
1561
            croak qq{Filter "$filter" is not registered } . _subname
1562
              if  $state eq 'name'
1563
               && ! exists $self->filters->{$filter};
1564
            
1565
            # Set filter
1566
            my $f = $state eq 'not_defined' ? undef
1567
                  : $state eq 'code'        ? $filter
1568
                  : $self->filters->{$filter};
1569
            $self->{filter}{$way}{$table}{$column} = $f;
1570
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1571
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1572
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1573
        }
1574
    }
1575
    
1576
    return $self;
1577
}
1578

            
1579
# DEPRECATED!
1580
sub create_query {
1581
    warn "create_query is DEPRECATED! use query option of each method";
1582
    shift->_create_query(@_);
1583
}
1584

            
cleanup
Yuki Kimoto authored on 2011-06-13
1585
# DEPRECATED!
1586
sub apply_filter {
1587
    my $self = shift;
1588
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1589
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1590
    return $self->_apply_filter(@_);
1591
}
1592

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1600
    # Arguments
1601
    my $primary_keys = delete $args{primary_key};
1602
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1603
    my $where = delete $args{where};
1604
    my $param = delete $args{param};
1605
    
1606
    # Check arguments
1607
    foreach my $name (keys %args) {
1608
        croak qq{"$name" is wrong option } . _subname
1609
          unless $SELECT_AT_ARGS{$name};
1610
    }
1611
    
1612
    # Table
1613
    croak qq{"table" option must be specified } . _subname
1614
      unless $args{table};
1615
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1616
    
1617
    # Create where parameter
1618
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1619
    
1620
    return $self->select(where => $where_param, %args);
1621
}
1622

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

            
1628
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1629
    
1630
    # Arguments
1631
    my $primary_keys = delete $args{primary_key};
1632
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1633
    my $where = delete $args{where};
1634
    
1635
    # Check arguments
1636
    foreach my $name (keys %args) {
1637
        croak qq{"$name" is wrong option } . _subname
1638
          unless $DELETE_AT_ARGS{$name};
1639
    }
1640
    
1641
    # Create where parameter
1642
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1643
    
1644
    return $self->delete(where => $where_param, %args);
1645
}
1646

            
cleanup
Yuki Kimoto authored on 2011-06-08
1647
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1648
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1649
sub update_at {
1650
    my $self = shift;
1651

            
1652
    warn "update_at is DEPRECATED! use update and id option instead";
1653
    
1654
    # Arguments
1655
    my $param;
1656
    $param = shift if @_ % 2;
1657
    my %args = @_;
1658
    my $primary_keys = delete $args{primary_key};
1659
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1660
    my $where = delete $args{where};
1661
    my $p = delete $args{param} || {};
1662
    $param  ||= $p;
1663
    
1664
    # Check arguments
1665
    foreach my $name (keys %args) {
1666
        croak qq{"$name" is wrong option } . _subname
1667
          unless $UPDATE_AT_ARGS{$name};
1668
    }
1669
    
1670
    # Create where parameter
1671
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1672
    
1673
    return $self->update(where => $where_param, param => $param, %args);
1674
}
1675

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1676
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1677
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1678
sub insert_at {
1679
    my $self = shift;
1680
    
1681
    warn "insert_at is DEPRECATED! use insert and id option instead";
1682
    
1683
    # Arguments
1684
    my $param;
1685
    $param = shift if @_ % 2;
1686
    my %args = @_;
1687
    my $primary_key = delete $args{primary_key};
1688
    $primary_key = [$primary_key] unless ref $primary_key;
1689
    my $where = delete $args{where};
1690
    my $p = delete $args{param} || {};
1691
    $param  ||= $p;
1692
    
1693
    # Check arguments
1694
    foreach my $name (keys %args) {
1695
        croak qq{"$name" is wrong option } . _subname
1696
          unless $INSERT_AT_ARGS{$name};
1697
    }
1698
    
1699
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1700
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1701
    $param = $self->merge_param($where_param, $param);
1702
    
1703
    return $self->insert(param => $param, %args);
1704
}
1705

            
added warnings
Yuki Kimoto authored on 2011-06-07
1706
# DEPRECATED!
1707
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1708
    my $self = shift;
1709
    
added warnings
Yuki Kimoto authored on 2011-06-07
1710
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1711
    
1712
    # Merge tag
1713
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1714
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1715
    
1716
    return $self;
1717
}
1718

            
1719
# DEPRECATED!
1720
sub register_tag_processor {
1721
    my $self = shift;
1722
    warn "register_tag_processor is DEPRECATED!";
1723
    # Merge tag
1724
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1725
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1726
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1727
}
1728

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1729
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1730
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1731
has dbi_options => sub { {} };
1732
has filter_check  => 1;
1733
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1734

            
cleanup
Yuki Kimoto authored on 2011-01-25
1735
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1736
sub default_bind_filter {
1737
    my $self = shift;
1738
    
cleanup
Yuki Kimoto authored on 2011-06-13
1739
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1740
    
cleanup
Yuki Kimoto authored on 2011-01-12
1741
    if (@_) {
1742
        my $fname = $_[0];
1743
        
1744
        if (@_ && !$fname) {
1745
            $self->{default_out_filter} = undef;
1746
        }
1747
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1748
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1749
              unless exists $self->filters->{$fname};
1750
        
1751
            $self->{default_out_filter} = $self->filters->{$fname};
1752
        }
1753
        return $self;
1754
    }
1755
    
1756
    return $self->{default_out_filter};
1757
}
1758

            
cleanup
Yuki Kimoto authored on 2011-01-25
1759
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1760
sub default_fetch_filter {
1761
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1762

            
cleanup
Yuki Kimoto authored on 2011-06-13
1763
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1764
    
1765
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1766
        my $fname = $_[0];
1767

            
cleanup
Yuki Kimoto authored on 2011-01-12
1768
        if (@_ && !$fname) {
1769
            $self->{default_in_filter} = undef;
1770
        }
1771
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1772
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1773
              unless exists $self->filters->{$fname};
1774
        
1775
            $self->{default_in_filter} = $self->filters->{$fname};
1776
        }
1777
        
1778
        return $self;
1779
    }
1780
    
many changed
Yuki Kimoto authored on 2011-01-23
1781
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1782
}
1783

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1784
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1785
sub insert_param_tag {
1786
    warn "insert_param_tag is DEPRECATED! " .
1787
         "use insert_param instead!";
1788
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1789
}
1790

            
1791
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1792
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1793
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1794
         "use update_param instead";
1795
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1796
}
cleanup
Yuki Kimoto authored on 2011-03-08
1797
# DEPRECATED!
1798
sub _push_relation {
1799
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1800
    
1801
    if (keys %{$relation || {}}) {
1802
        push @$sql, $need_where ? 'where' : 'and';
1803
        foreach my $rcolumn (keys %$relation) {
1804
            my $table1 = (split (/\./, $rcolumn))[0];
1805
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1806
            push @$tables, ($table1, $table2);
1807
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1808
        }
1809
    }
1810
    pop @$sql if $sql->[-1] eq 'and';    
1811
}
1812

            
1813
# DEPRECATED!
1814
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1815
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1816
    
1817
    if (keys %{$relation || {}}) {
1818
        foreach my $rcolumn (keys %$relation) {
1819
            my $table1 = (split (/\./, $rcolumn))[0];
1820
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1821
            my $table1_exists;
1822
            my $table2_exists;
1823
            foreach my $table (@$tables) {
1824
                $table1_exists = 1 if $table eq $table1;
1825
                $table2_exists = 1 if $table eq $table2;
1826
            }
1827
            unshift @$tables, $table1 unless $table1_exists;
1828
            unshift @$tables, $table2 unless $table2_exists;
1829
        }
1830
    }
1831
}
1832

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1835
=head1 NAME
1836

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

            
1839
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1840

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1841
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1842
    
1843
    # Connect
1844
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1845
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1846
        user => 'ken',
1847
        password => '!LFKD%$&',
1848
        dbi_option => {mysql_enable_utf8 => 1}
1849
    );
cleanup
yuki-kimoto authored on 2010-08-05
1850

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1851
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1852
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1853
    
1854
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1855
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1856
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1857
    
1858
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1859
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1860

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1865
    # Select, more complex
1866
    my $result = $dbi->select(
1867
        table  => 'book',
1868
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1869
            {book => [qw/title author/]},
1870
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1871
        ],
1872
        where  => {'book.author' => 'Ken'},
1873
        join => ['left outer join company on book.company_id = company.id'],
1874
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1875
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1876
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1877
    # Fetch
1878
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1879
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1880
    }
1881
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1882
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1883
    while (my $row = $result->fetch_hash) {
1884
        
1885
    }
1886
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1887
    # Execute SQL with parameter.
1888
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1889
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1890
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1891
    );
1892
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1893
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1894

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1910
Named place holder support
1911

            
1912
=item *
1913

            
cleanup
Yuki Kimoto authored on 2011-07-29
1914
Model support
1915

            
1916
=item *
1917

            
1918
Connection manager support
1919

            
1920
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1921

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

            
1926
=item *
1927

            
1928
Filtering by data type or column name(EXPERIMENTAL)
1929

            
1930
=item *
1931

            
1932
Create C<order by> clause flexibly(EXPERIMENTAL)
1933

            
1934
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1935

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1943
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1944
L<DBIx::Custom::Result>,
1945
L<DBIx::Custom::Query>,
1946
L<DBIx::Custom::Where>,
1947
L<DBIx::Custom::Model>,
1948
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1949

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

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

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

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

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

            
1963
    my $connector = DBIx::Connector->new(
1964
        "dbi:mysql:database=$DATABASE",
1965
        $USER,
1966
        $PASSWORD,
1967
        DBIx::Custom->new->default_dbi_option
1968
    );
1969
    
updated pod
Yuki Kimoto authored on 2011-06-21
1970
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1971

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

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

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

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

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

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

            
1987
=head2 C<default_dbi_option>
1988

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1995
    {
1996
        RaiseError => 1,
1997
        PrintError => 0,
1998
        AutoCommit => 1,
1999
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2000

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

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

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

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

            
2010
    my $last_sql = $dbi->last_sql;
2011
    $dbi = $dbi->last_sql($last_sql);
2012

            
2013
Get last successed SQL executed by C<execute> method.
2014

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2022
=head2 C<password>
2023

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2044
You can set quote pair.
2045

            
2046
    $dbi->quote('[]');
2047

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

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

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

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

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

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

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

            
2065
    my $separator = $self->separator;
2066
    $dbi = $self->separator($separator);
2067

            
2068
Separator whichi join table and column.
2069
This is used by C<column> and C<mycolumn> method.
2070

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

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

            
2076
Regex matching system table.
2077
this regex match is used by C<each_table> method and C<each_column> method
2078
System table is ignored.
2079
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2080
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2081
The performance is up.
2082

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

            
2085
    my $tag_parse = $dbi->tag_parse(0);
2086
    $dbi = $dbi->tag_parse;
2087

            
2088
Enable DEPRECATED tag parsing functionality, default to 1.
2089
If you want to disable tag parsing functionality, set to 0.
2090

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2132
Create column clause. The follwoing column clause is created.
2133

            
2134
    book.author as "book.author",
2135
    book.title as "book.title"
2136

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2139
    # Separator is double underbar
2140
    $dbi->separator('__');
2141
    
2142
    book.author as "book__author",
2143
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2144

            
cleanup
Yuki Kimoto authored on 2011-06-13
2145
    # Separator is hyphen
2146
    $dbi->separator('-');
2147
    
2148
    book.author as "book-author",
2149
    book.title as "book-title"
2150
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2151
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2152

            
update pod
Yuki Kimoto authored on 2011-03-13
2153
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2154
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2155
        user => 'ken',
2156
        password => '!LFKD%$&',
2157
        dbi_option => {mysql_enable_utf8 => 1}
2158
    );
2159

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2168
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2169
        table => 'book',
2170
        primary_key => 'id',
2171
        join => [
2172
            'inner join company on book.comparny_id = company.id'
2173
        ],
2174
    );
2175

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

            
2179
   $dbi->model('book')->select(...);
2180

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

            
2183
    my $dbh = $dbi->dbh;
2184

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

            
2188
=head2 C<each_column>
2189

            
2190
    $dbi->each_column(
2191
        sub {
2192
            my ($dbi, $table, $column, $column_info) = @_;
2193
            
2194
            my $type = $column_info->{TYPE_NAME};
2195
            
2196
            if ($type eq 'DATE') {
2197
                # ...
2198
            }
2199
        }
2200
    );
2201

            
2202
Iterate all column informations of all table from database.
2203
Argument is callback when one column is found.
2204
Callback receive four arguments, dbi object, table name,
2205
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2206

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

            
2209
    $dbi->each_table(
2210
        sub {
2211
            my ($dbi, $table, $table_info) = @_;
2212
            
2213
            my $table_name = $table_info->{TABLE_NAME};
2214
        }
2215
    );
2216

            
2217
Iterate all table informationsfrom database.
2218
Argument is callback when one table is found.
2219
Callback receive three arguments, dbi object, table name,
2220
table information.
2221

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

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

            
2229
    my $result = $dbi->execute(
2230
      "select * from book where title = :book.title and author like :book.author",
2231
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2232
    );
2233

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2240
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2241
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2242
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2243
    select * from book where title = :title and author like :author
2244
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2245
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2246
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2247

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2251
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2252
    select * from book where :title{=} and :author{like}
2253
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2254
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2255
    select * from where title = ? and author like ?;
2256

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

            
2261
    select * from where title = "aa\\:bb";
2262

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

            
2265
=over 4
2266

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2267
=item C<bind_type>
2268

            
2269
Specify database bind data type.
2270

            
2271
    bind_type => [image => DBI::SQL_BLOB]
2272
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2273

            
2274
This is used to bind parameter by C<bind_param> of statment handle.
2275

            
2276
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2277

            
update pod
Yuki Kimoto authored on 2011-03-13
2278
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2279
    
2280
    filter => {
2281
        title  => sub { uc $_[0] }
2282
        author => sub { uc $_[0] }
2283
    }
update pod
Yuki Kimoto authored on 2011-03-13
2284

            
updated pod
Yuki Kimoto authored on 2011-06-09
2285
    # Filter name
2286
    filter => {
2287
        title  => 'upper_case',
2288
        author => 'upper_case'
2289
    }
2290
        
2291
    # At once
2292
    filter => [
2293
        [qw/title author/]  => sub { uc $_[0] }
2294
    ]
2295

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

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

            
2303
    query => 1
2304

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

            
2308
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2309
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2310
    my $columns = $query->columns;
2311
    
2312
If you want to execute SQL fast, you can do the following way.
2313

            
2314
    my $query;
2315
    foreach my $row (@$rows) {
2316
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2317
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2318
    }
2319

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

            
2323
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
2324
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2325
    
2326
    my $query;
2327
    my $sth;
2328
    foreach my $row (@$rows) {
2329
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2330
      $sth ||= $query->sth;
2331
      $sth->execute(map { $row->{$_} } sort keys %$row);
2332
    }
2333

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2338
=item C<sqlfilter EXPERIMENTAL> 
2339

            
2340
SQL filter function.
2341

            
2342
    sqlfilter => $code_ref
2343

            
2344
This option is generally for Oracle and SQL Server paging process.
2345
    
2346
    my $limit = sub {
2347
        my ($sql, $count, $offset) = @_;
2348
        
2349
        my $min = $offset + 1;
2350
        my $max = $offset + $count;
2351
        
2352
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2353
        
2354
        return $sql;
2355
    }
2356
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2357
        my $sql = shift;
2358
        return $limit->($sql, 100, 50);
2359
    })
2360

            
updated pod
Yuki Kimoto authored on 2011-06-09
2361
=item C<table>
2362
    
2363
    table => 'author'
2364

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2372
    # Same
2373
    $dbi->execute(
2374
      "select * from book where title = :book.title and author = :book.author",
2375
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2376

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

            
2379
    table_alias => {user => 'hiker'}
2380

            
2381
Table alias. Key is real table name, value is alias table name.
2382
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2383
on alias table name.
2384

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

            
2387
    type_rule_off => 1
2388

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

            
2391
=item C<type_rule1_off> EXPERIMENTAL
2392

            
2393
    type_rule1_off => 1
2394

            
2395
Turn C<into1> type rule off.
2396

            
2397
=item C<type_rule2_off> EXPERIMENTAL
2398

            
2399
    type_rule2_off => 1
2400

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2413
=over 4
2414

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

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

            
2419
=item C<filter>
2420

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2425
    id => 4
2426
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2427

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2431
    $dbi->delete(
2432
        parimary_key => ['id1', 'id2'],
2433
        id => [4, 5],
2434
        table => 'book',
2435
    );
update pod
Yuki Kimoto authored on 2011-03-13
2436

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

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

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

            
2443
    prefix => 'some'
2444

            
2445
prefix before table name section.
2446

            
2447
    delete some from book
2448

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2453
=item C<sqlfilter EXPERIMENTAL>
2454

            
2455
Same as C<execute> method's C<sqlfilter> option.
2456

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2461
Table name.
2462

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

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

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

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

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

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

            
2475
=item C<type_rule_off> EXPERIMENTAL
2476

            
2477
Same as C<execute> method's C<type_rule_off> option.
2478

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

            
2481
    type_rule1_off => 1
2482

            
2483
Same as C<execute> method's C<type_rule1_off> option.
2484

            
2485
=item C<type_rule2_off> EXPERIMENTAL
2486

            
2487
    type_rule2_off => 1
2488

            
2489
Same as C<execute> method's C<type_rule2_off> option.
2490

            
updated pod
Yuki Kimoto authored on 2011-06-08
2491
=back
update pod
Yuki Kimoto authored on 2011-03-13
2492

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2500
=head2 C<insert>
2501

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

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

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

            
2510
    {date => \"NOW()"}
2511

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2520
=item C<bind_type>
2521

            
2522
Same as C<execute> method's C<bind_type> option.
2523

            
update pod
Yuki Kimoto authored on 2011-03-13
2524
=item C<filter>
2525

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

            
2528
=item C<id>
2529

            
updated document
Yuki Kimoto authored on 2011-06-09
2530
    id => 4
2531
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2532

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2536
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2537
        {title => 'Perl', author => 'Ken'}
2538
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2539
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2540
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2541
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2542

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

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

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

            
2552
    prefix => 'or replace'
2553

            
2554
prefix before table name section
2555

            
2556
    insert or replace into book
2557

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

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

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

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

            
2567
Same as C<execute> method's C<query> option.
2568

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2569
=item C<sqlfilter EXPERIMENTAL>
2570

            
2571
Same as C<execute> method's C<sqlfilter> option.
2572

            
updated document
Yuki Kimoto authored on 2011-06-09
2573
=item C<table>
2574

            
2575
    table => 'book'
2576

            
2577
Table name.
2578

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

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

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

            
2585
    type_rule1_off => 1
2586

            
2587
Same as C<execute> method's C<type_rule1_off> option.
2588

            
2589
=item C<type_rule2_off> EXPERIMENTAL
2590

            
2591
    type_rule2_off => 1
2592

            
2593
Same as C<execute> method's C<type_rule2_off> option.
2594

            
update pod
Yuki Kimoto authored on 2011-03-13
2595
=back
2596

            
2597
=over 4
2598

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2614
    lib / MyModel.pm
2615
        / MyModel / book.pm
2616
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2617

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

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

            
2622
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2623
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2624
    
2625
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2626

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2631
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2632
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2633
    
2634
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2635

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2638
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2639
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2640
    
2641
    1;
2642
    
updated pod
Yuki Kimoto authored on 2011-06-21
2643
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2644

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

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

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

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

            
2654
    my $map_param = $dbi->map_param(
2655
        {id => 1, authro => 'Ken', price => 1900},
2656
        'id' => 'book.id',
2657
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2658
        'price' => [
2659
            'book.price', {if => sub { length $_[0] }}
2660
        ]
2661
    );
2662

            
2663
Map paramters to other key and value. First argument is original
2664
parameter. this is hash reference. Rest argument is mapping.
2665
By default, Mapping is done if the value length is not zero.
2666

            
2667
=over 4
2668

            
2669
=item Key mapping
2670

            
2671
    'id' => 'book.id'
2672

            
2673
This is only key mapping. Value is same as original one.
2674

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

            
2677
=item Key and value mapping
2678

            
2679
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2680

            
2681
This is key and value mapping. Frist element of array reference
2682
is mapped key name, second element is code reference to map the value.
2683

            
2684
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2685
      if value length is not zero.
2686

            
2687
=item Condition
2688

            
2689
    'price' => ['book.price', {if => 'exists'}]
2690
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2691
    'price' => ['book.price', {if => sub { defined shift }}]
2692

            
2693
If you need condition, you can sepecify it. this is code reference
2694
or 'exists'. By default, condition is the following one.
2695

            
2696
    sub { defined $_[0] && length $_[0] }
2697

            
2698
=back
2699

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

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

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

            
2706
    {key1 => [1, 1], key2 => 2}
2707

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

            
2710
    $dbi->method(
2711
        update_or_insert => sub {
2712
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2713
            
2714
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2715
        },
2716
        find_or_create   => sub {
2717
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2718
            
2719
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2720
        }
2721
    );
2722

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

            
2725
    $dbi->update_or_insert;
2726
    $dbi->find_or_create;
2727

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

            
2730
    my $model = $dbi->model('book');
2731

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

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

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

            
2738
Create column clause for myself. The follwoing column clause is created.
2739

            
2740
    book.author as author,
2741
    book.title as title
2742

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2745
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2746
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2747
        user => 'ken',
2748
        password => '!LFKD%$&',
2749
        dbi_option => {mysql_enable_utf8 => 1}
2750
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2751

            
2752
Create a new L<DBIx::Custom> object.
2753

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

            
2756
    my $not_exists = $dbi->not_exists;
2757

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

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

            
2763
    my $order = $dbi->order;
2764

            
2765
Create a new L<DBIx::Custom::Order> object.
2766

            
cleanup
yuki-kimoto authored on 2010-10-17
2767
=head2 C<register_filter>
2768

            
update pod
Yuki Kimoto authored on 2011-03-13
2769
    $dbi->register_filter(
2770
        # Time::Piece object to database DATE format
2771
        tp_to_date => sub {
2772
            my $tp = shift;
2773
            return $tp->strftime('%Y-%m-%d');
2774
        },
2775
        # database DATE format to Time::Piece object
2776
        date_to_tp => sub {
2777
           my $date = shift;
2778
           return Time::Piece->strptime($date, '%Y-%m-%d');
2779
        }
2780
    );
cleanup
yuki-kimoto authored on 2010-10-17
2781
    
update pod
Yuki Kimoto authored on 2011-03-13
2782
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2783

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

            
2786
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2787
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2788
            date => sub { ... },
2789
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2790
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2791
        into2 => {
2792
            date => sub { ... },
2793
            datetime => sub { ... }
2794
        },
2795
        from1 => {
2796
            # DATE
2797
            9 => sub { ... },
2798
            # DATETIME or TIMESTAMP
2799
            11 => sub { ... },
2800
        }
2801
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2802
            # DATE
2803
            9 => sub { ... },
2804
            # DATETIME or TIMESTAMP
2805
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2806
        }
2807
    );
2808

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2824
=over 4
2825

            
2826
=item 1. column name
2827

            
2828
    issue_date
2829
    issue_datetime
2830

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

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

            
2835
    book.issue_date
2836
    book.issue_datetime
2837

            
2838
=back
2839

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

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

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

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

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

            
2852
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2853
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2854
            [qw/DATE DATETIME/] => sub { ... },
2855
        ],
2856
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2857

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2860
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2861
        table  => 'book',
2862
        column => ['author', 'title'],
2863
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2864
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2865
    
updated document
Yuki Kimoto authored on 2011-06-09
2866
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2867

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

            
2870
=over 4
2871

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2876
Append statement to last of SQL.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2877

            
2878
=item C<bind_type>
2879

            
2880
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
2881
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2882
=item C<column>
2883
    
updated document
Yuki Kimoto authored on 2011-06-09
2884
    column => 'author'
2885
    column => ['author', 'title']
2886

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2895
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2896
        {book => [qw/author title/]},
2897
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2898
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2899

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

            
2902
    book.author as "book.author",
2903
    book.title as "book.title",
2904
    person.name as "person.name",
2905
    person.age as "person.age"
2906

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

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

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

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

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

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

            
2922
=item C<id>
2923

            
2924
    id => 4
2925
    id => [4, 5]
2926

            
2927
ID corresponding to C<primary_key>.
2928
You can select rows by C<id> and C<primary_key>.
2929

            
2930
    $dbi->select(
2931
        parimary_key => ['id1', 'id2'],
2932
        id => [4, 5],
2933
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2934
    );
2935

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2938
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2939
        where => {id1 => 4, id2 => 5},
2940
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2941
    );
2942
    
updated document
Yuki Kimoto authored on 2011-06-09
2943
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2944

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

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

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

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

            
2957
    prefix => 'SQL_CALC_FOUND_ROWS'
2958

            
2959
Prefix of column cluase
2960

            
2961
    select SQL_CALC_FOUND_ROWS title, author from book;
2962

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

            
2965
    join => [
2966
        'left outer join company on book.company_id = company_id',
2967
        'left outer join location on company.location_id = location.id'
2968
    ]
2969
        
2970
Join clause. If column cluase or where clause contain table name like "company.name",
2971
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2972

            
2973
    $dbi->select(
2974
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2975
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2976
        where => {'company.name' => 'Orange'},
2977
        join => [
2978
            'left outer join company on book.company_id = company.id',
2979
            'left outer join location on company.location_id = location.id'
2980
        ]
2981
    );
2982

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2986
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2987
    from book
2988
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2989
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2990

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

            
2994
    $dbi->select(
2995
        table => 'book',
2996
        column => ['company.location_id as location_id'],
2997
        where => {'company.name' => 'Orange'},
2998
        join => [
2999
            {
3000
                clause => 'left outer join location on company.location_id = location.id',
3001
                table => ['company', 'location']
3002
            }
3003
        ]
3004
    );
3005

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

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3017
=item C<sqlfilter EXPERIMENTAL>
updated pod
Yuki Kimoto authored on 2011-06-08
3018

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3019
Same as C<execute> method's C<sqlfilter> option
updated pod
Yuki Kimoto authored on 2011-06-08
3020

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3025
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3026

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

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

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

            
3033
    type_rule1_off => 1
3034

            
3035
Same as C<execute> method's C<type_rule1_off> option.
3036

            
3037
=item C<type_rule2_off> EXPERIMENTAL
3038

            
3039
    type_rule2_off => 1
3040

            
3041
Same as C<execute> method's C<type_rule2_off> option.
3042

            
updated document
Yuki Kimoto authored on 2011-06-09
3043
=item C<where>
3044
    
3045
    # Hash refrence
3046
    where => {author => 'Ken', 'title' => 'Perl'}
3047
    
3048
    # DBIx::Custom::Where object
3049
    where => $dbi->where(
3050
        clause => ['and', 'author = :author', 'title like :title'],
3051
        param  => {author => 'Ken', title => '%Perl%'}
3052
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3053
    
3054
    # Array reference 1 (array reference, hash referenc). same as above
3055
    where => [
3056
        ['and', 'author = :author', 'title like :title'],
3057
        {author => 'Ken', title => '%Perl%'}
3058
    ];    
3059
    
3060
    # Array reference 2 (String, hash reference)
3061
    where => [
3062
        'title like :title',
3063
        {title => '%Perl%'}
3064
    ]
3065
    
3066
    # String
3067
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3068

            
updated document
Yuki Kimoto authored on 2011-06-09
3069
Where clause.
3070
    
improved pod
Yuki Kimoto authored on 2011-04-19
3071
=item C<wrap> EXPERIMENTAL
3072

            
3073
Wrap statement. This is array reference.
3074

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3075
    wrap => ['select * from (', ') as t where ROWNUM < 10']
improved pod
Yuki Kimoto authored on 2011-04-19
3076

            
3077
This option is for Oracle and SQL Server paging process.
3078

            
update pod
Yuki Kimoto authored on 2011-03-12
3079
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3080

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

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

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

            
3087
If you want to set constant value to row data, use scalar reference
3088
as parameter value.
3089

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3094
=over 4
3095

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3100
=item C<bind_type>
3101

            
3102
Same as C<execute> method's C<bind_type> option.
3103

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3110
    id => 4
3111
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3112

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3116
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3117
        {title => 'Perl', author => 'Ken'}
3118
        parimary_key => ['id1', 'id2'],
3119
        id => [4, 5],
3120
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3121
    );
update pod
Yuki Kimoto authored on 2011-03-13
3122

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3125
    $dbi->update(
3126
        {title => 'Perl', author => 'Ken'}
3127
        where => {id1 => 4, id2 => 5},
3128
        table => 'book'
3129
    );
update pod
Yuki Kimoto authored on 2011-03-13
3130

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

            
3133
    prefix => 'or replace'
3134

            
3135
prefix before table name section
3136

            
3137
    update or replace book
3138

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

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3150
=item C<sqlfilter EXPERIMENTAL>
3151

            
3152
Same as C<execute> method's C<sqlfilter> option.
3153

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

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

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

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

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

            
3164
=item C<type_rule1_off> EXPERIMENTAL
3165

            
3166
    type_rule1_off => 1
3167

            
3168
Same as C<execute> method's C<type_rule1_off> option.
3169

            
3170
=item C<type_rule2_off> EXPERIMENTAL
3171

            
3172
    type_rule2_off => 1
3173

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3176
=item C<where>
3177

            
3178
Same as C<select> method's C<where> option.
3179

            
updated pod
Yuki Kimoto authored on 2011-06-08
3180
=back
update pod
Yuki Kimoto authored on 2011-03-13
3181

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

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

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

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

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

            
3193
Create update parameter tag.
3194

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

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

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

            
3204
Create a new L<DBIx::Custom::Where> object.
3205

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

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

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

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

            
3215
=head2 C<DBIX_CUSTOM_DEBUG>
3216

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

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

            
3222
    $dbi->show_datatype($table);
3223

            
3224
Show data type of the columns of specified table.
3225

            
3226
    book
3227
    title: 5
3228
    issue_date: 91
3229

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
3232
=head2 C<show_tables EXPERIMETNAL>
3233

            
3234
    $dbi->show_tables;
3235

            
3236
Show tables.
3237

            
update pod
Yuki Kimoto authored on 2011-08-10
3238
=head2 C<show_typename EXPERIMENTAL>
3239

            
3240
    $dbi->show_typename($table);
3241

            
3242
Show type name of the columns of specified table.
3243

            
3244
    book
3245
    title: varchar
3246
    issue_date: date
3247

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

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

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

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

            
3256
L<DBIx::Custom>
3257

            
3258
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3259
    data_source # will be removed at 2017/1/1
3260
    dbi_options # will be removed at 2017/1/1
3261
    filter_check # will be removed at 2017/1/1
3262
    reserved_word_quote # will be removed at 2017/1/1
3263
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3264
    
3265
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3266
    create_query # will be removed at 2017/1/1
3267
    apply_filter # will be removed at 2017/1/1
3268
    select_at # will be removed at 2017/1/1
3269
    delete_at # will be removed at 2017/1/1
3270
    update_at # will be removed at 2017/1/1
3271
    insert_at # will be removed at 2017/1/1
3272
    register_tag # will be removed at 2017/1/1
3273
    default_bind_filter # will be removed at 2017/1/1
3274
    default_fetch_filter # will be removed at 2017/1/1
3275
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3276
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3277
    register_tag_processor # will be removed at 2017/1/1
3278
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3279
    
3280
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3281
    select method relation option # will be removed at 2017/1/1
3282
    select method param option # will be removed at 2017/1/1
3283
    select method column option [COLUMN, as => ALIAS] format
3284
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3285
    
3286
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3287
    execute("select * from {= title}"); # execute method's
3288
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3289
                                        # will be removed at 2017/1/1
3290
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3291

            
3292
L<DBIx::Custom::Model>
3293

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3294
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3295
    filter # will be removed at 2017/1/1
3296
    name # will be removed at 2017/1/1
3297
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3298

            
3299
L<DBIx::Custom::Query>
3300
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3301
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3302
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3303
    table # will be removed at 2017/1/1
3304
    filters # will be removed at 2017/1/1
3305
    
3306
    # Methods
3307
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3308

            
3309
L<DBIx::Custom::QueryBuilder>
3310
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3311
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3312
    tags # will be removed at 2017/1/1
3313
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3314
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3315
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3316
    register_tag # will be removed at 2017/1/1
3317
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3318
    
3319
    # Others
3320
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3321
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3322

            
3323
L<DBIx::Custom::Result>
3324
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3325
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3326
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3327
    
3328
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3329
    end_filter # will be removed at 2017/1/1
3330
    remove_end_filter # will be removed at 2017/1/1
3331
    remove_filter # will be removed at 2017/1/1
3332
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3333

            
3334
L<DBIx::Custom::Tag>
3335

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

            
3338
=head1 BACKWORD COMPATIBLE POLICY
3339

            
3340
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3341
except for attribute method.
3342
You can check all DEPRECATED functionalities by document.
3343
DEPRECATED functionality is removed after five years,
3344
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
3345
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3346

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

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

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

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

            
3355
C<< <kimoto.yuki at gmail.com> >>
3356

            
3357
L<http://github.com/yuki-kimoto/DBIx-Custom>
3358

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3359
=head1 AUTHOR
3360

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

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

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

            
3367
This program is free software; you can redistribute it and/or modify it
3368
under the same terms as Perl itself.
3369

            
3370
=cut