DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3389 lines | 87.686kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

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

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

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

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

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
264
sub DESTROY {}
added helper method
yuki-kimoto authored on 2010-10-17
265

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

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

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
517
sub find_tables {
518
    my ($self, %args) = @_;
519
    
520
    my $exclude = delete $args{exclude};
521
    croak qq/"$_" is wrong option/ for keys %args;
522
    
523
    my %tables;
524
    $self->each_table(sub { push $table{$_[1]}++ }, exclude => $exclude);
525
    
526
    return [sort keys %tables];
527
}
528

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
550
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
551
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
552
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
553
        $param = $self->merge_param($id_param, $param);
554
    }
555

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
589
sub include_model {
590
    my ($self, $name_space, $model_infos) = @_;
591
    
cleanup
Yuki Kimoto authored on 2011-04-02
592
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
593
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
594
    
595
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
596
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
597

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

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

            
680
        # Map parameter
681
        my $value;
682
        if (ref $condition eq 'CODE') {
683
            $map_param->{$map_key} = $value_cb->($param->{$key})
684
              if $condition->($param->{$key});
685
        }
686
        elsif ($condition eq 'exists') {
687
            $map_param->{$map_key} = $value_cb->($param->{$key})
688
              if exists $param->{$key};
689
        }
690
        else { croak qq/Condition must be code reference or "exists" / . _subname }
691
    }
692
    
693
    return $map_param;
694
}
695

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
720
sub method {
721
    my $self = shift;
722
    
cleanup
Yuki Kimoto authored on 2011-04-02
723
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
724
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
725
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
726
    
727
    return $self;
728
}
729

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
730
sub model {
731
    my ($self, $name, $model) = @_;
732
    
cleanup
Yuki Kimoto authored on 2011-04-02
733
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
734
    if ($model) {
735
        $self->models->{$name} = $model;
736
        return $self;
737
    }
738
    
739
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
740
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
741
      unless $self->models->{$name};
742
    
cleanup
Yuki Kimoto authored on 2011-04-02
743
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
744
    return $self->models->{$name};
745
}
746

            
cleanup
Yuki Kimoto authored on 2011-03-21
747
sub mycolumn {
748
    my ($self, $table, $columns) = @_;
749
    
cleanup
Yuki Kimoto authored on 2011-04-02
750
    # Create column clause
751
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
752
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
753
    push @column, $self->_q($table) . "." . $self->_q($_) .
754
      " as " . $self->_q($_)
755
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
756
    
757
    return join (', ', @column);
758
}
759

            
added dbi_options attribute
kimoto authored on 2010-12-20
760
sub new {
761
    my $self = shift->SUPER::new(@_);
762
    
cleanup
Yuki Kimoto authored on 2011-04-02
763
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
764
    my @attrs = keys %$self;
765
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
766
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
767
          unless $self->can($attr);
768
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
769

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
770
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
771
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
772
        '?'     => \&DBIx::Custom::Tag::placeholder,
773
        '='     => \&DBIx::Custom::Tag::equal,
774
        '<>'    => \&DBIx::Custom::Tag::not_equal,
775
        '>'     => \&DBIx::Custom::Tag::greater_than,
776
        '<'     => \&DBIx::Custom::Tag::lower_than,
777
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
778
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
779
        'like'  => \&DBIx::Custom::Tag::like,
780
        'in'    => \&DBIx::Custom::Tag::in,
781
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
782
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
783
    };
784
    
785
    return $self;
786
}
787

            
788
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
789
sub not_exists { $not_exists }
790

            
791
sub order {
792
    my $self = shift;
793
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
794
}
795

            
cleanup
yuki-kimoto authored on 2010-10-17
796
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
797
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
798
    
799
    # Register filter
800
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
801
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
802
    
cleanup
Yuki Kimoto authored on 2011-04-02
803
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
804
}
packaging one directory
yuki-kimoto authored on 2009-11-16
805

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
939
sub setup_model {
940
    my $self = shift;
941
    
cleanup
Yuki Kimoto authored on 2011-04-02
942
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
943
    $self->each_column(
944
        sub {
945
            my ($self, $table, $column, $column_info) = @_;
946
            if (my $model = $self->models->{$table}) {
947
                push @{$model->columns}, $column;
948
            }
949
        }
950
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
951
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
952
}
953

            
update pod
Yuki Kimoto authored on 2011-08-10
954
sub show_datatype {
955
    my ($self, $table) = @_;
956
    croak "Table name must be specified" unless defined $table;
957
    print "$table\n";
958
    
959
    my $result = $self->select(table => $table, where => "'0' <> '0'");
960
    my $sth = $result->sth;
961

            
962
    my $columns = $sth->{NAME};
963
    my $data_types = $sth->{TYPE};
964
    
965
    for (my $i = 0; $i < @$columns; $i++) {
966
        my $column = $columns->[$i];
967
        my $data_type = $data_types->[$i];
968
        print "$column: $data_type\n";
969
    }
970
}
971

            
972
sub show_typename {
973
    my ($self, $t) = @_;
974
    croak "Table name must be specified" unless defined $t;
975
    print "$t\n";
976
    
977
    $self->each_column(sub {
978
        my ($self, $table, $column, $infos) = @_;
979
        return unless $table eq $t;
980
        my $typename = $infos->{TYPE_NAME};
981
        print "$column: $typename\n";
982
    });
983
    
984
    return $self;
985
}
986

            
test cleanup
Yuki Kimoto authored on 2011-08-15
987
sub show_tables {
988
    my $self = shift;
989
    
990
    my %tables;
991
    $self->each_table(sub { $tables{$_[1]}++ });
992
    print join("\n", sort keys %tables) . "\n";
993
    return $self;
994
}
995

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1029
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1030
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1031
                }
1032
            });
1033
        }
1034

            
1035
        # From
