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

            
added test
Yuki Kimoto authored on 2011-08-16
23
has [qw/connector dsn password quote user exclude_table user_tables/],
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 test
Yuki Kimoto authored on 2011-08-16
326
    my $user_table_infos = $self->user_tables;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
327
    
added test
Yuki Kimoto authored on 2011-08-16
328
    # Iterate tables
329
    if ($user_table_infos) {
330
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
331
    }
332
    else {
333
        my $re = $self->exclude_table || $option{exclude};
334
        my $sth_tables = $self->dbh->table_info;
335
        while (my $table_info = $sth_tables->fetchrow_hashref) {
336
            
337
            # Table
338
            my $table = $table_info->{TABLE_NAME};
339
            next if defined $re && $table =~ /$re/;
340
            $self->$cb($table, $table_info);
341
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
342
    }
343
}
344

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

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

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

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

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

            
added test
Yuki Kimoto authored on 2011-08-16
523
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
524
    my ($self, %args) = @_;
525
    
526
    my $exclude = delete $args{exclude};
527
    croak qq/"$_" is wrong option/ for keys %args;
528
    
added test
Yuki Kimoto authored on 2011-08-16
529
    my $table_info = [];
530
    $self->each_table(
531
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
532
        exclude => $exclude
533
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
534
    
added test
Yuki Kimoto authored on 2011-08-16
535
    return $table_info;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
536
}
537

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
559
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
560
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
561
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
562
        $param = $self->merge_param($id_param, $param);
563
    }
564

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
598
sub include_model {
599
    my ($self, $name_space, $model_infos) = @_;
600
    
cleanup
Yuki Kimoto authored on 2011-04-02
601
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
602
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
603
    
604
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
605
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
606

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

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

            
689
        # Map parameter
690
        my $value;
691
        if (ref $condition eq 'CODE') {
692
            $map_param->{$map_key} = $value_cb->($param->{$key})
693
              if $condition->($param->{$key});
694
        }
695
        elsif ($condition eq 'exists') {
696
            $map_param->{$map_key} = $value_cb->($param->{$key})
697
              if exists $param->{$key};
698
        }
699
        else { croak qq/Condition must be code reference or "exists" / . _subname }
700
    }
701
    
702
    return $map_param;
703
}
704

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
729
sub method {
730
    my $self = shift;
731
    
cleanup
Yuki Kimoto authored on 2011-04-02
732
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
733
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
734
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
735
    
736
    return $self;
737
}
738

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
739
sub model {
740
    my ($self, $name, $model) = @_;
741
    
cleanup
Yuki Kimoto authored on 2011-04-02
742
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
743
    if ($model) {
744
        $self->models->{$name} = $model;
745
        return $self;
746
    }
747
    
748
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
749
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
750
      unless $self->models->{$name};
751
    
cleanup
Yuki Kimoto authored on 2011-04-02
752
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
753
    return $self->models->{$name};
754
}
755

            
cleanup
Yuki Kimoto authored on 2011-03-21
756
sub mycolumn {
757
    my ($self, $table, $columns) = @_;
758
    
cleanup
Yuki Kimoto authored on 2011-04-02
759
    # Create column clause
760
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
761
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
762
    push @column, $self->_q($table) . "." . $self->_q($_) .
763
      " as " . $self->_q($_)
764
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
765
    
766
    return join (', ', @column);
767
}
768

            
added dbi_options attribute
kimoto authored on 2010-12-20
769
sub new {
770
    my $self = shift->SUPER::new(@_);
771
    
cleanup
Yuki Kimoto authored on 2011-04-02
772
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
773
    my @attrs = keys %$self;
774
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
775
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
776
          unless $self->can($attr);
777
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
778

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
779
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
780
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
781
        '?'     => \&DBIx::Custom::Tag::placeholder,
782
        '='     => \&DBIx::Custom::Tag::equal,
783
        '<>'    => \&DBIx::Custom::Tag::not_equal,
784
        '>'     => \&DBIx::Custom::Tag::greater_than,
785
        '<'     => \&DBIx::Custom::Tag::lower_than,
786
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
787
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
788
        'like'  => \&DBIx::Custom::Tag::like,
789
        'in'    => \&DBIx::Custom::Tag::in,
790
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
791
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
792
    };
793
    
794
    return $self;
795
}
796

            
797
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
798
sub not_exists { $not_exists }
799

            
800
sub order {
801
    my $self = shift;
802
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
803
}
804

            
cleanup
yuki-kimoto authored on 2010-10-17
805
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
806
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
807
    
808
    # Register filter
809
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
810
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
811
    