1036
        foreach my $i (1 .. 2) {
1037
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1038
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1039
                croak qq{data type of from$i section must be lower case or number}
1040
                  if $data_type =~ /[A-Z]/;
1041
                my $fname = $type_rule->{"from$i"}{$data_type};
1042
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1043
                    croak qq{Filter "$fname" is not registered" } . _subname
1044
                      unless exists $self->filters->{$fname};
1045
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1046
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1047
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1048
            }
1049
        }
1050
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1051
        return $self;
1052
    }
1053
    
1054
    return $self->{type_rule} || {};
1055
}
1056

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1060
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1061
    my $param;
1062
    $param = shift if @_ % 2;
1063
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1064
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1065
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1066
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1067
    my $p = delete $args{param} || {};
1068
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1069
    my $where = delete $args{where} || {};
1070
    my $where_param = delete $args{where_param} || {};
1071
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1072
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1073
    my $id = delete $args{id};
1074
    my $primary_key = delete $args{primary_key};
1075
    croak "update method primary_key option " .
1076
          "must be specified when id is specified " . _subname
1077
      if defined $id && !defined $primary_key;
1078
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1079
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1080

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1123
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1124
    my ($self, $param, $opt) = @_;
1125
    
cleanup
Yuki Kimoto authored on 2011-04-02
1126
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1127
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1128
    $tag = "set $tag" unless $opt->{no_set};
1129

            
cleanup
Yuki Kimoto authored on 2011-04-02
1130
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1131
}
1132

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1135
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1136
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1137
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1138
    
updated pod
Yuki Kimoto authored on 2011-06-21
1139
    # Cache
1140
    my $cache = $self->cache;
1141
    
1142
    # Query
1143
    my $query;
1144
    
1145
    # Get cached query
1146
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1147
        
updated pod
Yuki Kimoto authored on 2011-06-21
1148
        # Get query
1149
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1150
        
updated pod
Yuki Kimoto authored on 2011-06-21
1151
        # Create query
1152
        if ($q) {
1153
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1154
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1155
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1156
    }
1157
    
1158
    # Create query
1159
    unless ($query) {
1160

            
1161
        # Create query
1162
        my $builder = $self->query_builder;
1163
        $query = $builder->build_query($source);
1164

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

            
1171
        # Save query to cache
1172
        $self->cache_method->(
1173
            $self, $source,
1174
            {
1175
                sql     => $query->sql, 
1176
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1177
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1178
            }
1179
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1180
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1181

            
1182
    # Filter SQL
1183
    if ($sqlfilter) {
1184
        my $sql = $query->sql;
1185
        $sql = $sqlfilter->($sql);
1186
        $query->sql($sql);
1187
    }
1188
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1189
    # Save sql
1190
    $self->last_sql($query->sql);
1191
    
updated pod
Yuki Kimoto authored on 2011-06-21
1192
    # Prepare statement handle
1193
    my $sth;
1194
    eval { $sth = $self->dbh->prepare($query->{sql})};
1195
    
1196
    if ($@) {
1197
        $self->_croak($@, qq{. Following SQL is executed.\n}
1198
                        . qq{$query->{sql}\n} . _subname);
1199
    }
1200
    
1201
    # Set statement handle
1202
    $query->sth($sth);
1203
    
1204
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1205
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1206
    
1207
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1208
}
1209

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1260
sub _create_param_from_id {
1261
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1262
    
cleanup
Yuki Kimoto authored on 2011-06-08
1263
    # Create parameter
1264
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1265
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1266
        $id = [$id] unless ref $id;
1267
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1268
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1269
          unless !ref $id || ref $id eq 'ARRAY';
1270
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1271
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1272
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1273
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1274
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1275
        }
1276
    }
1277
    
cleanup
Yuki Kimoto authored on 2011-06-08
1278
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1279
}
1280

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1281
sub _connect {
1282
    my $self = shift;
1283
    
1284
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1285
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1286
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1287
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1288
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1289
    croak qq{"dsn" must be specified } . _subname
1290
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1291
    my $user        = $self->user;
1292
    my $password    = $self->password;
1293
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1294
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1295
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1296
    
1297
    # Connect
1298
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1299
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1300
        $user,
1301
        $password,
1302
        {
1303
            %{$self->default_dbi_option},
1304
            %$dbi_option
1305
        }
1306
    )};
1307
    
1308
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1309
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1310
    
1311
    return $dbh;