cleanup
Yuki Kimoto authored on 2011-04-02
812
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
813
}
packaging one directory
yuki-kimoto authored on 2009-11-16
814

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
948
sub setup_model {
949
    my $self = shift;
950
    
cleanup
Yuki Kimoto authored on 2011-04-02
951
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
952
    $self->each_column(
953
        sub {
954
            my ($self, $table, $column, $column_info) = @_;
955
            if (my $model = $self->models->{$table}) {
956
                push @{$model->columns}, $column;
957
            }
958
        }
959
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
960
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
961
}
962

            
update pod
Yuki Kimoto authored on 2011-08-10
963
sub show_datatype {
964
    my ($self, $table) = @_;
965
    croak "Table name must be specified" unless defined $table;
966
    print "$table\n";
967
    
968
    my $result = $self->select(table => $table, where => "'0' <> '0'");
969
    my $sth = $result->sth;
970

            
971
    my $columns = $sth->{NAME};
972
    my $data_types = $sth->{TYPE};
973
    
974
    for (my $i = 0; $i < @$columns; $i++) {
975
        my $column = $columns->[$i];
976
        my $data_type = $data_types->[$i];
977
        print "$column: $data_type\n";
978
    }
979
}
980

            
981
sub show_typename {
982
    my ($self, $t) = @_;
983
    croak "Table name must be specified" unless defined $t;
984
    print "$t\n";
985
    
986
    $self->each_column(sub {
987
        my ($self, $table, $column, $infos) = @_;
988
        return unless $table eq $t;
989
        my $typename = $infos->{TYPE_NAME};
990
        print "$column: $typename\n";
991
    });
992
    
993
    return $self;
994
}
995

            
test cleanup
Yuki Kimoto authored on 2011-08-15
996
sub show_tables {
997
    my $self = shift;
998
    
999
    my %tables;
1000
    $self->each_table(sub { $tables{$_[1]}++ });
1001
    print join("\n", sort keys %tables) . "\n";
1002
    return $self;
1003
}
1004

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1038
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1039
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1040
                }
1041
            });
1042
        }
1043

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1132
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1133
    my ($self, $param, $opt) = @_;
1134
    
cleanup
Yuki Kimoto authored on 2011-04-02
1135
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1136
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1137
    $tag = "set $tag" unless $opt->{no_set};
1138

            
cleanup
Yuki Kimoto authored on 2011-04-02
1139
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1140
}
1141

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

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

            
1170
        # Create query
1171
        my $builder = $self->query_builder;
1172
        $query = $builder->build_query($source);
1173

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

            
1180
        # Save query to cache
1181
        $self->cache_method->(
1182
            $self, $source,
1183
            {
1184
                sql     => $query->sql, 
1185
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1186
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1187
            }
1188
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1189
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1190

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1323
sub _croak {
1324
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1325
    
1326
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1327
    $append ||= "";
1328
    
1329
    # Verbose
1330
    if ($Carp::Verbose) { croak $error }
1331
    
1332
    # Not verbose
1333
    else {
1334
        
1335
        # Remove line and module infromation
1336
        my $at_pos = rindex($error, ' at ');
1337
        $error = substr($error, 0, $at_pos);
1338
        $error =~ s/\s+$//;
1339
        croak "$error$append";
1340
    }
1341
}
1342

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1345
sub _need_tables {
1346
    my ($self, $tree, $need_tables, $tables) = @_;
1347
    
cleanup
Yuki Kimoto authored on 2011-04-02
1348
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1349
    foreach my $table (@$tables) {
1350
        if ($tree->{$table}) {
1351
            $need_tables->{$table} = 1;
1352
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1353
        }
1354
    }
1355
}
1356

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1422
sub _quote {
1423
    my $self = shift;
1424
    
1425
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1426
         : defined $self->quote ? $self->quote
1427
         : '';
1428
}
1429

            
cleanup
Yuki Kimoto authored on 2011-07-29
1430
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1431
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1432
    
1433
    my $quote = $self->_quote;
1434
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1435
    my $p;
1436
    if (defined $quote && length $quote > 1) {
1437
        $p = substr($quote, 1, 1);
1438
    }
1439
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1440
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1441
    if ($quotemeta) {
1442
        $q = quotemeta($q);
1443
        $p = quotemeta($p);
1444
    }
1445
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1446
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1447
}
1448

            
cleanup
Yuki Kimoto authored on 2011-04-02
1449
sub _remove_duplicate_table {
1450
    my ($self, $tables, $main_table) = @_;
1451
    
1452
    # Remove duplicate table
1453
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1454
    delete $tables{$main_table} if $main_table;
1455
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1456
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1457
    if (my $q = $self->_quote) {
1458
        $q = quotemeta($q);
1459
        $_ =~ s/[$q]//g for @$new_tables;
1460
    }
1461

            
1462
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1463
}
1464

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

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

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

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

            
1601
# DEPRECATED!
1602
sub create_query {
1603
    warn "create_query is DEPRECATED! use query option of each method";
1604
    shift->_create_query(@_);
1605
}
1606

            
cleanup
Yuki Kimoto authored on 2011-06-13
1607
# DEPRECATED!
1608
sub apply_filter {
1609
    my $self = shift;
1610
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1611
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1612
    return $self->_apply_filter(@_);
1613
}
1614

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

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

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

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

            
1650
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1651
    
1652
    # Arguments
1653
    my $primary_keys = delete $args{primary_key};