1312
}
1313

            
cleanup
yuki-kimoto authored on 2010-10-17
1314
sub _croak {
1315
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1316
    
1317
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1318
    $append ||= "";
1319
    
1320
    # Verbose
1321
    if ($Carp::Verbose) { croak $error }
1322
    
1323
    # Not verbose
1324
    else {
1325
        
1326
        # Remove line and module infromation
1327
        my $at_pos = rindex($error, ' at ');
1328
        $error = substr($error, 0, $at_pos);
1329
        $error =~ s/\s+$//;
1330
        croak "$error$append";
1331
    }
1332
}
1333

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1336
sub _need_tables {
1337
    my ($self, $tree, $need_tables, $tables) = @_;
1338
    
cleanup
Yuki Kimoto authored on 2011-04-02
1339
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1340
    foreach my $table (@$tables) {
1341
        if ($tree->{$table}) {
1342
            $need_tables->{$table} = 1;
1343
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1344
        }
1345
    }
1346
}
1347

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1348
sub _push_join {
1349
    my ($self, $sql, $join, $join_tables) = @_;
1350
    
cleanup
Yuki Kimoto authored on 2011-04-02
1351
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1352
    return unless @$join;
1353
    
cleanup
Yuki Kimoto authored on 2011-04-02
1354
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1355
    my $tree = {};
1356
    for (my $i = 0; $i < @$join; $i++) {
1357
        
cleanup
Yuki Kimoto authored on 2011-07-28
1358
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1359
        my $join_clause;;
1360
        my $option;
1361
        if (ref $join->[$i] eq 'HASH') {
1362
            $join_clause = $join->[$i]->{clause};
1363
            $option = {table => $join->[$i]->{table}};
1364
        }
1365
        else {
1366
            $join_clause = $join->[$i];
1367
            $option = {};
1368
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1369

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1413
sub _quote {
1414
    my $self = shift;
1415
    
1416
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1417
         : defined $self->quote ? $self->quote
1418
         : '';
1419
}
1420

            
cleanup
Yuki Kimoto authored on 2011-07-29
1421
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1422
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1423
    
1424
    my $quote = $self->_quote;
1425
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1426
    my $p;
1427
    if (defined $quote && length $quote > 1) {
1428
        $p = substr($quote, 1, 1);
1429
    }
1430
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1431
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1432
    if ($quotemeta) {
1433
        $q = quotemeta($q);
1434
        $p = quotemeta($p);
1435
    }
1436
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1437
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1438
}
1439

            
cleanup
Yuki Kimoto authored on 2011-04-02
1440
sub _remove_duplicate_table {
1441
    my ($self, $tables, $main_table) = @_;
1442
    
1443
    # Remove duplicate table
1444
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1445
    delete $tables{$main_table} if $main_table;
1446
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1447
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1448
    if (my $q = $self->_quote) {
1449
        $q = quotemeta($q);
1450
        $_ =~ s/[$q]//g for @$new_tables;
1451
    }
1452

            
1453
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1454
}
1455

            
cleanup
Yuki Kimoto authored on 2011-04-02
1456
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1457
    my ($self, $source) = @_;
1458
    
cleanup
Yuki Kimoto authored on 2011-04-02
1459
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1460
    my $tables = [];
1461
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1462
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1463
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1464
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1465
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1466
    while ($source =~ /$table_re/g) {
1467
        push @$tables, $1;
1468
    }
1469
    
1470
    return $tables;
1471
}
1472

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

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

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

            
1592
# DEPRECATED!
1593
sub create_query {
1594
    warn "create_query is DEPRECATED! use query option of each method";
1595
    shift->_create_query(@_);
1596
}
1597

            
cleanup
Yuki Kimoto authored on 2011-06-13
1598
# DEPRECATED!
1599
sub apply_filter {
1600
    my $self = shift;
1601
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1602
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1603
    return $self->_apply_filter(@_);
1604
}
1605

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1613
    # Arguments
1614
    my $primary_keys = delete $args{primary_key};
1615
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1616
    my $where = delete $args{where};
1617
    my $param = delete $args{param};
1618
    
1619
    # Check arguments
1620
    foreach my $name (keys %args) {
1621
        croak qq{"$name" is wrong option } . _subname
1622
          unless $SELECT_AT_ARGS{$name};
1623
    }
1624
    
1625
    # Table
1626
    croak qq{"table" option must be specified } . _subname
1627
      unless $args{table};
1628
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1629
    
1630
    # Create where parameter
1631
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1632
    
1633
    return $self->select(where => $where_param, %args);
1634
}
1635

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

            
1641
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1642
    
1643
    # Arguments
1644
    my $primary_keys = delete $args{primary_key};
1645
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1646
    my $where = delete $args{where};
1647
    
1648
    # Check arguments
1649
    foreach my $name (keys %args) {
1650
        croak qq{"$name" is wrong option } . _subname
1651
          unless $DELETE_AT_ARGS{$name};
1652
    }
1653
    
1654
    # Create where parameter
1655
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1656
    
1657
    return $self->delete(where => $where_param, %args);
1658
}
1659

            
cleanup
Yuki Kimoto authored on 2011-06-08
1660
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1661
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1662
sub update_at {
1663
    my $self = shift;
1664

            
1665
    warn "update_at is DEPRECATED! use update and id option instead";
1666
    
1667
    # Arguments
1668
    my $param;
1669
    $param = shift if @_ % 2;
1670
    my %args = @_;
1671
    my $primary_keys = delete $args{primary_key};
1672
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1673
    my $where = delete $args{where};
1674
    my $p = delete $args{param} || {};
1675
    $param  ||= $p;
1676
    
1677
    # Check arguments
1678
    foreach my $name (keys %args) {
1679
        croak qq{"$name" is wrong option } . _subname
1680
          unless $UPDATE_AT_ARGS{$name};
1681
    }
1682
    
1683
    # Create where parameter
1684
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1685
    
1686
    return $self->update(where => $where_param, param => $param, %args);
1687
}
1688

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1689
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1690
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1691
sub insert_at {
1692
    my $self = shift;
1693
    
1694
    warn "insert_at is DEPRECATED! use insert and id option instead";
1695
    
1696
    # Arguments
1697
    my $param;
1698
    $param = shift if @_ % 2;
1699
    my %args = @_;
1700
    my $primary_key = delete $args{primary_key};
1701
    $primary_key = [$primary_key] unless ref $primary_key;
1702
    my $where = delete $args{where};
1703
    my $p = delete $args{param} || {};
1704
    $param  ||= $p;
1705
    
1706
    # Check arguments
1707
    foreach my $name (keys %args) {
1708
        croak qq{"$name" is wrong option } . _subname
1709
          unless $INSERT_AT_ARGS{$name};
1710
    }
1711
    
1712
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1713
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1714
    $param = $self->merge_param($where_param, $param);
1715
    
1716
    return $self->insert(param => $param, %args);
1717
}
1718

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

            
1732
# DEPRECATED!
1733
sub register_tag_processor {
1734
    my $self = shift;
1735
    warn "register_tag_processor is DEPRECATED!";
1736
    # Merge tag
1737
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1738
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1739
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1740
}
1741

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1742
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1743
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1744
has dbi_options => sub { {} };
1745
has filter_check  => 1;
1746
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1747

            
cleanup
Yuki Kimoto authored on 2011-01-25
1748
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1749
sub default_bind_filter {
1750
    my $self = shift;
1751
    
cleanup
Yuki Kimoto authored on 2011-06-13
1752
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1753
    
cleanup
Yuki Kimoto authored on 2011-01-12
1754
    if (@_) {
1755
        my $fname = $_[0];
1756
        
1757
        if (@_ && !$fname) {
1758
            $self->{default_out_filter} = undef;
1759
        }
1760
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1761
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1762
              unless exists $self->filters->{$fname};
1763
        
1764
            $self->{default_out_filter} = $self->filters->{$fname};
1765
        }
1766
        return $self;
1767
    }
1768
    
1769
    return $self->{default_out_filter};
1770
}
1771

            
cleanup
Yuki Kimoto authored on 2011-01-25
1772
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1773
sub default_fetch_filter {
1774
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1775

            
cleanup
Yuki Kimoto authored on 2011-06-13
1776
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1777
    
1778
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1779
        my $fname = $_[0];
1780

            
cleanup
Yuki Kimoto authored on 2011-01-12
1781
        if (@_ && !$fname) {
1782
            $self->{default_in_filter} = undef;
1783
        }
1784
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1785
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1786
              unless exists $self->filters->{$fname};
1787
        
1788
            $self->{default_in_filter} = $self->filters->{$fname};
1789
        }
1790
        
1791
        return $self;
1792
    }
1793
    
many changed
Yuki Kimoto authored on 2011-01-23
1794
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1795
}
1796

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1797
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1798
sub insert_param_tag {
1799
    warn "insert_param_tag is DEPRECATED! " .
1800
         "use insert_param instead!";
1801
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1802
}
1803

            
1804
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1805
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1806
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1807
         "use update_param instead";
1808
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1809
}
cleanup
Yuki Kimoto authored on 2011-03-08
1810
# DEPRECATED!
1811
sub _push_relation {
1812
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1813
    
1814
    if (keys %{$relation || {}}) {
1815
        push @$sql, $need_where ? 'where' : 'and';
1816
        foreach my $rcolumn (keys %$relation) {
1817
            my $table1 = (split (/\./, $rcolumn))[0];
1818
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1819
            push @$tables, ($table1, $table2);
1820
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1821
        }
1822
    }
1823
    pop @$sql if $sql->[-1] eq 'and';    
1824
}
1825

            
1826
# DEPRECATED!
1827
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1828
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1829
    
1830
    if (keys %{$relation || {}}) {
1831
        foreach my $rcolumn (keys %$relation) {
1832
            my $table1 = (split (/\./, $rcolumn))[0];
1833
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1834
            my $table1_exists;
1835
            my $table2_exists;
1836
            foreach my $table (@$tables) {
1837
                $table1_exists = 1 if $table eq $table1;
1838
                $table2_exists = 1 if $table eq $table2;
1839
            }
1840
            unshift @$tables, $table1 unless $table1_exists;
1841
            unshift @$tables, $table2 unless $table2_exists;
1842
        }
1843
    }
1844
}
1845

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1848
=head1 NAME
1849

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

            
1852
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1853

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1854
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1855
    
1856
    # Connect
1857
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1858
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1859
        user => 'ken',
1860
        password => '!LFKD%$&',
1861
        dbi_option => {mysql_enable_utf8 => 1}
1862
    );
cleanup
yuki-kimoto authored on 2010-08-05
1863

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1864
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1865
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1866
    
1867
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1868
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1869
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1870
    
1871
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1872
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1873

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1923
Named place holder support
1924

            
1925
=item *
1926

            
cleanup
Yuki Kimoto authored on 2011-07-29
1927
Model support
1928

            
1929
=item *
1930

            
1931
Connection manager support
1932

            
1933
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1934

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

            
1939
=item *
1940

            
1941
Filtering by data type or column name(EXPERIMENTAL)
1942

            
1943
=item *
1944

            
1945
Create C<order by> clause flexibly(EXPERIMENTAL)
1946

            
1947
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1948

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1956
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1957
L<DBIx::Custom::Result>,
1958
L<DBIx::Custom::Query>,
1959
L<DBIx::Custom::Where>,
1960
L<DBIx::Custom::Model>,
1961
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1962

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

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

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

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

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

            
1976
    my $connector = DBIx::Connector->new(
1977
        "dbi:mysql:database=$DATABASE",
1978
        $USER,
1979
        $PASSWORD,
1980
        DBIx::Custom->new->default_dbi_option
1981
    );
1982
    
updated pod
Yuki Kimoto authored on 2011-06-21
1983
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1984

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

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

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

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

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

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

            
2000
=head2 C<default_dbi_option>
2001

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2008
    {
2009
        RaiseError => 1,
2010
        PrintError => 0,
2011
        AutoCommit => 1,
2012
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2013

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

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

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

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

            
2023
    my $last_sql = $dbi->last_sql;
2024
    $dbi = $dbi->last_sql($last_sql);
2025

            
2026
Get last successed SQL executed by C<execute> method.
2027

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2035
=head2 C<password>
2036

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2057
You can set quote pair.
2058

            
2059
    $dbi->quote('[]');
2060

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

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

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

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

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

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

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

            
2078
    my $separator = $self->separator;
2079
    $dbi = $self->separator($separator);
2080

            
2081
Separator whichi join table and column.
2082
This is used by C<column> and C<mycolumn> method.
2083

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

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

            
2089
Regex matching system table.
2090
this regex match is used by C<each_table> method and C<each_column> method
2091
System table is ignored.
2092
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2093
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2094
The performance is up.
2095

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

            
2098
    my $tag_parse = $dbi->tag_parse(0);
2099
    $dbi = $dbi->tag_parse;
2100

            
2101
Enable DEPRECATED tag parsing functionality, default to 1.
2102
If you want to disable tag parsing functionality, set to 0.
2103

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2145
Create column clause. The follwoing column clause is created.
2146

            
2147
    book.author as "book.author",
2148
    book.title as "book.title"
2149

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2152
    # Separator is double underbar
2153
    $dbi->separator('__');
2154
    
2155
    book.author as "book__author",
2156
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2157

            
cleanup
Yuki Kimoto authored on 2011-06-13
2158
    # Separator is hyphen
2159
    $dbi->separator('-');
2160
    
2161
    book.author as "book-author",
2162
    book.title as "book-title"
2163
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2164
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2165

            
update pod
Yuki Kimoto authored on 2011-03-13
2166
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2167
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2168
        user => 'ken',
2169
        password => '!LFKD%$&',
2170
        dbi_option => {mysql_enable_utf8 => 1}
2171
    );