1654
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1655
    my $where = delete $args{where};
1656
    
1657
    # Check arguments
1658
    foreach my $name (keys %args) {
1659
        croak qq{"$name" is wrong option } . _subname
1660
          unless $DELETE_AT_ARGS{$name};
1661
    }
1662
    
1663
    # Create where parameter
1664
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1665
    
1666
    return $self->delete(where => $where_param, %args);
1667
}
1668

            
cleanup
Yuki Kimoto authored on 2011-06-08
1669
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1670
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1671
sub update_at {
1672
    my $self = shift;
1673

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

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

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

            
1741
# DEPRECATED!
1742
sub register_tag_processor {
1743
    my $self = shift;
1744
    warn "register_tag_processor is DEPRECATED!";
1745
    # Merge tag
1746
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1747
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1748
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1749
}
1750

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1751
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1752
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1753
has dbi_options => sub { {} };
1754
has filter_check  => 1;
1755
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1756

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1781
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1782
sub default_fetch_filter {
1783
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1784

            
cleanup
Yuki Kimoto authored on 2011-06-13
1785
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1786
    
1787
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1788
        my $fname = $_[0];
1789

            
cleanup
Yuki Kimoto authored on 2011-01-12
1790
        if (@_ && !$fname) {
1791
            $self->{default_in_filter} = undef;
1792
        }
1793
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1794
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1795
              unless exists $self->filters->{$fname};
1796
        
1797
            $self->{default_in_filter} = $self->filters->{$fname};
1798
        }
1799
        
1800
        return $self;
1801
    }
1802
    
many changed
Yuki Kimoto authored on 2011-01-23
1803
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1804
}
1805

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1806
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1807
sub insert_param_tag {
1808
    warn "insert_param_tag is DEPRECATED! " .
1809
         "use insert_param instead!";
1810
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1811
}
1812

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

            
1835
# DEPRECATED!
1836
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1837
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1838
    
1839
    if (keys %{$relation || {}}) {
1840
        foreach my $rcolumn (keys %$relation) {
1841
            my $table1 = (split (/\./, $rcolumn))[0];
1842
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1843
            my $table1_exists;
1844
            my $table2_exists;
1845
            foreach my $table (@$tables) {
1846
                $table1_exists = 1 if $table eq $table1;
1847
                $table2_exists = 1 if $table eq $table2;
1848
            }
1849
            unshift @$tables, $table1 unless $table1_exists;
1850
            unshift @$tables, $table2 unless $table2_exists;
1851
        }
1852
    }
1853
}
1854

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1857
=head1 NAME
1858

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

            
1861
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1862

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1863
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1864
    
1865
    # Connect
1866
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1867
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1868
        user => 'ken',
1869
        password => '!LFKD%$&',
1870
        dbi_option => {mysql_enable_utf8 => 1}
1871
    );
cleanup
yuki-kimoto authored on 2010-08-05
1872

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1873
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1874
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1875
    
1876
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1877
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1878
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1879
    
1880
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1881
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1882

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1932
Named place holder support
1933

            
1934
=item *
1935

            
cleanup
Yuki Kimoto authored on 2011-07-29
1936
Model support
1937

            
1938
=item *
1939

            
1940
Connection manager support
1941

            
1942
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1943

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

            
1948
=item *
1949

            
1950
Filtering by data type or column name(EXPERIMENTAL)
1951

            
1952
=item *
1953

            
1954
Create C<order by> clause flexibly(EXPERIMENTAL)
1955

            
1956
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1957

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1965
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1966
L<DBIx::Custom::Result>,
1967
L<DBIx::Custom::Query>,
1968
L<DBIx::Custom::Where>,
1969
L<DBIx::Custom::Model>,
1970
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1971

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

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

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

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

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

            
1985
    my $connector = DBIx::Connector->new(
1986
        "dbi:mysql:database=$DATABASE",
1987
        $USER,
1988
        $PASSWORD,
1989
        DBIx::Custom->new->default_dbi_option
1990
    );
1991
    