2172

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2181
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2182
        table => 'book',
2183
        primary_key => 'id',
2184
        join => [
2185
            'inner join company on book.comparny_id = company.id'
2186
        ],
2187
    );
2188

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

            
2192
   $dbi->model('book')->select(...);
2193

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

            
2196
    my $dbh = $dbi->dbh;
2197

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

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2201
=head2 C<delete>
2202

            
2203
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2204

            
2205
Execute delete statement.
2206

            
2207
The following opitons are available.
2208

            
2209
=over 4
2210

            
2211
=item C<append>
2212

            
2213
Same as C<select> method's C<append> option.
2214

            
2215
=item C<filter>
2216

            
2217
Same as C<execute> method's C<filter> option.
2218

            
2219
=item C<id>
2220

            
2221
    id => 4
2222
    id => [4, 5]
2223

            
2224
ID corresponding to C<primary_key>.
2225
You can delete rows by C<id> and C<primary_key>.
2226

            
2227
    $dbi->delete(
2228
        parimary_key => ['id1', 'id2'],
2229
        id => [4, 5],
2230
        table => 'book',
2231
    );
2232

            
2233
The above is same as the followin one.
2234

            
2235
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
2236

            
2237
=item C<prefix>
2238

            
2239
    prefix => 'some'
2240

            
2241
prefix before table name section.
2242

            
2243
    delete some from book
2244

            
2245
=item C<query>
2246

            
2247
Same as C<execute> method's C<query> option.
2248

            
2249
=item C<sqlfilter EXPERIMENTAL>
2250

            
2251
Same as C<execute> method's C<sqlfilter> option.
2252

            
2253
=item C<table>
2254

            
2255
    table => 'book'
2256

            
2257
Table name.
2258

            
2259
=item C<where>
2260

            
2261
Same as C<select> method's C<where> option.
2262

            
2263
=item C<primary_key>
2264

            
2265
See C<id> option.
2266

            
2267
=item C<bind_type>
2268

            
2269
Same as C<execute> method's C<bind_type> option.
2270

            
2271
=item C<type_rule_off> EXPERIMENTAL
2272

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

            
2275
=item C<type_rule1_off> EXPERIMENTAL
2276

            
2277
    type_rule1_off => 1
2278

            
2279
Same as C<execute> method's C<type_rule1_off> option.
2280

            
2281
=item C<type_rule2_off> EXPERIMENTAL
2282

            
2283
    type_rule2_off => 1
2284

            
2285
Same as C<execute> method's C<type_rule2_off> option.
2286

            
2287
=back
2288

            
2289
=head2 C<delete_all>
2290

            
2291
    $dbi->delete_all(table => $table);
2292

            
2293
Execute delete statement for all rows.
2294
Options is same as C<delete>.
2295

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2296
=head2 C<each_column>
2297

            
2298
    $dbi->each_column(
2299
        sub {
2300
            my ($dbi, $table, $column, $column_info) = @_;
2301
            
2302
            my $type = $column_info->{TYPE_NAME};
2303
            
2304
            if ($type eq 'DATE') {
2305
                # ...
2306
            }
2307
        }
2308
    );
2309

            
2310
Iterate all column informations of all table from database.
2311
Argument is callback when one column is found.
2312
Callback receive four arguments, dbi object, table name,
2313
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2314

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

            
2317
    $dbi->each_table(
2318
        sub {
2319
            my ($dbi, $table, $table_info) = @_;
2320
            
2321
            my $table_name = $table_info->{TABLE_NAME};
2322
        }
2323
    );
2324

            
2325
Iterate all table informationsfrom database.
2326
Argument is callback when one table is found.
2327
Callback receive three arguments, dbi object, table name,
2328
table information.
2329

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

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

            
2337
    my $result = $dbi->execute(
2338
      "select * from book where title = :book.title and author like :book.author",
2339
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2340
    );
2341

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2348
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2349
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2350
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2351
    select * from book where title = :title and author like :author
2352
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2353
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2354
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2355

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2359
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2360
    select * from book where :title{=} and :author{like}
2361
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2362
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2363
    select * from where title = ? and author like ?;
2364

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

            
2369
    select * from where title = "aa\\:bb";
2370

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

            
2373
=over 4
2374

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

            
2377
Specify database bind data type.
2378

            
2379
    bind_type => [image => DBI::SQL_BLOB]
2380
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2381

            
2382
This is used to bind parameter by C<bind_param> of statment handle.
2383

            
2384
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2385

            
update pod
Yuki Kimoto authored on 2011-03-13
2386
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2387
    
2388
    filter => {
2389
        title  => sub { uc $_[0] }
2390
        author => sub { uc $_[0] }
2391
    }
update pod
Yuki Kimoto authored on 2011-03-13
2392

            
updated pod
Yuki Kimoto authored on 2011-06-09
2393
    # Filter name
2394
    filter => {
2395
        title  => 'upper_case',
2396
        author => 'upper_case'
2397
    }
2398
        
2399
    # At once
2400
    filter => [
2401
        [qw/title author/]  => sub { uc $_[0] }
2402
    ]
2403

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

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

            
2411
    query => 1
2412

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

            
2416
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2417
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2418
    my $columns = $query->columns;
2419
    
2420
If you want to execute SQL fast, you can do the following way.
2421

            
2422
    my $query;
2423
    foreach my $row (@$rows) {
2424
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2425
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2426
    }
2427

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

            
2431
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
2432
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2433
    
2434
    my $query;
2435
    my $sth;
2436
    foreach my $row (@$rows) {
2437
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2438
      $sth ||= $query->sth;
2439
      $sth->execute(map { $row->{$_} } sort keys %$row);
2440
    }
2441

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

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

            
2448
SQL filter function.
2449

            
2450
    sqlfilter => $code_ref
2451

            
2452
This option is generally for Oracle and SQL Server paging process.
2453
    
2454
    my $limit = sub {
2455
        my ($sql, $count, $offset) = @_;
2456
        
2457
        my $min = $offset + 1;
2458
        my $max = $offset + $count;
2459
        
2460
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2461
        
2462
        return $sql;
2463
    }
2464
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2465
        my $sql = shift;
2466
        return $limit->($sql, 100, 50);
2467
    })
2468

            
updated pod
Yuki Kimoto authored on 2011-06-09
2469
=item C<table>
2470
    
2471
    table => 'author'
2472

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2480
    # Same
2481
    $dbi->execute(
2482
      "select * from book where title = :book.title and author = :book.author",
2483
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2484

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

            
2487
    table_alias => {user => 'hiker'}
2488

            
2489
Table alias. Key is real table name, value is alias table name.
2490
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2491
on alias table name.
2492

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

            
2495
    type_rule_off => 1
2496

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

            
2499
=item C<type_rule1_off> EXPERIMENTAL
2500

            
2501
    type_rule1_off => 1
2502

            
2503
Turn C<into1> type rule off.
2504

            
2505
=item C<type_rule2_off> EXPERIMENTAL
2506

            
2507
    type_rule2_off => 1
2508

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

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

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2513
=head2 C<find_tables EXPERIMENTAL>
update pod
Yuki Kimoto authored on 2011-03-13
2514

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2515
    my $tables = $self->find_tables(exclude => qr/^system_/);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2516

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2517
Find tables except for one which match C<exclude> pattern.
update pod
Yuki Kimoto authored on 2011-03-13
2518

            
cleanup
yuki-kimoto authored on 2010-10-17
2519
=head2 C<insert>
2520

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

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

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

            
2529
    {date => \"NOW()"}
2530

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

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

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

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

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

            
2541
Same as C<execute> method's C<bind_type> option.
2542

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

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

            
2547
=item C<id>
2548

            
updated document
Yuki Kimoto authored on 2011-06-09
2549
    id => 4
2550
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2551

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2555
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2556
        {title => 'Perl', author => 'Ken'}
2557
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2558
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2559
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2560
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2561

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

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

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

            
2571
    prefix => 'or replace'
2572

            
2573
prefix before table name section
2574

            
2575
    insert or replace into book
2576

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

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

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

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

            
2586
Same as C<execute> method's C<query> option.
2587

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

            
2590
Same as C<execute> method's C<sqlfilter> option.
2591

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

            
2594
    table => 'book'
2595

            
2596
Table name.
2597

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

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

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

            
2604
    type_rule1_off => 1
2605

            
2606
Same as C<execute> method's C<type_rule1_off> option.
2607

            
2608
=item C<type_rule2_off> EXPERIMENTAL
2609

            
2610
    type_rule2_off => 1
2611

            
2612
Same as C<execute> method's C<type_rule2_off> option.
2613

            
update pod
Yuki Kimoto authored on 2011-03-13
2614
=back
2615

            
2616
=over 4
2617

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2633
    lib / MyModel.pm
2634
        / MyModel / book.pm
2635
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2636

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

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

            
2641
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2642
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2643
    
2644
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2645

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2650
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2651
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2652
    
2653
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2654

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2657
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2658
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2659
    
2660
    1;
2661
    
updated pod
Yuki Kimoto authored on 2011-06-21
2662
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2663

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

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

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

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

            
2673
    my $map_param = $dbi->map_param(
2674
        {id => 1, authro => 'Ken', price => 1900},
2675
        'id' => 'book.id',
2676
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2677
        'price' => [
2678
            'book.price', {if => sub { length $_[0] }}
2679
        ]
2680
    );
2681

            
2682
Map paramters to other key and value. First argument is original
2683
parameter. this is hash reference. Rest argument is mapping.
2684
By default, Mapping is done if the value length is not zero.
2685

            
2686
=over 4
2687

            
2688
=item Key mapping
2689

            
2690
    'id' => 'book.id'
2691

            
2692
This is only key mapping. Value is same as original one.
2693

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

            
2696
=item Key and value mapping
2697

            
2698
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2699

            
2700
This is key and value mapping. Frist element of array reference
2701
is mapped key name, second element is code reference to map the value.
2702

            
2703
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2704
      if value length is not zero.
2705

            
2706
=item Condition
2707

            
2708
    'price' => ['book.price', {if => 'exists'}]
2709
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2710
    'price' => ['book.price', {if => sub { defined shift }}]
2711

            
2712
If you need condition, you can sepecify it. this is code reference
2713
or 'exists'. By default, condition is the following one.
2714

            
2715
    sub { defined $_[0] && length $_[0] }
2716

            
2717
=back
2718

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

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

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

            
2725
    {key1 => [1, 1], key2 => 2}
2726

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

            
2729
    $dbi->method(
2730
        update_or_insert => sub {
2731
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2732
            
2733
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2734
        },
2735
        find_or_create   => sub {
2736
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2737
            
2738
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2739
        }
2740
    );
2741

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

            
2744
    $dbi->update_or_insert;
2745
    $dbi->find_or_create;
2746

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

            
2749
    my $model = $dbi->model('book');
2750

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

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

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

            
2757
Create column clause for myself. The follwoing column clause is created.
2758

            
2759
    book.author as author,
2760
    book.title as title
2761

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2764
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2765
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2766
        user => 'ken',
2767
        password => '!LFKD%$&',
2768
        dbi_option => {mysql_enable_utf8 => 1}
2769
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2770

            
2771
Create a new L<DBIx::Custom> object.
2772

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

            
2775
    my $not_exists = $dbi->not_exists;
2776

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

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

            
2782
    my $order = $dbi->order;
2783

            
2784
Create a new L<DBIx::Custom::Order> object.
2785

            
cleanup
yuki-kimoto authored on 2010-10-17
2786
=head2 C<register_filter>
2787

            
update pod
Yuki Kimoto authored on 2011-03-13
2788
    $dbi->register_filter(
2789
        # Time::Piece object to database DATE format
2790
        tp_to_date => sub {
2791
            my $tp = shift;
2792
            return $tp->strftime('%Y-%m-%d');
2793
        },
2794
        # database DATE format to Time::Piece object
2795
        date_to_tp => sub {
2796
           my $date = shift;
2797
           return Time::Piece->strptime($date, '%Y-%m-%d');
2798
        }
2799
    );
cleanup
yuki-kimoto authored on 2010-10-17
2800
    
update pod
Yuki Kimoto authored on 2011-03-13
2801
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2802

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

            
2805
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2806
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2807
            date => sub { ... },
2808
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2809
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2810
        into2 => {
2811
            date => sub { ... },
2812
            datetime => sub { ... }
2813
        },
2814
        from1 => {
2815
            # DATE
2816
            9 => sub { ... },
2817
            # DATETIME or TIMESTAMP
2818
            11 => sub { ... },
2819
        }
2820
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2821
            # DATE
2822
            9 => sub { ... },
2823
            # DATETIME or TIMESTAMP
2824
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2825
        }