updated pod
Yuki Kimoto authored on 2011-06-21
1992
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1993

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

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

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

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

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

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

            
2009
=head2 C<default_dbi_option>
2010

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2017
    {
2018
        RaiseError => 1,
2019
        PrintError => 0,
2020
        AutoCommit => 1,
2021
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2022

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

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

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

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

            
2032
    my $last_sql = $dbi->last_sql;
2033
    $dbi = $dbi->last_sql($last_sql);
2034

            
2035
Get last successed SQL executed by C<execute> method.
2036

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2044
=head2 C<password>
2045

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2066
You can set quote pair.
2067

            
2068
    $dbi->quote('[]');
2069

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

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

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

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

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

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

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

            
2087
    my $separator = $self->separator;
2088
    $dbi = $self->separator($separator);
2089

            
2090
Separator whichi join table and column.
2091
This is used by C<column> and C<mycolumn> method.
2092

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

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

            
2098
Regex matching system table.
2099
this regex match is used by C<each_table> method and C<each_column> method
2100
System table is ignored.
2101
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2102
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2103
The performance is up.
2104

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

            
2107
    my $tag_parse = $dbi->tag_parse(0);
2108
    $dbi = $dbi->tag_parse;
2109

            
2110
Enable DEPRECATED tag parsing functionality, default to 1.
2111
If you want to disable tag parsing functionality, set to 0.
2112

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

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

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

            
added test
Yuki Kimoto authored on 2011-08-16
2120
=head2 C<user_table_info EXPERIMENTAL>
2121

            
2122
    my $user_table_info = $dbi->user_table_info;
2123
    $dbi = $dbi->user_table_info($user_table_info);
2124

            
2125
You can set the following data.
2126

            
2127
    [
2128
        {table => 'book', info => {...}},
2129
        {table => 'author', info => {...}}
2130
    ]
2131

            
2132
Usually, you can set return value of C<get_table_info>.
2133

            
2134
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2135
    $dbi->user_table_info($user_table_info);
2136

            
2137
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2138
to find table info.
2139

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2174
Create column clause. The follwoing column clause is created.
2175

            
2176
    book.author as "book.author",
2177
    book.title as "book.title"
2178

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2181
    # Separator is double underbar
2182
    $dbi->separator('__');
2183
    
2184
    book.author as "book__author",
2185
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2186

            
cleanup
Yuki Kimoto authored on 2011-06-13
2187
    # Separator is hyphen
2188
    $dbi->separator('-');
2189
    
2190
    book.author as "book-author",
2191
    book.title as "book-title"
2192
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2193
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2194

            
update pod
Yuki Kimoto authored on 2011-03-13
2195
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2196
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2197
        user => 'ken',
2198
        password => '!LFKD%$&',
2199
        dbi_option => {mysql_enable_utf8 => 1}
2200
    );
2201

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2210
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2211
        table => 'book',
2212
        primary_key => 'id',
2213
        join => [
2214
            'inner join company on book.comparny_id = company.id'
2215
        ],
2216
    );
2217

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

            
2221
   $dbi->model('book')->select(...);
2222

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

            
2225
    my $dbh = $dbi->dbh;
2226

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

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

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

            
2234
Execute delete statement.
2235

            
2236
The following opitons are available.
2237

            
2238
=over 4
2239

            
2240
=item C<append>
2241

            
2242
Same as C<select> method's C<append> option.
2243

            
2244
=item C<filter>
2245

            
2246
Same as C<execute> method's C<filter> option.
2247

            
2248
=item C<id>
2249

            
2250
    id => 4
2251
    id => [4, 5]
2252

            
2253
ID corresponding to C<primary_key>.
2254
You can delete rows by C<id> and C<primary_key>.
2255

            
2256
    $dbi->delete(
2257
        parimary_key => ['id1', 'id2'],
2258
        id => [4, 5],
2259
        table => 'book',
2260
    );
2261

            
2262
The above is same as the followin one.
2263

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

            
2266
=item C<prefix>
2267

            
2268
    prefix => 'some'
2269

            
2270
prefix before table name section.
2271

            
2272
    delete some from book
2273

            
2274
=item C<query>
2275

            
2276
Same as C<execute> method's C<query> option.
2277

            
2278
=item C<sqlfilter EXPERIMENTAL>
2279

            
2280
Same as C<execute> method's C<sqlfilter> option.
2281

            
2282
=item C<table>
2283

            
2284
    table => 'book'
2285

            
2286
Table name.
2287

            
2288
=item C<where>
2289

            
2290
Same as C<select> method's C<where> option.
2291

            
2292
=item C<primary_key>
2293

            
2294
See C<id> option.
2295

            
2296
=item C<bind_type>
2297

            
2298
Same as C<execute> method's C<bind_type> option.
2299

            
2300
=item C<type_rule_off> EXPERIMENTAL
2301

            
2302
Same as C<execute> method's C<type_rule_off> option.
2303

            
2304
=item C<type_rule1_off> EXPERIMENTAL
2305

            
2306
    type_rule1_off => 1
2307

            
2308
Same as C<execute> method's C<type_rule1_off> option.
2309

            
2310
=item C<type_rule2_off> EXPERIMENTAL
2311

            
2312
    type_rule2_off => 1
2313

            
2314
Same as C<execute> method's C<type_rule2_off> option.
2315

            
2316
=back
2317

            
2318
=head2 C<delete_all>
2319

            
2320
    $dbi->delete_all(table => $table);
2321

            
2322
Execute delete statement for all rows.
2323
Options is same as C<delete>.
2324

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

            
2327
    $dbi->each_column(
2328
        sub {
2329
            my ($dbi, $table, $column, $column_info) = @_;
2330
            
2331
            my $type = $column_info->{TYPE_NAME};
2332
            
2333
            if ($type eq 'DATE') {
2334
                # ...
2335
            }
2336
        }
2337
    );
2338

            
2339
Iterate all column informations of all table from database.
2340
Argument is callback when one column is found.
2341
Callback receive four arguments, dbi object, table name,
2342
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2343

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

            
2346
    $dbi->each_table(
2347
        sub {
2348
            my ($dbi, $table, $table_info) = @_;
2349
            
2350
            my $table_name = $table_info->{TABLE_NAME};
2351
        }
2352
    );
2353

            
2354
Iterate all table informationsfrom database.
2355
Argument is callback when one table is found.
2356
Callback receive three arguments, dbi object, table name,
2357
table information.
2358

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

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

            
2366
    my $result = $dbi->execute(
2367
      "select * from book where title = :book.title and author like :book.author",
2368
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2369
    );
2370

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2377
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2378
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2379
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2380
    select * from book where title = :title and author like :author
2381
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2382
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2383
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2384

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2388
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2389
    select * from book where :title{=} and :author{like}
2390
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2391
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2392
    select * from where title = ? and author like ?;
2393

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

            
2398
    select * from where title = "aa\\:bb";
2399

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

            
2402
=over 4
2403

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

            
2406
Specify database bind data type.
2407

            
2408
    bind_type => [image => DBI::SQL_BLOB]
2409
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2410

            
2411
This is used to bind parameter by C<bind_param> of statment handle.
2412

            
2413
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2414

            
update pod
Yuki Kimoto authored on 2011-03-13
2415
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2416
    
2417
    filter => {
2418
        title  => sub { uc $_[0] }
2419
        author => sub { uc $_[0] }
2420
    }
update pod
Yuki Kimoto authored on 2011-03-13
2421

            
updated pod
Yuki Kimoto authored on 2011-06-09
2422
    # Filter name
2423
    filter => {
2424
        title  => 'upper_case',
2425
        author => 'upper_case'
2426
    }
2427
        
2428
    # At once
2429
    filter => [
2430
        [qw/title author/]  => sub { uc $_[0] }
2431
    ]
2432

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

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

            
2440
    query => 1
2441

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

            
2445
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2446
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2447
    my $columns = $query->columns;
2448
    
2449
If you want to execute SQL fast, you can do the following way.
2450

            
2451
    my $query;
2452
    foreach my $row (@$rows) {
2453
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2454
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2455
    }
2456

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

            
2460
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
2461
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2462
    
2463
    my $query;
2464
    my $sth;
2465
    foreach my $row (@$rows) {
2466
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2467
      $sth ||= $query->sth;
2468
      $sth->execute(map { $row->{$_} } sort keys %$row);
2469
    }
2470

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

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

            
2477
SQL filter function.
2478

            
2479
    sqlfilter => $code_ref
2480

            
2481
This option is generally for Oracle and SQL Server paging process.
2482
    
2483
    my $limit = sub {
2484
        my ($sql, $count, $offset) = @_;
2485
        
2486
        my $min = $offset + 1;
2487
        my $max = $offset + $count;
2488
        
2489
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2490
        
2491
        return $sql;
2492
    }
2493
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2494
        my $sql = shift;
2495
        return $limit->($sql, 100, 50);
2496
    })
2497

            
updated pod
Yuki Kimoto authored on 2011-06-09
2498
=item C<table>
2499
    
2500
    table => 'author'
2501

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2509
    # Same