2826
    );
2827

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2843
=over 4
2844

            
2845
=item 1. column name
2846

            
2847
    issue_date
2848
    issue_datetime
2849

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

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

            
2854
    book.issue_date
2855
    book.issue_datetime
2856

            
2857
=back
2858

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

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

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

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

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

            
2871
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2872
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2873
            [qw/DATE DATETIME/] => sub { ... },
2874
        ],
2875
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2876

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2879
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2880
        table  => 'book',
2881
        column => ['author', 'title'],
2882
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2883
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2884
    
updated document
Yuki Kimoto authored on 2011-06-09
2885
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2886

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

            
2889
=over 4
2890

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

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

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

            
2897
=item C<bind_type>
2898

            
2899
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
2900
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2901
=item C<column>
2902
    
updated document
Yuki Kimoto authored on 2011-06-09
2903
    column => 'author'
2904
    column => ['author', 'title']
2905

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2914
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2915
        {book => [qw/author title/]},
2916
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2917
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2918

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

            
2921
    book.author as "book.author",
2922
    book.title as "book.title",
2923
    person.name as "person.name",
2924
    person.age as "person.age"
2925

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

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

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

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

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

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

            
2941
=item C<id>
2942

            
2943
    id => 4
2944
    id => [4, 5]
2945

            
2946
ID corresponding to C<primary_key>.
2947
You can select rows by C<id> and C<primary_key>.
2948

            
2949
    $dbi->select(
2950
        parimary_key => ['id1', 'id2'],
2951
        id => [4, 5],
2952
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2953
    );
2954

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2957
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2958
        where => {id1 => 4, id2 => 5},
2959
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2960
    );
2961
    
updated document
Yuki Kimoto authored on 2011-06-09
2962
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2963

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

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

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

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

            
2976
    prefix => 'SQL_CALC_FOUND_ROWS'
2977

            
2978
Prefix of column cluase
2979

            
2980
    select SQL_CALC_FOUND_ROWS title, author from book;
2981

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

            
2984
    join => [
2985
        'left outer join company on book.company_id = company_id',
2986
        'left outer join location on company.location_id = location.id'
2987
    ]
2988
        
2989
Join clause. If column cluase or where clause contain table name like "company.name",
2990
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2991

            
2992
    $dbi->select(
2993
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2994
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2995
        where => {'company.name' => 'Orange'},
2996
        join => [
2997
            'left outer join company on book.company_id = company.id',
2998
            'left outer join location on company.location_id = location.id'
2999
        ]
3000
    );
3001

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3005
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3006
    from book
3007
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3008
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3009

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

            
3013
    $dbi->select(
3014
        table => 'book',
3015
        column => ['company.location_id as location_id'],
3016
        where => {'company.name' => 'Orange'},
3017
        join => [
3018
            {
3019
                clause => 'left outer join location on company.location_id = location.id',
3020
                table => ['company', 'location']
3021
            }
3022
        ]
3023
    );
3024

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3044
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3045

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

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

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

            
3052
    type_rule1_off => 1
3053

            
3054
Same as C<execute> method's C<type_rule1_off> option.
3055

            
3056
=item C<type_rule2_off> EXPERIMENTAL
3057

            
3058
    type_rule2_off => 1
3059

            
3060
Same as C<execute> method's C<type_rule2_off> option.
3061

            
updated document
Yuki Kimoto authored on 2011-06-09
3062
=item C<where>
3063
    
3064
    # Hash refrence
3065
    where => {author => 'Ken', 'title' => 'Perl'}
3066
    
3067
    # DBIx::Custom::Where object