2510
    $dbi->execute(
2511
      "select * from book where title = :book.title and author = :book.author",
2512
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2513

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

            
2516
    table_alias => {user => 'hiker'}
2517

            
2518
Table alias. Key is real table name, value is alias table name.
2519
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2520
on alias table name.
2521

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

            
2524
    type_rule_off => 1
2525

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

            
2528
=item C<type_rule1_off> EXPERIMENTAL
2529

            
2530
    type_rule1_off => 1
2531

            
2532
Turn C<into1> type rule off.
2533

            
2534
=item C<type_rule2_off> EXPERIMENTAL
2535

            
2536
    type_rule2_off => 1
2537

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

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

            
added test
Yuki Kimoto authored on 2011-08-16
2542
=head2 C<get_table_info EXPERIMENTAL>
2543

            
2544
    my $tables = $self->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2545

            
added test
Yuki Kimoto authored on 2011-08-16
2546
get table infomation except for one which match C<exclude> pattern.
2547

            
2548
    [
2549
        {table => 'book', info => {...}},
2550
        {table => 'author', info => {...}}
2551
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2552

            
added test
Yuki Kimoto authored on 2011-08-16
2553
You can set this value to C<user_table_info>.
update pod
Yuki Kimoto authored on 2011-03-13
2554

            
cleanup
yuki-kimoto authored on 2010-10-17
2555
=head2 C<insert>
2556

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

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

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

            
2565
    {date => \"NOW()"}
2566

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

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

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

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

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

            
2577
Same as C<execute> method's C<bind_type> option.
2578

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

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

            
2583
=item C<id>
2584

            
updated document
Yuki Kimoto authored on 2011-06-09
2585
    id => 4
2586
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2587

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2591
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2592
        {title => 'Perl', author => 'Ken'}
2593
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2594
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2595
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2596
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2597

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

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

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

            
2607
    prefix => 'or replace'
2608

            
2609
prefix before table name section
2610

            
2611
    insert or replace into book
2612

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

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

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

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

            
2622
Same as C<execute> method's C<query> option.
2623

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

            
2626
Same as C<execute> method's C<sqlfilter> option.
2627

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

            
2630
    table => 'book'
2631

            
2632
Table name.
2633

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

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

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

            
2640
    type_rule1_off => 1
2641

            
2642
Same as C<execute> method's C<type_rule1_off> option.
2643

            
2644
=item C<type_rule2_off> EXPERIMENTAL
2645

            
2646
    type_rule2_off => 1
2647

            
2648
Same as C<execute> method's C<type_rule2_off> option.
2649

            
update pod
Yuki Kimoto authored on 2011-03-13
2650
=back
2651

            
2652
=over 4
2653

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2669
    lib / MyModel.pm
2670
        / MyModel / book.pm
2671
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2672

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

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

            
2677
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2678
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2679
    
2680
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2681

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2686
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2687
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2688
    
2689
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2690

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2693
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2694
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2695
    
2696
    1;
2697
    
updated pod
Yuki Kimoto authored on 2011-06-21
2698
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2699

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

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

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

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

            
2709
    my $map_param = $dbi->map_param(
2710
        {id => 1, authro => 'Ken', price => 1900},
2711
        'id' => 'book.id',
2712
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2713
        'price' => [
2714
            'book.price', {if => sub { length $_[0] }}
2715
        ]
2716
    );
2717

            
2718
Map paramters to other key and value. First argument is original
2719
parameter. this is hash reference. Rest argument is mapping.
2720
By default, Mapping is done if the value length is not zero.
2721

            
2722
=over 4
2723

            
2724
=item Key mapping
2725

            
2726
    'id' => 'book.id'
2727

            
2728
This is only key mapping. Value is same as original one.
2729

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

            
2732
=item Key and value mapping
2733

            
2734
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2735

            
2736
This is key and value mapping. Frist element of array reference
2737
is mapped key name, second element is code reference to map the value.
2738

            
2739
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2740
      if value length is not zero.
2741

            
2742
=item Condition
2743

            
2744
    'price' => ['book.price', {if => 'exists'}]
2745
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2746
    'price' => ['book.price', {if => sub { defined shift }}]
2747

            
2748
If you need condition, you can sepecify it. this is code reference
2749
or 'exists'. By default, condition is the following one.
2750

            
2751
    sub { defined $_[0] && length $_[0] }
2752

            
2753
=back
2754

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

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

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

            
2761
    {key1 => [1, 1], key2 => 2}
2762

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

            
2765
    $dbi->method(
2766
        update_or_insert => sub {
2767
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2768
            
2769
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2770
        },
2771
        find_or_create   => sub {
2772
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2773
            
2774
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2775
        }
2776
    );
2777

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

            
2780
    $dbi->update_or_insert;
2781
    $dbi->find_or_create;
2782

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

            
2785
    my $model = $dbi->model('book');
2786

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

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

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

            
2793
Create column clause for myself. The follwoing column clause is created.
2794

            
2795
    book.author as author,
2796
    book.title as title
2797

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2800
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2801
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2802
        user => 'ken',
2803
        password => '!LFKD%$&',
2804
        dbi_option => {mysql_enable_utf8 => 1}
2805
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2806

            
2807
Create a new L<DBIx::Custom> object.
2808

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

            
2811
    my $not_exists = $dbi->not_exists;
2812

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

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

            
2818
    my $order = $dbi->order;
2819

            
2820
Create a new L<DBIx::Custom::Order> object.
2821

            
cleanup
yuki-kimoto authored on 2010-10-17
2822
=head2 C<register_filter>
2823

            
update pod
Yuki Kimoto authored on 2011-03-13
2824
    $dbi->register_filter(
2825
        # Time::Piece object to database DATE format
2826
        tp_to_date => sub {
2827
            my $tp = shift;
2828
            return $tp->strftime('%Y-%m-%d');
2829
        },
2830
        # database DATE format to Time::Piece object
2831
        date_to_tp => sub {
2832
           my $date = shift;
2833
           return Time::Piece->strptime($date, '%Y-%m-%d');
2834
        }
2835
    );
cleanup
yuki-kimoto authored on 2010-10-17
2836
    
update pod
Yuki Kimoto authored on 2011-03-13
2837
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2838

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

            
2841
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2842
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2843
            date => sub { ... },
2844
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2845
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2846
        into2 => {
2847
            date => sub { ... },
2848
            datetime => sub { ... }
2849
        },
2850
        from1 => {
2851
            # DATE
2852
            9 => sub { ... },
2853
            # DATETIME or TIMESTAMP
2854
            11 => sub { ... },
2855
        }
2856
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2857
            # DATE
2858
            9 => sub { ... },
2859
            # DATETIME or TIMESTAMP
2860
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2861
        }
2862
    );
2863

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2879
=over 4
2880

            
2881
=item 1. column name
2882

            
2883
    issue_date
2884
    issue_datetime
2885

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

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

            
2890
    book.issue_date
2891
    book.issue_datetime
2892

            
2893
=back
2894

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

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

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

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

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

            
2907
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2908
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2909
            [qw/DATE DATETIME/] => sub { ... },
2910
        ],
2911
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2912

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2915
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2916
        table  => 'book',
2917
        column => ['author', 'title'],
2918
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2919
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2920
    
updated document
Yuki Kimoto authored on 2011-06-09
2921
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2922

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

            
2925
=over 4
2926

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

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

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

            
2933
=item C<bind_type>
2934

            
2935
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
2936
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2937
=item C<column>
2938
    
updated document
Yuki Kimoto authored on 2011-06-09
2939
    column => 'author'
2940
    column => ['author', 'title']
2941

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2950
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2951
        {book => [qw/author title/]},
2952
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2953
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2954

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

            
2957
    book.author as "book.author",
2958
    book.title as "book.title",
2959
    person.name as "person.name",
2960
    person.age as "person.age"
2961

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

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

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

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

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

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

            
2977
=item C<id>
2978

            
2979
    id => 4
2980
    id => [4, 5]
2981

            
2982
ID corresponding to C<primary_key>.
2983
You can select rows by C<id> and C<primary_key>.
2984

            
2985
    $dbi->select(
2986
        parimary_key => ['id1', 'id2'],
2987
        id => [4, 5],
2988
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2989
    );
2990

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2993
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2994
        where => {id1 => 4, id2 => 5},
2995
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2996
    );
2997
    
updated document
Yuki Kimoto authored on 2011-06-09
2998
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2999

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

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

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

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

            
3012
    prefix => 'SQL_CALC_FOUND_ROWS'
3013

            
3014
Prefix of column cluase
3015

            
3016
    select SQL_CALC_FOUND_ROWS title, author from book;
3017

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

            
3020
    join => [
3021
        'left outer join company on book.company_id = company_id',
3022
        'left outer join location on company.location_id = location.id'
3023
    ]
3024
        
3025
Join clause. If column cluase or where clause contain table name like "company.name",
3026
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3027

            
3028
    $dbi->select(
3029
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3030
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3031
        where => {'company.name' => 'Orange'},
3032
        join => [
3033
            'left outer join company on book.company_id = company.id',
3034
            'left outer join location on company.location_id = location.id'
3035
        ]
3036
    );
3037

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3041
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3042
    from book
3043
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3044
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3045

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

            
3049
    $dbi->select(
3050
        table => 'book',
3051
        column => ['company.location_id as location_id'],
3052
        where => {'company.name' => 'Orange'},
3053
        join => [
3054
            {
3055
                clause => 'left outer join location on company.location_id = location.id',
3056
                table => ['company', 'location']
3057
            }
3058
        ]
3059
    );
3060

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3080
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3081

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

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

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

            
3088
    type_rule1_off => 1
3089

            
3090
Same as C<execute> method's C<type_rule1_off> option.
3091

            
3092
=item C<type_rule2_off> EXPERIMENTAL
3093

            
3094
    type_rule2_off => 1
3095

            
3096
Same as C<execute> method's C<type_rule2_off> option.
3097

            
updated document
Yuki Kimoto authored on 2011-06-09
3098
=item C<where>
3099
    
3100
    # Hash refrence
3101
    where => {author => 'Ken', 'title' => 'Perl'}
3102
    
3103
    # DBIx::Custom::Where object
3104
    where => $dbi->where(
3105
        clause => ['and', 'author = :author', 'title like :title'],
3106
        param  => {author => 'Ken', title => '%Perl%'}
3107
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3108
    
3109
    # Array reference 1 (array reference, hash referenc). same as above
3110
    where => [
3111
        ['and', 'author = :author', 'title like :title'],
3112
        {author => 'Ken', title => '%Perl%'}
3113
    ];    
3114
    
3115
    # Array reference 2 (String, hash reference)
3116
    where => [
3117
        'title like :title',
3118
        {title => '%Perl%'}
3119
    ]
3120
    
3121
    # String
3122
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3123

            
updated document
Yuki Kimoto authored on 2011-06-09
3124
Where clause.
3125
    
improved pod
Yuki Kimoto authored on 2011-04-19
3126
=item C<wrap> EXPERIMENTAL
3127

            
3128
Wrap statement. This is array reference.
3129

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

            
3132
This option is for Oracle and SQL Server paging process.
3133

            
update pod
Yuki Kimoto authored on 2011-03-12
3134
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3135

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

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

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

            
3142
If you want to set constant value to row data, use scalar reference
3143
as parameter value.
3144

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3149
=over 4
3150

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

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

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

            
3157
Same as C<execute> method's C<bind_type> option.
3158

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3165
    id => 4
3166
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3167

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3171
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3172
        {title => 'Perl', author => 'Ken'}
3173
        parimary_key => ['id1', 'id2'],
3174
        id => [4, 5],
3175
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3176
    );