3068
    where => $dbi->where(
3069
        clause => ['and', 'author = :author', 'title like :title'],
3070
        param  => {author => 'Ken', title => '%Perl%'}
3071
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3072
    
3073
    # Array reference 1 (array reference, hash referenc). same as above
3074
    where => [
3075
        ['and', 'author = :author', 'title like :title'],
3076
        {author => 'Ken', title => '%Perl%'}
3077
    ];    
3078
    
3079
    # Array reference 2 (String, hash reference)
3080
    where => [
3081
        'title like :title',
3082
        {title => '%Perl%'}
3083
    ]
3084
    
3085
    # String
3086
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3087

            
updated document
Yuki Kimoto authored on 2011-06-09
3088
Where clause.
3089
    
improved pod
Yuki Kimoto authored on 2011-04-19
3090
=item C<wrap> EXPERIMENTAL
3091

            
3092
Wrap statement. This is array reference.
3093

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

            
3096
This option is for Oracle and SQL Server paging process.
3097

            
update pod
Yuki Kimoto authored on 2011-03-12
3098
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3099

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

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

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

            
3106
If you want to set constant value to row data, use scalar reference
3107
as parameter value.
3108

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3113
=over 4
3114

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

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

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

            
3121
Same as C<execute> method's C<bind_type> option.
3122

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3129
    id => 4
3130
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3131

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3135
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3136
        {title => 'Perl', author => 'Ken'}
3137
        parimary_key => ['id1', 'id2'],
3138
        id => [4, 5],
3139
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3140
    );
update pod
Yuki Kimoto authored on 2011-03-13
3141

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3144
    $dbi->update(
3145
        {title => 'Perl', author => 'Ken'}
3146
        where => {id1 => 4, id2 => 5},
3147
        table => 'book'
3148
    );
update pod
Yuki Kimoto authored on 2011-03-13
3149

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

            
3152
    prefix => 'or replace'
3153

            
3154
prefix before table name section
3155

            
3156
    update or replace book
3157

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

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

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

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

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

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

            
3171
Same as C<execute> method's C<sqlfilter> option.
3172

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

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

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

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

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

            
3183
=item C<type_rule1_off> EXPERIMENTAL
3184

            
3185
    type_rule1_off => 1
3186

            
3187
Same as C<execute> method's C<type_rule1_off> option.
3188

            
3189
=item C<type_rule2_off> EXPERIMENTAL
3190

            
3191
    type_rule2_off => 1
3192

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

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

            
3197
Same as C<select> method's C<where> option.
3198

            
updated pod
Yuki Kimoto authored on 2011-06-08
3199
=back
update pod
Yuki Kimoto authored on 2011-03-13
3200

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

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

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

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

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

            
3212
Create update parameter tag.
3213

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

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

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

            
3223
Create a new L<DBIx::Custom::Where> object.
3224

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

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

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

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

            
3234
=head2 C<DBIX_CUSTOM_DEBUG>
3235

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

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

            
3241
    $dbi->show_datatype($table);
3242

            
3243
Show data type of the columns of specified table.
3244

            
3245
    book
3246
    title: 5
3247
    issue_date: 91
3248

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

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

            
3253
    $dbi->show_tables;
3254

            
3255
Show tables.
3256

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

            
3259
    $dbi->show_typename($table);
3260

            
3261
Show type name of the columns of specified table.
3262

            
3263
    book
3264
    title: varchar
3265
    issue_date: date
3266

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

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

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

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

            
3275
L<DBIx::Custom>
3276

            
3277
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3278
    data_source # will be removed at 2017/1/1
3279
    dbi_options # will be removed at 2017/1/1
3280
    filter_check # will be removed at 2017/1/1
3281
    reserved_word_quote # will be removed at 2017/1/1
3282
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3283
    
3284
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3285
    create_query # will be removed at 2017/1/1
3286
    apply_filter # will be removed at 2017/1/1
3287
    select_at # will be removed at 2017/1/1
3288
    delete_at # will be removed at 2017/1/1
3289
    update_at # will be removed at 2017/1/1
3290
    insert_at # will be removed at 2017/1/1
3291
    register_tag # will be removed at 2017/1/1
3292
    default_bind_filter # will be removed at 2017/1/1
3293
    default_fetch_filter # will be removed at 2017/1/1
3294
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3295
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3296
    register_tag_processor # will be removed at 2017/1/1
3297
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3298
    
3299
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3300
    select method relation option # will be removed at 2017/1/1
3301
    select method param option # will be removed at 2017/1/1
3302
    select method column option [COLUMN, as => ALIAS] format
3303
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3304
    
3305
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3306
    execute("select * from {= title}"); # execute method's
3307
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3308
                                        # will be removed at 2017/1/1
3309
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3310

            
3311
L<DBIx::Custom::Model>
3312

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3313
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3314
    filter # will be removed at 2017/1/1
3315
    name # will be removed at 2017/1/1
3316
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3317

            
3318
L<DBIx::Custom::Query>
3319
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3320
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3321
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3322
    table # will be removed at 2017/1/1
3323
    filters # will be removed at 2017/1/1
3324
    
3325
    # Methods
3326
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3327

            
3328
L<DBIx::Custom::QueryBuilder>
3329
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3330
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3331
    tags # will be removed at 2017/1/1
3332
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3333
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3334
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3335
    register_tag # will be removed at 2017/1/1
3336
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3337
    
3338
    # Others
3339
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3340
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3341

            
3342
L<DBIx::Custom::Result>
3343
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3344
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3345
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3346
    
3347
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3348
    end_filter # will be removed at 2017/1/1
3349
    remove_end_filter # will be removed at 2017/1/1
3350
    remove_filter # will be removed at 2017/1/1
3351
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3352

            
3353
L<DBIx::Custom::Tag>
3354

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

            
3357
=head1 BACKWORD COMPATIBLE POLICY
3358

            
3359
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3360
except for attribute method.
3361
You can check all DEPRECATED functionalities by document.
3362
DEPRECATED functionality is removed after five years,
3363
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
3364
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3365

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

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

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

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

            
3374
C<< <kimoto.yuki at gmail.com> >>
3375

            
3376
L<http://github.com/yuki-kimoto/DBIx-Custom>
3377

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3378
=head1 AUTHOR
3379

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

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

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

            
3386
This program is free software; you can redistribute it and/or modify it
3387
under the same terms as Perl itself.
3388

            
3389
=cut