update pod
Yuki Kimoto authored on 2011-03-13
3177

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3180
    $dbi->update(
3181
        {title => 'Perl', author => 'Ken'}
3182
        where => {id1 => 4, id2 => 5},
3183
        table => 'book'
3184
    );
update pod
Yuki Kimoto authored on 2011-03-13
3185

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

            
3188
    prefix => 'or replace'
3189

            
3190
prefix before table name section
3191

            
3192
    update or replace book
3193

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

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

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

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

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

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

            
3207
Same as C<execute> method's C<sqlfilter> option.
3208

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

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

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

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

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

            
3219
=item C<type_rule1_off> EXPERIMENTAL
3220

            
3221
    type_rule1_off => 1
3222

            
3223
Same as C<execute> method's C<type_rule1_off> option.
3224

            
3225
=item C<type_rule2_off> EXPERIMENTAL
3226

            
3227
    type_rule2_off => 1
3228

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

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

            
3233
Same as C<select> method's C<where> option.
3234

            
updated pod
Yuki Kimoto authored on 2011-06-08
3235
=back
update pod
Yuki Kimoto authored on 2011-03-13
3236

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

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

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

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

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

            
3248
Create update parameter tag.
3249

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

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

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

            
3259
Create a new L<DBIx::Custom::Where> object.
3260

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

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

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

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

            
3270
=head2 C<DBIX_CUSTOM_DEBUG>
3271

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

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

            
3277
    $dbi->show_datatype($table);
3278

            
3279
Show data type of the columns of specified table.
3280

            
3281
    book
3282
    title: 5
3283
    issue_date: 91
3284

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

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

            
3289
    $dbi->show_tables;
3290

            
3291
Show tables.
3292

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

            
3295
    $dbi->show_typename($table);
3296

            
3297
Show type name of the columns of specified table.
3298

            
3299
    book
3300
    title: varchar
3301
    issue_date: date
3302

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

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

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

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

            
3311
L<DBIx::Custom>
3312

            
3313
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3314
    data_source # will be removed at 2017/1/1
3315
    dbi_options # will be removed at 2017/1/1
3316
    filter_check # will be removed at 2017/1/1
3317
    reserved_word_quote # will be removed at 2017/1/1
3318
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3319
    
3320
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3321
    create_query # will be removed at 2017/1/1
3322
    apply_filter # will be removed at 2017/1/1
3323
    select_at # will be removed at 2017/1/1
3324
    delete_at # will be removed at 2017/1/1
3325
    update_at # will be removed at 2017/1/1
3326
    insert_at # will be removed at 2017/1/1
3327
    register_tag # will be removed at 2017/1/1
3328
    default_bind_filter # will be removed at 2017/1/1
3329
    default_fetch_filter # will be removed at 2017/1/1
3330
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3331
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3332
    register_tag_processor # will be removed at 2017/1/1
3333
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3334
    
3335
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3336
    select method relation option # will be removed at 2017/1/1
3337
    select method param option # will be removed at 2017/1/1
3338
    select method column option [COLUMN, as => ALIAS] format
3339
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3340
    
3341
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3342
    execute("select * from {= title}"); # execute method's
3343
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3344
                                        # will be removed at 2017/1/1
3345
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3346

            
3347
L<DBIx::Custom::Model>
3348

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3349
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3350
    filter # will be removed at 2017/1/1
3351
    name # will be removed at 2017/1/1
3352
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3353

            
3354
L<DBIx::Custom::Query>
3355
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3356
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3357
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3358
    table # will be removed at 2017/1/1
3359
    filters # will be removed at 2017/1/1
3360
    
3361
    # Methods
3362
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3363

            
3364
L<DBIx::Custom::QueryBuilder>
3365
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3366
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3367
    tags # will be removed at 2017/1/1
3368
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3369
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3370
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3371
    register_tag # will be removed at 2017/1/1
3372
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3373
    
3374
    # Others
3375
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3376
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3377

            
3378
L<DBIx::Custom::Result>
3379
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3380
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3381
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3382
    
3383
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3384
    end_filter # will be removed at 2017/1/1
3385
    remove_end_filter # will be removed at 2017/1/1
3386
    remove_filter # will be removed at 2017/1/1
3387
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3388

            
3389
L<DBIx::Custom::Tag>
3390

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

            
3393
=head1 BACKWORD COMPATIBLE POLICY
3394

            
3395
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3396
except for attribute method.
3397
You can check all DEPRECATED functionalities by document.
3398
DEPRECATED functionality is removed after five years,
3399
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
3400
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3401

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

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

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

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

            
3410
C<< <kimoto.yuki at gmail.com> >>
3411

            
3412
L<http://github.com/yuki-kimoto/DBIx-Custom>
3413

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3414
=head1 AUTHOR
3415

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

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

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

            
3422
This program is free software; you can redistribute it and/or modify it
3423
under the same terms as Perl itself.
3424

            
3425
=cut