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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
4
our $VERSION = '0.1728';
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/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
101
our $AUTOLOAD;
102
sub AUTOLOAD {
103
    my $self = shift;
104

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
122
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
123
    my ($self, $param, $opts) = @_;
124
    
125
    my $wrap = $opts->{wrap} || {};
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
    
127
    # Create set tag
128
    my @params;
129
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
130
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
131
        croak qq{"$column" is not safety column name } . _subname
132
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
133
        my $column_quote = $self->_q($column);
134
        $column_quote =~ s/\./$self->_q(".")/e;
updated pod
Yuki Kimoto authored on 2011-09-02
135
        my $func = $wrap->{$column} || sub { $_[0] };
136
        push @params,
137
          ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}}
138
        : "$column_quote = " . $func->(":$column");
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
139
    }
140
    my $tag = join(', ', @params);
141
    
142
    return $tag;
143
}
144

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
170
sub connect {
cleanup
Yuki Kimoto authored on 2011-08-16
171
    my $self = ref $_[0] ? shift : shift->new(@_);
172
    
173
    my $connector = $self->connector;
174
    
175
    if (!ref $connector && $connector) {
176
        require DBIx::Connector;
177
        
178
        my $dsn = $self->dsn;
179
        my $user = $self->user;
180
        my $password = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
181
        my $option = $self->_option;
cleanup
Yuki Kimoto authored on 2011-08-16
182
        my $connector = DBIx::Connector->new($dsn, $user, $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
183
          {%{$self->default_option} , %$option});
cleanup
Yuki Kimoto authored on 2011-08-16
184
        $self->connector($connector);
185
    }
removed register_format()
yuki-kimoto authored on 2010-05-26
186
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
187
    # Connect
188
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
189
    
packaging one directory
yuki-kimoto authored on 2009-11-16
190
    return $self;
191
}
192

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
193
sub count { shift->select(column => 'count(*)', @_)->fetch_first->[0] }
194

            
update pod
Yuki Kimoto authored on 2011-03-13
195
sub dbh {
196
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
197
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
198
    # Set
199
    if (@_) {
200
        $self->{dbh} = $_[0];
201
        
202
        return $self;
203
    }
204
    
205
    # Get
206
    else {
207
        # From Connction manager
208
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
209
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
210
              unless ref $connector && $connector->can('dbh');
211
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
212
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
213
        }
214
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
215
        # Connect
216
        $self->{dbh} ||= $self->_connect;
217
        
218
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
219
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
220
            my $driver = $self->_driver;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
221
            my $quote =  $driver eq 'odbc' ? '[]'
222
                       : $driver eq 'ado' ? '[]'
223
                       : $driver eq 'mysql' ? '`'
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
224
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
225
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
226
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
227
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
228
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
229
    }
230
}
231

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

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
235
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
236
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
237
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
238
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
239
    my $where            = delete $args{where} || {};
240
    my $append           = delete $args{append};
241
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
242
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
243
    my $id = delete $args{id};
244
    my $primary_key = delete $args{primary_key};
245
    croak "update method primary_key option " .
246
          "must be specified when id is specified " . _subname
247
      if defined $id && !defined $primary_key;
248
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
249
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
250
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
251
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
252
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
253
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
254
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
255
        $where_clause = "where " . $where->[0];
256
        $where_param = $where->[1];
257
    }
258
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
259
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
260
        $where_param = keys %$where_param
261
                     ? $self->merge_param($where_param, $where->param)
262
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
263
        
264
        # String where
265
        $where_clause = $where->to_string;
266
    }
267
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
268
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
269
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
270

            
cleanup
Yuki Kimoto authored on 2011-04-02
271
    # Delete statement
micro optimization
Yuki Kimoto authored on 2011-09-30
272
    my $sql;
273
    $sql .= "delete ";
274
    $sql .= "$prefix " if defined $prefix;
275
    $sql .= "from " . $self->_q($table) . " $where_clause ";
276
    $sql .= $append if defined $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
277
    
278
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
279
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
280
}
281

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
286
sub create_model {
287
    my $self = shift;
288
    
cleanup
Yuki Kimoto authored on 2011-04-02
289
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
290
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
291
    $args->{dbi} = $self;
292
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
293
    my $model_name  = delete $args->{name};
294
    my $model_table = delete $args->{table};
295
    $model_name ||= $model_table;
296
    
cleanup
Yuki Kimoto authored on 2011-04-02
297
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
298
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
299
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
300
    $model->name($model_name) unless $model->name;
301
    $model->table($model_table) unless $model->table;
302
    
micro optimization
Yuki Kimoto authored on 2011-07-30
303
    # Apply filter(DEPRECATED logic)
304
    if ($model->{filter}) {
305
        my $filter = ref $model->filter eq 'HASH'
306
                   ? [%{$model->filter}]
307
                   : $model->filter;
308
        $filter ||= [];
309
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
310
          if @$filter;
311
        $self->_apply_filter($model->table, @$filter);
312
    }
313
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
314
    # Set model
315
    $self->model($model->name, $model);
316
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
317
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
318
}
319

            
320
sub each_column {
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
321
    my ($self, $cb, %options) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
322

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
323
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
324
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
325
    if ($user_column_info) {
326
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
327
    }
328
    else {
329
    
330
        my $re = $self->exclude_table || $options{exclude_table};
331
        # Tables
332
        my %tables;
333
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
334

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
335
        # Iterate all tables
336
        my @tables = sort keys %tables;
337
        for (my $i = 0; $i < @tables; $i++) {
338
            my $table = $tables[$i];
339
            
340
            # Iterate all columns
341
            my $sth_columns;
342
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
343
            next if $@;
344
            while (my $column_info = $sth_columns->fetchrow_hashref) {
345
                my $column = $column_info->{COLUMN_NAME};
346
                $self->$cb($table, $column, $column_info);
347
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
348
        }
349
    }
350
}
351

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
352
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
353
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
354
    
cleanup test
Yuki Kimoto authored on 2011-08-16
355
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
356
    
added test
Yuki Kimoto authored on 2011-08-16
357
    # Iterate tables
358
    if ($user_table_infos) {
359
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
360
    }
361
    else {
362
        my $re = $self->exclude_table || $option{exclude};
363
        my $sth_tables = $self->dbh->table_info;
364
        while (my $table_info = $sth_tables->fetchrow_hashref) {
365
            
366
            # Table
367
            my $table = $table_info->{TABLE_NAME};
368
            next if defined $re && $table =~ /$re/;
369
            $self->$cb($table, $table_info);
370
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
371
    }
372
}
373

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
374
our %VALID_ARGS = map { $_ => 1 } qw/append after_build_sql allow_delete_all
simplified arguments check
Yuki Kimoto authored on 2011-07-11
375
  allow_update_all bind_type column filter id join param prefix primary_key
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
376
  query relation sqlfilter table table_alias timestamp type type_rule_off
377
  type_rule1_off type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
378

            
379
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
380
    my $self = shift;
381
    my $query = shift;
382
    my $param;
383
    $param = shift if @_ % 2;
384
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
385
    
cleanup
Yuki Kimoto authored on 2011-04-02
386
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
387
    my $p = delete $args{param} || {};
388
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
389
    my $tables = delete $args{table} || [];
390
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
391
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
392
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
393
    my $bind_type = delete $args{bind_type} || delete $args{type};
394
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
395
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
396
    my $type_rule_off_parts = {
397
        1 => delete $args{type_rule1_off},
398
        2 => delete $args{type_rule2_off}
399
    };
cleanup
Yuki Kimoto authored on 2011-06-09
400
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
401
    my $table_alias = delete $args{table_alias} || {};
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
402
    my $after_build_sql = $args{after_build_sql} || $args{sqlfilter};
403
    warn "sqlfilter option is DEPRECATED" if $args{sqlfilter};
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
404
    my $id = delete $args{id};
405
    my $primary_key = delete $args{primary_key};
406
    croak "insert method primary_key option " .
407
          "must be specified when id is specified " . _subname
408
      if defined $id && !defined $primary_key;
409
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
410

            
411
    if (defined $id) {
412
        my $id_param = $self->_create_param_from_id($id, $primary_key);
413
        $param = $self->merge_param($id_param, $param);
414
    }
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
415
    
cleanup
Yuki Kimoto authored on 2011-03-09
416
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
417
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
418
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
419
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
420
    }
421
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
422
    $query = $self->_create_query($query, $after_build_sql) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
423
    
424
    # Save query
425
    $self->last_sql($query->sql);
426

            
cleanup
Yuki Kimoto authored on 2011-06-09
427
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
428
    
429
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
430
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
431
    
cleanup
Yuki Kimoto authored on 2011-04-02
432
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
433
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
434
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
435
    
micro optimization
Yuki Kimoto authored on 2011-07-30
436
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
437
    $tables = $self->_remove_duplicate_table($tables, $main_table)
438
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
439
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
440
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
441
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
442
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
443
        foreach my $i (1, 2) {
444
            unless ($type_rule_off_parts->{$i}) {
445
                $type_filters->{$i} = {};
446
                foreach my $alias (keys %$table_alias) {
447
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
448
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
449
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
450
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
451
                    }
452
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
453
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
454
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
455
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
456
        }
457
    }
cleanup
Yuki Kimoto authored on 2011-04-02
458
    
micro optimization
Yuki Kimoto authored on 2011-07-30
459
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
460
    if ($self->{filter}{on}) {
461
        my $applied_filter = {};
462
        foreach my $table (@$tables) {
463
            $applied_filter = {
464
                %$applied_filter,
465
                %{$self->{filter}{out}->{$table} || {}}
466
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
467
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
468
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
469
    }
470
    
cleanup
Yuki Kimoto authored on 2011-04-02
471
    # Replace filter name to code
472
    foreach my $column (keys %$filter) {
473
        my $name = $filter->{$column};
474
        if (!defined $name) {
475
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
476
        }
cleanup
Yuki Kimoto authored on 2011-04-02
477
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
478
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
479
            unless exists $self->filters->{$name};
480
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
481
        }
482
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
483
    
cleanup
Yuki Kimoto authored on 2011-04-02
484
    # Create bind values
485
    my $bind = $self->_create_bind_values(
486
        $param,
487
        $query->columns,
488
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
489
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
490
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
491
    );
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
492

            
cleanup
yuki-kimoto authored on 2010-10-17
493
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
494
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
495
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
496
    eval {
497
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
498
            my $bind_type = $bind->[$i]->{bind_type};
499
            $sth->bind_param(
500
                $i + 1,
501
                $bind->[$i]->{value},
502
                $bind_type ? $bind_type : ()
503
            );
cleanup
Yuki Kimoto authored on 2011-03-21
504
        }
505
        $affected = $sth->execute;
506
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
507
    
micro optimization
Yuki Kimoto authored on 2011-07-30
508
    $self->_croak($@, qq{. Following SQL is executed.\n}
509
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
510
    
improved debug message
Yuki Kimoto authored on 2011-05-23
511
    # DEBUG message
512
    if (DEBUG) {
513
        print STDERR "SQL:\n" . $query->sql . "\n";
514
        my @output;
515
        foreach my $b (@$bind) {
516
            my $value = $b->{value};
517
            $value = 'undef' unless defined $value;
518
            $value = encode(DEBUG_ENCODING(), $value)
519
              if utf8::is_utf8($value);
520
            push @output, $value;
521
        }
522
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
523
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
524
    
cleanup
Yuki Kimoto authored on 2011-04-02
525
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
526
    if ($sth->{NUM_OF_FIELDS}) {
527
        
micro optimization
Yuki Kimoto authored on 2011-07-30
528
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
529
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
530
        if ($self->{filter}{on}) {
531
            $filter->{in}  = {};
532
            $filter->{end} = {};
533
            push @$tables, $main_table if $main_table;
534
            foreach my $table (@$tables) {
535
                foreach my $way (qw/in end/) {
536
                    $filter->{$way} = {
537
                        %{$filter->{$way}},
538
                        %{$self->{filter}{$way}{$table} || {}}
539
                    };
540
                }
cleanup
Yuki Kimoto authored on 2011-04-02
541
            }
cleanup
Yuki Kimoto authored on 2011-01-12
542
        }
543
        
544
        # Result
545
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
546
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
547
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
548
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
549
            filter => $filter->{in} || {},
550
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
551
            type_rule => {
552
                from1 => $self->type_rule->{from1},
553
                from2 => $self->type_rule->{from2}
554
            },
cleanup
yuki-kimoto authored on 2010-10-17
555
        );
556

            
557
        return $result;
558
    }
cleanup
Yuki Kimoto authored on 2011-04-02
559
    
560
    # Not select statement
561
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
562
}
563

            
added test
Yuki Kimoto authored on 2011-08-16
564
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
565
    my ($self, %args) = @_;
566
    
567
    my $exclude = delete $args{exclude};
568
    croak qq/"$_" is wrong option/ for keys %args;
569
    
added test
Yuki Kimoto authored on 2011-08-16
570
    my $table_info = [];
571
    $self->each_table(
572
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
573
        exclude => $exclude
574
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
575
    
cleanup test
Yuki Kimoto authored on 2011-08-16
576
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
577
}
578

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
579
sub get_column_info {
580
    my ($self, %args) = @_;
581
    
582
    my $exclude_table = delete $args{exclude_table};
583
    croak qq/"$_" is wrong option/ for keys %args;
584
    
585
    my $column_info = [];
586
    $self->each_column(
587
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
588
        exclude_table => $exclude_table
589
    );
590
    
591
    return [
592
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
593
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
594
}
595

            
cleanup
yuki-kimoto authored on 2010-10-17
596
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
597
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
598
    
cleanup
yuki-kimoto authored on 2010-10-17
599
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
600
    my $param;
601
    $param = shift if @_ % 2;
602
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
603
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
604
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
605
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
606
    my $p = delete $args{param} || {};
607
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
608
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
609
    my $id = delete $args{id};
610
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
611
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
612
          "must be specified when id is specified " . _subname
613
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
614
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
615
    my $prefix = delete $args{prefix};
updated pod
Yuki Kimoto authored on 2011-09-02
616
    my $wrap = delete $args{wrap};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
617
    my $timestamp = $args{timestamp};
618
    
619
    # Timestamp
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
620
    if ($timestamp && (my $insert_timestamp = $self->insert_timestamp)) {
621
        my $columns = $insert_timestamp->[0];
622
        $columns = [$columns] unless ref $columns eq 'ARRAY';
623
        my $value = $insert_timestamp->[1];
624
        $value = $value->() if ref $value eq 'CODE';
625
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
626
    }
cleanup
Yuki Kimoto authored on 2011-04-02
627

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
628
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
629
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
630
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
631
        $param = $self->merge_param($id_param, $param);
632
    }
633

            
cleanup
Yuki Kimoto authored on 2011-04-02
634
    # Insert statement
micro optimization
Yuki Kimoto authored on 2011-09-30
635
    my $sql;
636
    $sql .= "insert ";
637
    $sql .= "$prefix " if defined $prefix;
638
    $sql .= "into " . $self->_q($table) . " "
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
639
      . $self->values_clause($param, {wrap => $wrap}) . " ";
micro optimization
Yuki Kimoto authored on 2011-09-30
640
    $sql .= $append if defined $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
641
    
642
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
643
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
644
}
645

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
646
sub values_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
647
    my ($self, $param, $opts) = @_;
648
    
649
    my $wrap = $opts->{wrap} || {};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
650
    
cleanup
Yuki Kimoto authored on 2011-04-02
651
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
652
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
653
    my @columns;
654
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
655
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
656
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
657
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
658
        my $column_quote = $self->_q($column);
659
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
660
        push @columns, $column_quote;
updated pod
Yuki Kimoto authored on 2011-09-02
661
        
662
        my $func = $wrap->{$column} || sub { $_[0] };
663
        push @placeholders,
664
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
665
        : $func->(":$column");
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
666
    }
667
    
cleanup
Yuki Kimoto authored on 2011-04-02
668
    return '(' . join(', ', @columns) . ') ' . 'values ' .
669
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
670
}
671

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
672
sub insert_timestamp {
673
    my $self = shift;
674
    
675
    if (@_) {
676
        $self->{insert_timestamp} = [@_];
677
        
678
        return $self;
679
    }
680
    return $self->{insert_timestamp};
681
}
682

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
683
sub include_model {
684
    my ($self, $name_space, $model_infos) = @_;
685
    
cleanup
Yuki Kimoto authored on 2011-04-02
686
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
687
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
688
    
689
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
690
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
691

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
692
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
693
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
694
          if $name_space =~ /[^\w:]/;
695
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
696
        croak qq{Name space module "$name_space.pm" is needed. $@ }
697
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
698
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
699
        
700
        # Search model modules
701
        my $path = $INC{"$name_space.pm"};
702
        $path =~ s/\.pm$//;
703
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
704
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
705
        $model_infos = [];
706
        while (my $module = readdir $dh) {
707
            push @$model_infos, $module
708
              if $module =~ s/\.pm$//;
709
        }
710
        close $dh;
711
    }
712
    
cleanup
Yuki Kimoto authored on 2011-04-02
713
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
714
    foreach my $model_info (@$model_infos) {
715
        
cleanup
Yuki Kimoto authored on 2011-04-02
716
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
717
        my $model_class;
718
        my $model_name;
719
        my $model_table;
720
        if (ref $model_info eq 'HASH') {
721
            $model_class = $model_info->{class};
722
            $model_name  = $model_info->{name};
723
            $model_table = $model_info->{table};
724
            
725
            $model_name  ||= $model_class;
726
            $model_table ||= $model_name;
727
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
728
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
729
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
730
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
731
          if $mclass =~ /[^\w:]/;
732
        unless ($mclass->can('isa')) {
733
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
734
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
735
        }
736
        
cleanup
Yuki Kimoto authored on 2011-04-02
737
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
738
        my $args = {};
739
        $args->{model_class} = $mclass if $mclass;
740
        $args->{name}        = $model_name if $model_name;
741
        $args->{table}       = $model_table if $model_table;
742
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
743
    }
744
    
745
    return $self;
746
}
747

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
748
sub like_value { sub { "%$_[0]%" } }
749

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
750
sub mapper {
751
    my $self = shift;
752
    return DBIx::Custom::Mapper->new(@_);
753
}
754

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
755
sub merge_param {
756
    my ($self, @params) = @_;
757
    
cleanup
Yuki Kimoto authored on 2011-04-02
758
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
759
    my $merge = {};
760
    foreach my $param (@params) {
761
        foreach my $column (keys %$param) {
762
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
763
            
764
            if (exists $merge->{$column}) {
765
                $merge->{$column} = [$merge->{$column}]
766
                  unless ref $merge->{$column} eq 'ARRAY';
767
                push @{$merge->{$column}},
768
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
769
            }
770
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
771
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
772
            }
773
        }
774
    }
775
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
776
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
777
}
778

            
cleanup
Yuki Kimoto authored on 2011-03-21
779
sub method {
780
    my $self = shift;
781
    
cleanup
Yuki Kimoto authored on 2011-04-02
782
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
783
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
784
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
785
    
786
    return $self;
787
}
788

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
789
sub model {
790
    my ($self, $name, $model) = @_;
791
    
cleanup
Yuki Kimoto authored on 2011-04-02
792
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
793
    if ($model) {
794
        $self->models->{$name} = $model;
795
        return $self;
796
    }
797
    
798
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
799
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
800
      unless $self->models->{$name};
801
    
cleanup
Yuki Kimoto authored on 2011-04-02
802
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
803
    return $self->models->{$name};
804
}
805

            
cleanup
Yuki Kimoto authored on 2011-03-21
806
sub mycolumn {
807
    my ($self, $table, $columns) = @_;
808
    
cleanup
Yuki Kimoto authored on 2011-04-02
809
    # Create column clause
810
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
811
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
812
    push @column, $self->_q($table) . "." . $self->_q($_) .
813
      " as " . $self->_q($_)
814
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
815
    
816
    return join (', ', @column);
817
}
818

            
added dbi_options attribute
kimoto authored on 2010-12-20
819
sub new {
820
    my $self = shift->SUPER::new(@_);
821
    
cleanup
Yuki Kimoto authored on 2011-04-02
822
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
823
    my @attrs = keys %$self;
824
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
825
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
826
          unless $self->can($attr);
827
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
828

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
829
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
830
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
831
        '?'     => \&DBIx::Custom::Tag::placeholder,
832
        '='     => \&DBIx::Custom::Tag::equal,
833
        '<>'    => \&DBIx::Custom::Tag::not_equal,
834
        '>'     => \&DBIx::Custom::Tag::greater_than,
835
        '<'     => \&DBIx::Custom::Tag::lower_than,
836
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
837
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
838
        'like'  => \&DBIx::Custom::Tag::like,
839
        'in'    => \&DBIx::Custom::Tag::in,
840
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
841
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
842
    };
843
    
844
    return $self;
845
}
846

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
847
sub not_exists { DBIx::Custom::NotExists->singleton }
cleanup
Yuki Kimoto authored on 2011-08-13
848

            
849
sub order {
850
    my $self = shift;
851
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
852
}
853

            
cleanup
yuki-kimoto authored on 2010-10-17
854
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
855
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
856
    
857
    # Register filter
858
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
859
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
860
    
cleanup
Yuki Kimoto authored on 2011-04-02
861
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
862
}
packaging one directory
yuki-kimoto authored on 2009-11-16
863

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
867
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
868
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
869
    my $tables = ref $table eq 'ARRAY' ? $table
870
               : defined $table ? [$table]
871
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
872
    my $columns   = delete $args{column};
873
    my $where     = delete $args{where} || {};
874
    my $append    = delete $args{append};
875
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
876
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
877
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
878
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
879
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
880
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
881
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
882
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
883
      if keys %$param;
884
    my $where_param = delete $args{where_param} || $param || {};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
885
    my $id = delete $args{id};
886
    my $primary_key = delete $args{primary_key};
887
    croak "update method primary_key option " .
888
          "must be specified when id is specified " . _subname
889
      if defined $id && !defined $primary_key;
890
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
891
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
892
    
cleanup
Yuki Kimoto authored on 2011-03-09
893
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
894
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
895
    
cleanup
Yuki Kimoto authored on 2011-04-02
896
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
897
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
898
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
899
    # Prefix
micro optimization
Yuki Kimoto authored on 2011-09-30
900
    $sql .= "$prefix " if defined $prefix;
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
901
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
902
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
903
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
904
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
905
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
906
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
907
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
908
            }
909
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
910
                if (@$column == 3 && $column->[1] eq 'as') {
911
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
912
                    splice @$column, 1, 1;
913
                }
914
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
915
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
916
            }
cleanup
Yuki Kimoto authored on 2011-04-02
917
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
918
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
919
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
920
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
921
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
922
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
923
    
924
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
925
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-03-30
926
    if ($relation) {
927
        my $found = {};
928
        foreach my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
929
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
930
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
931
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
932
    }
cleanup
Yuki Kimoto authored on 2011-03-30
933
    else {
934
        my $main_table = $tables->[-1] || '';
micro optimization
Yuki Kimoto authored on 2011-09-30
935
        $sql .= $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
936
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
937
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-04-25
938
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
939
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
940

            
cleanup
Yuki Kimoto authored on 2011-04-02
941
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
942
    unshift @$tables,
943
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
944
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
945
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
946
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
947
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
948
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
949
        $where_clause = "where " . $where->[0];
950
        $where_param = $where->[1];
951
    }
952
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
953
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
954
        $where_param = keys %$where_param
955
                     ? $self->merge_param($where_param, $where->param)
956
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
957
        
958
        # String where
959
        $where_clause = $where->to_string;
960
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
961
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
962
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
963
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
964
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
965
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
966
    # Push join
micro optimization
Yuki Kimoto authored on 2011-09-30
967
    $self->_push_join(\$sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
968
    
cleanup
Yuki Kimoto authored on 2011-03-09
969
    # Add where clause
micro optimization
Yuki Kimoto authored on 2011-09-30
970
    $sql .= "$where_clause ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
971
    
cleanup
Yuki Kimoto authored on 2011-03-08
972
    # Relation(DEPRECATED!);
micro optimization
Yuki Kimoto authored on 2011-09-30
973
    $self->_push_relation(\$sql, $tables, $relation, $where_clause eq '' ? 1 : 0)
974
      if $relation;
cleanup
Yuki Kimoto authored on 2011-03-08
975
    
cleanup
Yuki Kimoto authored on 2011-04-02
976
    # Append
micro optimization
Yuki Kimoto authored on 2011-09-30
977
    $sql .= $append if defined $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
978
    
979
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
980
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
981
    
982
    return $result;
983
}
984

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
985
sub setup_model {
986
    my $self = shift;
987
    
cleanup
Yuki Kimoto authored on 2011-04-02
988
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
989
    $self->each_column(
990
        sub {
991
            my ($self, $table, $column, $column_info) = @_;
992
            if (my $model = $self->models->{$table}) {
993
                push @{$model->columns}, $column;
994
            }
995
        }
996
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
997
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
998
}
999

            
update pod
Yuki Kimoto authored on 2011-08-10
1000
sub show_datatype {
1001
    my ($self, $table) = @_;
1002
    croak "Table name must be specified" unless defined $table;
1003
    print "$table\n";
1004
    
1005
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1006
    my $sth = $result->sth;
1007

            
1008
    my $columns = $sth->{NAME};
1009
    my $data_types = $sth->{TYPE};
1010
    
1011
    for (my $i = 0; $i < @$columns; $i++) {
1012
        my $column = $columns->[$i];
1013
        my $data_type = $data_types->[$i];
1014
        print "$column: $data_type\n";
1015
    }
1016
}
1017

            
1018
sub show_typename {
1019
    my ($self, $t) = @_;
1020
    croak "Table name must be specified" unless defined $t;
1021
    print "$t\n";
1022
    
1023
    $self->each_column(sub {
1024
        my ($self, $table, $column, $infos) = @_;
1025
        return unless $table eq $t;
1026
        my $typename = $infos->{TYPE_NAME};
1027
        print "$column: $typename\n";
1028
    });
1029
    
1030
    return $self;
1031
}
1032

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1033
sub show_tables {
1034
    my $self = shift;
1035
    
1036
    my %tables;
1037
    $self->each_table(sub { $tables{$_[1]}++ });
1038
    print join("\n", sort keys %tables) . "\n";
1039
    return $self;
1040
}
1041

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1042
sub type_rule {
1043
    my $self = shift;
1044
    
1045
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1046
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1047
        
1048
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1049
        foreach my $i (1 .. 2) {
1050
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1051
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1052
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1053
            $self->{type_rule} = $type_rule;
1054
            $self->{"_$into"} = {};
1055
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1056
                croak qq{type name of $into section must be lower case}
1057
                  if $type_name =~ /[A-Z]/;
1058
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1059
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1060
            $self->each_column(sub {
1061
                my ($dbi, $table, $column, $column_info) = @_;
1062
                
1063
                my $type_name = lc $column_info->{TYPE_NAME};
1064
                if ($type_rule->{$into} &&
1065
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1066
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1067
                    return unless exists $type_rule->{$into}->{$type_name};
1068
                    if  (defined $filter && ref $filter ne 'CODE') 
1069
                    {
1070
                        my $fname = $filter;
1071
                        croak qq{Filter "$fname" is not registered" } . _subname
1072
                          unless exists $self->filters->{$fname};
1073
                        
1074
                        $filter = $self->filters->{$fname};
1075
                    }
1076

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1077
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1078
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1079
                }
1080
            });
1081
        }
1082

            
1083
        # From
1084
        foreach my $i (1 .. 2) {
1085
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1086
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1087
                croak qq{data type of from$i section must be lower case or number}
1088
                  if $data_type =~ /[A-Z]/;
1089
                my $fname = $type_rule->{"from$i"}{$data_type};
1090
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1091
                    croak qq{Filter "$fname" is not registered" } . _subname
1092
                      unless exists $self->filters->{$fname};
1093
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1094
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1095
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1096
            }
1097
        }
1098
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1099
        return $self;
1100
    }
1101
    
1102
    return $self->{type_rule} || {};
1103
}
1104

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1108
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1109
    my $param;
1110
    $param = shift if @_ % 2;
1111
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1112
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1113
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1114
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1115
    my $p = delete $args{param} || {};
1116
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1117
    my $where = delete $args{where} || {};
1118
    my $where_param = delete $args{where_param} || {};
1119
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1120
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1121
    my $id = delete $args{id};
1122
    my $primary_key = delete $args{primary_key};
1123
    croak "update method primary_key option " .
1124
          "must be specified when id is specified " . _subname
1125
      if defined $id && !defined $primary_key;
1126
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1127
    my $prefix = delete $args{prefix};
updated pod
Yuki Kimoto authored on 2011-09-02
1128
    my $wrap = delete $args{wrap};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1129
    my $timestamp = $args{timestamp};
1130
    
1131
    # Timestamp
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1132
    if ($timestamp && (my $update_timestamp = $self->update_timestamp)) {
1133
        my $columns = $update_timestamp->[0];
1134
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1135
        my $value = $update_timestamp->[1];
1136
        $value = $value->() if ref $value eq 'CODE';
1137
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1138
    }
1139

            
cleanup
yuki-kimoto authored on 2010-10-17
1140
    # Update clause
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1141
    my $assign_clause = $self->assign_clause($param, {wrap => $wrap});
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1142

            
1143
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1144
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1145
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1146
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1147
        $where_clause = "where " . $where->[0];
1148
        $where_param = $where->[1];
1149
    }
1150
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1151
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1152
        $where_param = keys %$where_param
1153
                     ? $self->merge_param($where_param, $where->param)
1154
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1155
        
1156
        # String where
1157
        $where_clause = $where->to_string;
1158
    }
1159
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1160
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1161
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1162
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1163
    # Merge param
1164
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1165
    
cleanup
Yuki Kimoto authored on 2011-04-02
1166
    # Update statement
micro optimization
Yuki Kimoto authored on 2011-09-30
1167
    my $sql;
1168
    $sql .= "update ";
1169
    $sql .= "$prefix " if defined $prefix;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1170
    $sql .= $self->_q($table) . " set $assign_clause $where_clause ";
micro optimization
Yuki Kimoto authored on 2011-09-30
1171
    $sql .= $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
1172
    
cleanup
yuki-kimoto authored on 2010-10-17
1173
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1174
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1175
}
1176

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1179
sub update_timestamp {
1180
    my $self = shift;
1181
    
1182
    if (@_) {
1183
        $self->{update_timestamp} = [@_];
1184
        
1185
        return $self;
1186
    }
1187
    return $self->{update_timestamp};
1188
}
1189

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1192
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1193
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1194
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1195
    
updated pod
Yuki Kimoto authored on 2011-06-21
1196
    # Cache
1197
    my $cache = $self->cache;
1198
    
1199
    # Query
1200
    my $query;
1201
    
1202
    # Get cached query
1203
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1204
        
updated pod
Yuki Kimoto authored on 2011-06-21
1205
        # Get query
1206
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1207
        
updated pod
Yuki Kimoto authored on 2011-06-21
1208
        # Create query
1209
        if ($q) {
1210
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1211
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1212
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1213
    }
1214
    
1215
    # Create query
1216
    unless ($query) {
1217

            
1218
        # Create query
1219
        my $builder = $self->query_builder;
1220
        $query = $builder->build_query($source);
1221

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

            
1228
        # Save query to cache
1229
        $self->cache_method->(
1230
            $self, $source,
1231
            {
1232
                sql     => $query->sql, 
1233
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1234
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1235
            }
1236
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1237
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1238

            
1239
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1240
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1241
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1242
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1243
        $query->sql($sql);
1244
    }
1245
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1246
    # Save sql
1247
    $self->last_sql($query->sql);
1248
    
updated pod
Yuki Kimoto authored on 2011-06-21
1249
    # Prepare statement handle
1250
    my $sth;
1251
    eval { $sth = $self->dbh->prepare($query->{sql})};
1252
    
1253
    if ($@) {
1254
        $self->_croak($@, qq{. Following SQL is executed.\n}
1255
                        . qq{$query->{sql}\n} . _subname);
1256
    }
1257
    
1258
    # Set statement handle
1259
    $query->sth($sth);
1260
    
1261
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1262
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1263
    
1264
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1265
}
1266

            
cleanup
Yuki Kimoto authored on 2011-04-02
1267
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1268
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1269
    
cleanup
Yuki Kimoto authored on 2011-04-02
1270
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1271
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1272
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1273
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1274
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1275
        
1276
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1277
        my $value;
1278
        if(ref $params->{$column} eq 'ARRAY') {
1279
            my $i = $count->{$column} || 0;
1280
            $i += $not_exists->{$column} || 0;
1281
            my $found;
1282
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1283
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1284
                    $not_exists->{$column}++;
1285
                }
1286
                else  {
1287
                    $value = $params->{$column}->[$k];
1288
                    $found = 1;
1289
                    last
1290
                }
1291
            }
1292
            next unless $found;
1293
        }
1294
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1295
        
cleanup
Yuki Kimoto authored on 2011-01-12
1296
        # Filter
1297
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1298
        $value = $f->($value) if $f;
1299
        
1300
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1301
        foreach my $i (1 .. 2) {
1302
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1303
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1304
            $value = $tf->($value) if $tf;
1305
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1306
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1307
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1308
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1309
        
1310
        # Count up 
1311
        $count->{$column}++;
1312
    }
1313
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1314
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1315
}
1316

            
cleanup
Yuki Kimoto authored on 2011-06-08
1317
sub _create_param_from_id {
1318
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1319
    
cleanup
Yuki Kimoto authored on 2011-06-08
1320
    # Create parameter
1321
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1322
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1323
        $id = [$id] unless ref $id;
1324
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1325
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1326
          unless !ref $id || ref $id eq 'ARRAY';
1327
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1328
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1329
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1330
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1331
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1332
        }
1333
    }
1334
    
cleanup
Yuki Kimoto authored on 2011-06-08
1335
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1336
}
1337

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1338
sub _connect {
1339
    my $self = shift;
1340
    
1341
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1342
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1343
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1344
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1345
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1346
    croak qq{"dsn" must be specified } . _subname
1347
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1348
    my $user        = $self->user;
1349
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1350
    my $option = $self->_option;
1351
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1352
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1353
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1354
    my $dbh;
1355
    eval {
1356
        $dbh = DBI->connect(
1357
            $dsn,
1358
            $user,
1359
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1360
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1361
        );
1362
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1363
    
1364
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1365
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1366
    
1367
    return $dbh;
1368
}
1369

            
cleanup
yuki-kimoto authored on 2010-10-17
1370
sub _croak {
1371
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1372
    
1373
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1374
    $append ||= "";
1375
    
1376
    # Verbose
1377
    if ($Carp::Verbose) { croak $error }
1378
    
1379
    # Not verbose
1380
    else {
1381
        
1382
        # Remove line and module infromation
1383
        my $at_pos = rindex($error, ' at ');
1384
        $error = substr($error, 0, $at_pos);
1385
        $error =~ s/\s+$//;
1386
        croak "$error$append";
1387
    }
1388
}
1389

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1392
sub _need_tables {
1393
    my ($self, $tree, $need_tables, $tables) = @_;
1394
    
cleanup
Yuki Kimoto authored on 2011-04-02
1395
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1396
    foreach my $table (@$tables) {
1397
        if ($tree->{$table}) {
1398
            $need_tables->{$table} = 1;
1399
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1400
        }
1401
    }
1402
}
1403

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1404
sub _option {
1405
    my $self = shift;
1406
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1407
    warn "dbi_options is DEPRECATED! use option instead\n"
1408
      if keys %{$self->dbi_options};
1409
    warn "dbi_option is DEPRECATED! use option instead\n"
1410
      if keys %{$self->dbi_option};
1411
    return $option;
1412
}
1413

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1414
sub _push_join {
1415
    my ($self, $sql, $join, $join_tables) = @_;
1416
    
cleanup
Yuki Kimoto authored on 2011-04-02
1417
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1418
    return unless @$join;
1419
    
cleanup
Yuki Kimoto authored on 2011-04-02
1420
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1421
    my $tree = {};
1422
    for (my $i = 0; $i < @$join; $i++) {
1423
        
cleanup
Yuki Kimoto authored on 2011-07-28
1424
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1425
        my $join_clause;;
1426
        my $option;
1427
        if (ref $join->[$i] eq 'HASH') {
1428
            $join_clause = $join->[$i]->{clause};
1429
            $option = {table => $join->[$i]->{table}};
1430
        }
1431
        else {
1432
            $join_clause = $join->[$i];
1433
            $option = {};
1434
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1435

            
1436
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1437
        my $table1;
1438
        my $table2;
1439
        if (my $table = $option->{table}) {
1440
            $table1 = $table->[0];
1441
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1442
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1443
        else {
1444
            my $q = $self->_quote;
1445
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1446
            $j_clause =~ s/'.+?'//g;
1447
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1448
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1449
            
1450
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1451
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1452
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1453
            for my $clause (@j_clauses) {
1454
                if ($clause =~ $join_re) {
1455
                    $table1 = $1;
1456
                    $table2 = $2;
1457
                    last;
1458
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1459
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1460
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1461
        croak qq{join clause must have two table name after "on" keyword. } .
1462
              qq{"$join_clause" is passed }  . _subname
1463
          unless defined $table1 && defined $table2;
1464
        croak qq{right side table of "$join_clause" must be unique }
1465
            . _subname
1466
          if exists $tree->{$table2};
1467
        croak qq{Same table "$table1" is specified} . _subname
1468
          if $table1 eq $table2;
1469
        $tree->{$table2}
1470
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1471
    }
1472
    
cleanup
Yuki Kimoto authored on 2011-04-02
1473
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1474
    my $need_tables = {};
1475
    $self->_need_tables($tree, $need_tables, $join_tables);
1476
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1477
    
1478
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1479
    foreach my $need_table (@need_tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1480
        $$sql .= $tree->{$need_table}{join} . ' ';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1481
    }
1482
}
cleanup
Yuki Kimoto authored on 2011-03-08
1483

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1484
sub _quote {
1485
    my $self = shift;
1486
    
1487
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1488
         : defined $self->quote ? $self->quote
1489
         : '';
1490
}
1491

            
cleanup
Yuki Kimoto authored on 2011-07-29
1492
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1493
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1494
    
1495
    my $quote = $self->_quote;
1496
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1497
    my $p;
1498
    if (defined $quote && length $quote > 1) {
1499
        $p = substr($quote, 1, 1);
1500
    }
1501
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1502
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1503
    if ($quotemeta) {
1504
        $q = quotemeta($q);
1505
        $p = quotemeta($p);
1506
    }
1507
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1508
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1509
}
1510

            
cleanup
Yuki Kimoto authored on 2011-04-02
1511
sub _remove_duplicate_table {
1512
    my ($self, $tables, $main_table) = @_;
1513
    
1514
    # Remove duplicate table
1515
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1516
    delete $tables{$main_table} if $main_table;
1517
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1518
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1519
    if (my $q = $self->_quote) {
1520
        $q = quotemeta($q);
1521
        $_ =~ s/[$q]//g for @$new_tables;
1522
    }
1523

            
1524
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1525
}
1526

            
cleanup
Yuki Kimoto authored on 2011-04-02
1527
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1528
    my ($self, $source) = @_;
1529
    
cleanup
Yuki Kimoto authored on 2011-04-02
1530
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1531
    my $tables = [];
1532
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1533
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1534
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1535
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1536
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1537
    while ($source =~ /$table_re/g) {
1538
        push @$tables, $1;
1539
    }
1540
    
1541
    return $tables;
1542
}
1543

            
cleanup
Yuki Kimoto authored on 2011-04-02
1544
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1545
    my ($self, $where) = @_;
1546
    
cleanup
Yuki Kimoto authored on 2011-04-02
1547
    my $obj;
1548
    
1549
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1550
    if (ref $where eq 'HASH') {
1551
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1552
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1553
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1554
            my $table;
1555
            my $c;
1556
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1557
                $table = $1;
1558
                $c = $2;
1559
            }
1560
            
1561
            my $table_quote;
1562
            $table_quote = $self->_q($table) if defined $table;
1563
            my $column_quote = $self->_q($c);
1564
            $column_quote = $table_quote . '.' . $column_quote
1565
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1566
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1567
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1568
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1569
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1570
    
1571
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1572
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1573
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1574
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1575
    
updated pod
Yuki Kimoto authored on 2011-06-21
1576
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1577
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1578
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1579
            clause => $where->[0],
1580
            param  => $where->[1]
1581
        );
1582
    }
1583
    
cleanup
Yuki Kimoto authored on 2011-04-02
1584
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1585
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1586
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1587
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1588
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1589
    
cleanup
Yuki Kimoto authored on 2011-04-02
1590
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1591
}
1592

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

            
1596
    # Initialize filters
1597
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1598
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1599
    $self->{filter}{out} ||= {};
1600
    $self->{filter}{in} ||= {};
1601
    $self->{filter}{end} ||= {};
1602
    
1603
    # Usage
1604
    my $usage = "Usage: \$dbi->apply_filter(" .
1605
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1606
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1607
    
1608
    # Apply filter
1609
    for (my $i = 0; $i < @cinfos; $i += 2) {
1610
        
1611
        # Column
1612
        my $column = $cinfos[$i];
1613
        if (ref $column eq 'ARRAY') {
1614
            foreach my $c (@$column) {
1615
                push @cinfos, $c, $cinfos[$i + 1];
1616
            }
1617
            next;
1618
        }
1619
        
1620
        # Filter infomation
1621
        my $finfo = $cinfos[$i + 1] || {};
1622
        croak "$usage (table: $table) " . _subname
1623
          unless  ref $finfo eq 'HASH';
1624
        foreach my $ftype (keys %$finfo) {
1625
            croak "$usage (table: $table) " . _subname
1626
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1627
        }
1628
        
1629
        # Set filters
1630
        foreach my $way (qw/in out end/) {
1631
        
1632
            # Filter
1633
            my $filter = $finfo->{$way};
1634
            
1635
            # Filter state
1636
            my $state = !exists $finfo->{$way} ? 'not_exists'
1637
                      : !defined $filter        ? 'not_defined'
1638
                      : ref $filter eq 'CODE'   ? 'code'
1639
                      : 'name';
1640
            
1641
            # Filter is not exists
1642
            next if $state eq 'not_exists';
1643
            
1644
            # Check filter name
1645
            croak qq{Filter "$filter" is not registered } . _subname
1646
              if  $state eq 'name'
1647
               && ! exists $self->filters->{$filter};
1648
            
1649
            # Set filter
1650
            my $f = $state eq 'not_defined' ? undef
1651
                  : $state eq 'code'        ? $filter
1652
                  : $self->filters->{$filter};
1653
            $self->{filter}{$way}{$table}{$column} = $f;
1654
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1655
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1656
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1657
        }
1658
    }
1659
    
1660
    return $self;
1661
}
1662

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1663
# DEPRECATED!
1664
has 'data_source';
1665
has dbi_options => sub { {} };
1666
has filter_check  => 1;
1667
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1668
has dbi_option => sub { {} };
1669
has default_dbi_option => sub {
1670
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1671
    return shift->default_option;
1672
};
1673

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1674

            
1675
# DEPRECATED!
1676
sub assign_param {
1677
    my $self = shift;
1678
    warn "assing_param is DEPRECATED! use assign_clause instead";
1679
    return $self->assign_clause(@_);
1680
}
1681

            
1682
# DEPRECATED
1683
sub update_param {
1684
    my ($self, $param, $opts) = @_;
1685
    
1686
    warn "update_param is DEPRECATED! use assing_clause instead.";
1687
    
1688
    # Create update parameter tag
1689
    my $tag = $self->assign_clause($param, $opts);
1690
    $tag = "set $tag" unless $opts->{no_set};
1691

            
1692
    return $tag;
1693
}
1694

            
updated pod
Yuki Kimoto authored on 2011-06-21
1695
# DEPRECATED!
1696
sub create_query {
1697
    warn "create_query is DEPRECATED! use query option of each method";
1698
    shift->_create_query(@_);
1699
}
1700

            
cleanup
Yuki Kimoto authored on 2011-06-13
1701
# DEPRECATED!
1702
sub apply_filter {
1703
    my $self = shift;
1704
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1705
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1706
    return $self->_apply_filter(@_);
1707
}
1708

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1716
    # Arguments
1717
    my $primary_keys = delete $args{primary_key};
1718
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1719
    my $where = delete $args{where};
1720
    my $param = delete $args{param};
1721
    
1722
    # Check arguments
1723
    foreach my $name (keys %args) {
1724
        croak qq{"$name" is wrong option } . _subname
1725
          unless $SELECT_AT_ARGS{$name};
1726
    }
1727
    
1728
    # Table
1729
    croak qq{"table" option must be specified } . _subname
1730
      unless $args{table};
1731
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1732
    
1733
    # Create where parameter
1734
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1735
    
1736
    return $self->select(where => $where_param, %args);
1737
}
1738

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

            
1744
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1745
    
1746
    # Arguments
1747
    my $primary_keys = delete $args{primary_key};
1748
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1749
    my $where = delete $args{where};
1750
    
1751
    # Check arguments
1752
    foreach my $name (keys %args) {
1753
        croak qq{"$name" is wrong option } . _subname
1754
          unless $DELETE_AT_ARGS{$name};
1755
    }
1756
    
1757
    # Create where parameter
1758
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1759
    
1760
    return $self->delete(where => $where_param, %args);
1761
}
1762

            
cleanup
Yuki Kimoto authored on 2011-06-08
1763
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1764
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1765
sub update_at {
1766
    my $self = shift;
1767

            
1768
    warn "update_at is DEPRECATED! use update and id option instead";
1769
    
1770
    # Arguments
1771
    my $param;
1772
    $param = shift if @_ % 2;
1773
    my %args = @_;
1774
    my $primary_keys = delete $args{primary_key};
1775
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1776
    my $where = delete $args{where};
1777
    my $p = delete $args{param} || {};
1778
    $param  ||= $p;
1779
    
1780
    # Check arguments
1781
    foreach my $name (keys %args) {
1782
        croak qq{"$name" is wrong option } . _subname
1783
          unless $UPDATE_AT_ARGS{$name};
1784
    }
1785
    
1786
    # Create where parameter
1787
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1788
    
1789
    return $self->update(where => $where_param, param => $param, %args);
1790
}
1791

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1792
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1793
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1794
sub insert_at {
1795
    my $self = shift;
1796
    
1797
    warn "insert_at is DEPRECATED! use insert and id option instead";
1798
    
1799
    # Arguments
1800
    my $param;
1801
    $param = shift if @_ % 2;
1802
    my %args = @_;
1803
    my $primary_key = delete $args{primary_key};
1804
    $primary_key = [$primary_key] unless ref $primary_key;
1805
    my $where = delete $args{where};
1806
    my $p = delete $args{param} || {};
1807
    $param  ||= $p;
1808
    
1809
    # Check arguments
1810
    foreach my $name (keys %args) {
1811
        croak qq{"$name" is wrong option } . _subname
1812
          unless $INSERT_AT_ARGS{$name};
1813
    }
1814
    
1815
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1816
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1817
    $param = $self->merge_param($where_param, $param);
1818
    
1819
    return $self->insert(param => $param, %args);
1820
}
1821

            
added warnings
Yuki Kimoto authored on 2011-06-07
1822
# DEPRECATED!
1823
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1824
    my $self = shift;
1825
    
added warnings
Yuki Kimoto authored on 2011-06-07
1826
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
    
1828
    # Merge tag
1829
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1830
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1831
    
1832
    return $self;
1833
}
1834

            
1835
# DEPRECATED!
1836
sub register_tag_processor {
1837
    my $self = shift;
1838
    warn "register_tag_processor is DEPRECATED!";
1839
    # Merge tag
1840
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1841
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1842
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1843
}
1844

            
cleanup
Yuki Kimoto authored on 2011-01-25
1845
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1846
sub default_bind_filter {
1847
    my $self = shift;
1848
    
cleanup
Yuki Kimoto authored on 2011-06-13
1849
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1850
    
cleanup
Yuki Kimoto authored on 2011-01-12
1851
    if (@_) {
1852
        my $fname = $_[0];
1853
        
1854
        if (@_ && !$fname) {
1855
            $self->{default_out_filter} = undef;
1856
        }
1857
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1858
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1859
              unless exists $self->filters->{$fname};
1860
        
1861
            $self->{default_out_filter} = $self->filters->{$fname};
1862
        }
1863
        return $self;
1864
    }
1865
    
1866
    return $self->{default_out_filter};
1867
}
1868

            
cleanup
Yuki Kimoto authored on 2011-01-25
1869
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1870
sub default_fetch_filter {
1871
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1872

            
cleanup
Yuki Kimoto authored on 2011-06-13
1873
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1874
    
1875
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1876
        my $fname = $_[0];
1877

            
cleanup
Yuki Kimoto authored on 2011-01-12
1878
        if (@_ && !$fname) {
1879
            $self->{default_in_filter} = undef;
1880
        }
1881
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1882
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1883
              unless exists $self->filters->{$fname};
1884
        
1885
            $self->{default_in_filter} = $self->filters->{$fname};
1886
        }
1887
        
1888
        return $self;
1889
    }
1890
    
many changed
Yuki Kimoto authored on 2011-01-23
1891
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1892
}
1893

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1894
# DEPRECATED!
1895
sub insert_param {
1896
    my $self = shift;
1897
    warn "insert_param is DEPRECATED! use values_clause instead";
1898
    return $self->values_clause(@_);
1899
}
1900

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1901
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1902
sub insert_param_tag {
1903
    warn "insert_param_tag is DEPRECATED! " .
1904
         "use insert_param instead!";
1905
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1906
}
1907

            
1908
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1909
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1910
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1911
         "use update_param instead";
1912
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1913
}
cleanup
Yuki Kimoto authored on 2011-03-08
1914
# DEPRECATED!
1915
sub _push_relation {
1916
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1917
    
1918
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1919
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1920
        foreach my $rcolumn (keys %$relation) {
1921
            my $table1 = (split (/\./, $rcolumn))[0];
1922
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1923
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1924
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1925
        }
1926
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1927
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1928
}
1929

            
1930
# DEPRECATED!
1931
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1932
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1933
    
1934
    if (keys %{$relation || {}}) {
1935
        foreach my $rcolumn (keys %$relation) {
1936
            my $table1 = (split (/\./, $rcolumn))[0];
1937
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1938
            my $table1_exists;
1939
            my $table2_exists;
1940
            foreach my $table (@$tables) {
1941
                $table1_exists = 1 if $table eq $table1;
1942
                $table2_exists = 1 if $table eq $table2;
1943
            }
1944
            unshift @$tables, $table1 unless $table1_exists;
1945
            unshift @$tables, $table2 unless $table2_exists;
1946
        }
1947
    }
1948
}
1949

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1952
=head1 NAME
1953

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
1956
=head1 SYNOPSIS
cleanup
yuki-kimoto authored on 2010-08-05
1957

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1958
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1959
    
1960
    # Connect
1961
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1962
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1963
        user => 'ken',
1964
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1965
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1966
    );
cleanup
yuki-kimoto authored on 2010-08-05
1967

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1968
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1969
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1970
    
1971
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1972
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1973
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1974
    
1975
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1976
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1977

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1982
    # Select, more complex
1983
    my $result = $dbi->select(
1984
        table  => 'book',
1985
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1986
            {book => [qw/title author/]},
1987
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1988
        ],
1989
        where  => {'book.author' => 'Ken'},
1990
        join => ['left outer join company on book.company_id = company.id'],
1991
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1992
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1993
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1994
    # Fetch
1995
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1996
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1997
    }
1998
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1999
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2000
    while (my $row = $result->fetch_hash) {
2001
        
2002
    }
2003
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2004
    # Execute SQL with parameter.
2005
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2006
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2007
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2008
    );
2009
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2010
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2011

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2027
Named place holder support
2028

            
2029
=item *
2030

            
cleanup
Yuki Kimoto authored on 2011-07-29
2031
Model support
2032

            
2033
=item *
2034

            
2035
Connection manager support
2036

            
2037
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2038

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

            
2043
=item *
2044

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2045
Filtering by data type or column name
cleanup
Yuki Kimoto authored on 2011-07-29
2046

            
2047
=item *
2048

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2049
Create C<order by> clause flexibly
cleanup
Yuki Kimoto authored on 2011-07-29
2050

            
2051
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2052

            
fix heading typos
Terrence Brannon authored on 2011-08-17
2053
=head1 DOCUMENTATION
pod fix
Yuki Kimoto authored on 2011-01-21
2054

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2060
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2061
L<DBIx::Custom::Result>,
2062
L<DBIx::Custom::Query>,
2063
L<DBIx::Custom::Where>,
2064
L<DBIx::Custom::Model>,
2065
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2066

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

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

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

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

            
2077
This is L<DBIx::Connector> example. Please pass
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2078
C<default_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2079

            
2080
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2081
        "dbi:mysql:database=$database",
2082
        $user,
2083
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2084
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2085
    );
2086
    
updated pod
Yuki Kimoto authored on 2011-06-21
2087
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2088

            
cleanup
Yuki Kimoto authored on 2011-08-16
2089
If C<connector> is set to 1 when connect method is called,
2090
L<DBIx::Connector> is automatically set to C<connector>
2091

            
2092
    my $dbi = DBIx::Custom->connect(
2093
      dsn => $dsn, user => $user, password => $password, connector => 1);
2094
    
2095
    my $connector = $dbi->connector; # DBIx::Connector
2096

            
2097
Note that L<DBIx::Connector> must be installed.
2098

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2106
=head2 C<option>
added dbi_options attribute
kimoto authored on 2010-12-20
2107

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2108
    my $option = $dbi->option;
2109
    $dbi = $dbi->option($option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2110

            
updated pod
Yuki Kimoto authored on 2011-06-21
2111
L<DBI> option, used when C<connect> method is executed.
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2112
Each value in option override the value of C<default_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2113

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2114
=head2 C<default_option>
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2115

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2116
    my $default_option = $dbi->default_option;
2117
    $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2118

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2122
    {
2123
        RaiseError => 1,
2124
        PrintError => 0,
2125
        AutoCommit => 1,
2126
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2127

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

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

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

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

            
2137
    my $last_sql = $dbi->last_sql;
2138
    $dbi = $dbi->last_sql($last_sql);
2139

            
2140
Get last successed SQL executed by C<execute> method.
2141

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2149
=head2 C<password>
2150

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2171
You can set quote pair.
2172

            
2173
    $dbi->quote('[]');
2174

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2184
    my $safety_character = $dbi->safety_character;
2185
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2186

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2192
    my $separator = $dbi->separator;
2193
    $dbi = $dbi->separator('-');
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2194

            
2195
Separator which join table name and column name.
2196
This have effect to C<column> and C<mycolumn> method,
2197
and C<select> method's column option.
cleanup test
Yuki Kimoto authored on 2011-08-10
2198

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2199
Default to C<.>.
cleanup test
Yuki Kimoto authored on 2011-08-10
2200

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2201
=head2 C<exclude_table>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2202

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2203
    my $exclude_table = $dbi->exclude_table;
2204
    $dbi = $dbi->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2205

            
updated pod
Yuki Kimoto authored on 2011-09-27
2206
Excluded table regex.
2207
C<each_column>, C<each_table>, C<type_rule>,
2208
and C<setup_model> methods ignore matching tables.
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2209

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

            
2212
    my $tag_parse = $dbi->tag_parse(0);
2213
    $dbi = $dbi->tag_parse;
2214

            
2215
Enable DEPRECATED tag parsing functionality, default to 1.
2216
If you want to disable tag parsing functionality, set to 0.
2217

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2225
=head2 C<user_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2226

            
2227
    my $user_column_info = $dbi->user_column_info;
2228
    $dbi = $dbi->user_column_info($user_column_info);
2229

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2230
You can set the date like the following one.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2231

            
2232
    [
2233
        {table => 'book', column => 'title', info => {...}},
2234
        {table => 'author', column => 'name', info => {...}}
2235
    ]
2236

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2237
Usually, you set return value of C<get_column_info>.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2238

            
2239
    my $user_column_info
2240
      = $dbi->get_column_info(exclude_table => qr/^system/);
2241
    $dbi->user_column_info($user_column_info);
2242

            
2243
If C<user_column_info> is set, C<each_column> use C<user_column_info>
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2244
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2245

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2246
=head2 C<user_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2247

            
2248
    my $user_table_info = $dbi->user_table_info;
2249
    $dbi = $dbi->user_table_info($user_table_info);
2250

            
2251
You can set the following data.
2252

            
2253
    [
2254
        {table => 'book', info => {...}},
2255
        {table => 'author', info => {...}}
2256
    ]
2257

            
2258
Usually, you can set return value of C<get_table_info>.
2259

            
2260
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2261
    $dbi->user_table_info($user_table_info);
2262

            
2263
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2264
to find table info.
2265

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2272
=head2 C<available_datatype>
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2273

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2279
=head2 C<available_typename>
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2280

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2286
=head2 C<assign_clause>
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2287

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2288
    my $assign_clause = $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2289

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2290
Create assign clause
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2291

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2294
This is used to create update clause.
2295

            
2296
    "update book set " . $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2297

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

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

            
2302
Create column clause. The follwoing column clause is created.
2303

            
2304
    book.author as "book.author",
2305
    book.title as "book.title"
2306

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2309
    # Separator is hyphen
2310
    $dbi->separator('-');
2311
    
2312
    book.author as "book-author",
2313
    book.title as "book-title"
2314
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2315
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2316

            
update pod
Yuki Kimoto authored on 2011-03-13
2317
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2318
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2319
        user => 'ken',
2320
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2321
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2322
    );
2323

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2330
=head2 C<count>
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2331

            
2332
    my $count = $model->count(table => 'book');
2333

            
2334
Get rows count.
2335

            
2336
Options is same as C<select> method's ones.
2337

            
2338
=head2 C<create_model>
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2339

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2340
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2341
        table => 'book',
2342
        primary_key => 'id',
2343
        join => [
2344
            'inner join company on book.comparny_id = company.id'
2345
        ],
2346
    );
2347

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

            
2351
   $dbi->model('book')->select(...);
2352

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

            
2355
    my $dbh = $dbi->dbh;
2356

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

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

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

            
2364
Execute delete statement.
2365

            
2366
The following opitons are available.
2367

            
2368
=over 4
2369

            
2370
=item C<append>
2371

            
2372
Same as C<select> method's C<append> option.
2373

            
2374
=item C<filter>
2375

            
2376
Same as C<execute> method's C<filter> option.
2377

            
2378
=item C<id>
2379

            
2380
    id => 4
2381
    id => [4, 5]
2382

            
2383
ID corresponding to C<primary_key>.
2384
You can delete rows by C<id> and C<primary_key>.
2385

            
2386
    $dbi->delete(
2387
        parimary_key => ['id1', 'id2'],
2388
        id => [4, 5],
2389
        table => 'book',
2390
    );
2391

            
2392
The above is same as the followin one.
2393

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

            
2396
=item C<prefix>
2397

            
2398
    prefix => 'some'
2399

            
2400
prefix before table name section.
2401

            
2402
    delete some from book
2403

            
2404
=item C<query>
2405

            
2406
Same as C<execute> method's C<query> option.
2407

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2408
=item C<after_build_sql>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2409

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2410
Same as C<execute> method's C<after_build_sql> option.
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2411

            
2412
=item C<table>
2413

            
2414
    table => 'book'
2415

            
2416
Table name.
2417

            
2418
=item C<where>
2419

            
2420
Same as C<select> method's C<where> option.
2421

            
2422
=item C<primary_key>
2423

            
2424
See C<id> option.
2425

            
2426
=item C<bind_type>
2427

            
2428
Same as C<execute> method's C<bind_type> option.
2429

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2430
=item C<type_rule_off>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2431

            
2432
Same as C<execute> method's C<type_rule_off> option.
2433

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2434
=item C<type_rule1_off>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2435

            
2436
    type_rule1_off => 1
2437

            
2438
Same as C<execute> method's C<type_rule1_off> option.
2439

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2440
=item C<type_rule2_off>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2441

            
2442
    type_rule2_off => 1
2443

            
2444
Same as C<execute> method's C<type_rule2_off> option.
2445

            
2446
=back
2447

            
2448
=head2 C<delete_all>
2449

            
2450
    $dbi->delete_all(table => $table);
2451

            
2452
Execute delete statement for all rows.
2453
Options is same as C<delete>.
2454

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

            
2457
    $dbi->each_column(
2458
        sub {
2459
            my ($dbi, $table, $column, $column_info) = @_;
2460
            
2461
            my $type = $column_info->{TYPE_NAME};
2462
            
2463
            if ($type eq 'DATE') {
2464
                # ...
2465
            }
2466
        }
2467
    );
2468

            
2469
Iterate all column informations of all table from database.
2470
Argument is callback when one column is found.
2471
Callback receive four arguments, dbi object, table name,
2472
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2473

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

            
2476
    $dbi->each_table(
2477
        sub {
2478
            my ($dbi, $table, $table_info) = @_;
2479
            
2480
            my $table_name = $table_info->{TABLE_NAME};
2481
        }
2482
    );
2483

            
2484
Iterate all table informationsfrom database.
2485
Argument is callback when one table is found.
2486
Callback receive three arguments, dbi object, table name,
2487
table information.
2488

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

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

            
2496
    my $result = $dbi->execute(
2497
      "select * from book where title = :book.title and author like :book.author",
2498
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2499
    );
2500

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2507
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2508
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2509
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2510
    select * from book where title = :title and author like :author
2511
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2512
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2513
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2514

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2518
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2519
    select * from book where :title{=} and :author{like}
2520
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2521
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2522
    select * from where title = ? and author like ?;
2523

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

            
2528
    select * from where title = "aa\\:bb";
2529

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

            
2532
=over 4
2533

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

            
2536
Specify database bind data type.
2537

            
2538
    bind_type => [image => DBI::SQL_BLOB]
2539
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2540

            
2541
This is used to bind parameter by C<bind_param> of statment handle.
2542

            
2543
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2544

            
update pod
Yuki Kimoto authored on 2011-03-13
2545
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2546
    
2547
    filter => {
2548
        title  => sub { uc $_[0] }
2549
        author => sub { uc $_[0] }
2550
    }
update pod
Yuki Kimoto authored on 2011-03-13
2551

            
updated pod
Yuki Kimoto authored on 2011-06-09
2552
    # Filter name
2553
    filter => {
2554
        title  => 'upper_case',
2555
        author => 'upper_case'
2556
    }
2557
        
2558
    # At once
2559
    filter => [
2560
        [qw/title author/]  => sub { uc $_[0] }
2561
    ]
2562

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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2568
=item C<id>
2569

            
2570
    id => 4
2571
    id => [4, 5]
2572

            
2573
ID corresponding to C<primary_key>.
2574
You can delete rows by C<id> and C<primary_key>.
2575

            
2576
    $dbi->execute(
2577
        "select * from book where id1 = :id1 and id2 = :id2",
2578
        {},
2579
        parimary_key => ['id1', 'id2'],
2580
        id => [4, 5],
2581
    );
2582

            
2583
The above is same as the followin one.
2584

            
2585
    $dbi->execute(
2586
        "select * from book where id1 = :id1 and id2 = :id2",
2587
        {id1 => 4, id2 => 5}
2588
    );
2589

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

            
2592
    query => 1
2593

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

            
2597
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2598
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2599
    my $columns = $query->columns;
2600
    
2601
If you want to execute SQL fast, you can do the following way.
2602

            
2603
    my $query;
2604
    foreach my $row (@$rows) {
2605
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2606
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2607
    }
2608

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

            
2612
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
2613
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2614
    
2615
    my $query;
2616
    my $sth;
2617
    foreach my $row (@$rows) {
2618
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2619
      $sth ||= $query->sth;
2620
      $sth->execute(map { $row->{$_} } sort keys %$row);
2621
    }
2622

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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2627
=item C<primary_key>
2628

            
2629
See C<id> option.
2630

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2631
=item C<after_build_sql> 
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2632

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2633
You can filter sql after the sql is build.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2634

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2635
    after_build_sql => $code_ref
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2636

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2637
The following one is one example.
2638

            
2639
    $dbi->select(
2640
        table => 'book',
2641
        column => 'distinct(name)',
2642
        after_build_sql => sub {
2643
            "select count(*) from ($_[0]) as t1"
2644
        }
2645
    );
2646

            
2647
The following SQL is executed.
2648

            
2649
    select count(*) from (select distinct(name) from book) as t1;
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2650

            
updated pod
Yuki Kimoto authored on 2011-06-09
2651
=item C<table>
2652
    
2653
    table => 'author'
2654

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2662
    # Same
2663
    $dbi->execute(
2664
      "select * from book where title = :book.title and author = :book.author",
2665
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2666

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2667
=item C<table_alias>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2668

            
2669
    table_alias => {user => 'hiker'}
2670

            
2671
Table alias. Key is real table name, value is alias table name.
2672
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2673
on alias table name.
2674

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2675
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2676

            
2677
    type_rule_off => 1
2678

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2681
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2682

            
2683
    type_rule1_off => 1
2684

            
2685
Turn C<into1> type rule off.
2686

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2687
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2688

            
2689
    type_rule2_off => 1
2690

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2695
=head2 C<get_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2696

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2697
    my $tables = $dbi->get_column_info(exclude_table => qr/^system_/);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2698

            
2699
get column infomation except for one which match C<exclude_table> pattern.
2700

            
2701
    [
2702
        {table => 'book', column => 'title', info => {...}},
2703
        {table => 'author', column => 'name' info => {...}}
2704
    ]
2705

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2706
=head2 C<get_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2707

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2708
    my $tables = $dbi->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2709

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

            
2712
    [
2713
        {table => 'book', info => {...}},
2714
        {table => 'author', info => {...}}
2715
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2716

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2719
=head2 C<insert>
2720

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

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

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

            
2729
    {date => \"NOW()"}
2730

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

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

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

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

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

            
2741
Same as C<execute> method's C<bind_type> option.
2742

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

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

            
2747
=item C<id>
2748

            
updated document
Yuki Kimoto authored on 2011-06-09
2749
    id => 4
2750
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2751

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2755
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2756
        {title => 'Perl', author => 'Ken'}
2757
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2758
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2759
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2760
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2761

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

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

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

            
2771
    prefix => 'or replace'
2772

            
2773
prefix before table name section
2774

            
2775
    insert or replace into book
2776

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

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

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

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

            
2786
Same as C<execute> method's C<query> option.
2787

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2788
=item C<after_build_sql>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2789

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2790
Same as C<execute> method's C<after_build_sql> option.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2791

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

            
2794
    table => 'book'
2795

            
2796
Table name.
2797

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2798
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2799

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2802
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
2803

            
2804
    timestamp => 1
2805

            
2806
If this value is set to 1,
2807
automatically created timestamp column is set based on
2808
C<timestamp> attribute's C<insert> value.
2809

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2810
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2811

            
2812
    type_rule1_off => 1
2813

            
2814
Same as C<execute> method's C<type_rule1_off> option.
2815

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2816
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2817

            
2818
    type_rule2_off => 1
2819

            
2820
Same as C<execute> method's C<type_rule2_off> option.
2821

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2822
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
2823

            
2824
    wrap => {price => sub { "max($_[0])" }}
2825

            
2826
placeholder wrapped string.
2827

            
2828
If the following statement
2829

            
2830
    $dbi->insert({price => 100}, table => 'book',
2831
      {price => sub { "$_[0] + 5" }});
2832

            
2833
is executed, the following SQL is executed.
2834

            
2835
    insert into book price values ( ? + 5 );
2836

            
update pod
Yuki Kimoto authored on 2011-03-13
2837
=back
2838

            
2839
=over 4
2840

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2841
=head2 C<values_clause>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2842

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2843
    my $values_clause = $dbi->values_clause({title => 'a', age => 2});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2844

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2845
Create values clause.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2846

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2856
    lib / MyModel.pm
2857
        / MyModel / book.pm
2858
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2859

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

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

            
2864
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2865
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2866
    
2867
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2868

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2873
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2874
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2875
    
2876
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2877

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2880
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2881
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2882
    
2883
    1;
2884
    
updated pod
Yuki Kimoto authored on 2011-06-21
2885
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2886

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2894
=head2 C<insert_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2895

            
2896
    $dbi->insert_timestamp(
2897
      [qw/created_at updated_at/] => sub { localtime });
2898

            
2899
Parameter for timestamp columns when C<insert> method is executed
2900
with C<timestamp> option.
2901

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2902
If multiple column are specified, same value is used.
2903

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2904
=head2 C<like_value EXPERIMENTAL>
2905

            
2906
    my $like_value = $dbi->like_value
2907

            
2908
Constant code reference for the like value.
2909

            
2910
    sub { "%$_[0]%" }
2911

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2912
=head2 C<mapper>
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2913

            
2914
    my $mapper = $dbi->mapper(param => $param);
2915

            
2916
Create a new L<DBIx::Custom::Mapper> object.
2917

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

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

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

            
2924
    {key1 => [1, 1], key2 => 2}
2925

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

            
2928
    $dbi->method(
2929
        update_or_insert => sub {
2930
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2931
            
2932
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2933
        },
2934
        find_or_create   => sub {
2935
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2936
            
2937
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2938
        }
2939
    );
2940

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

            
2943
    $dbi->update_or_insert;
2944
    $dbi->find_or_create;
2945

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

            
2948
    my $model = $dbi->model('book');
2949

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2954
    my $column = $dbi->mycolumn(book => ['author', 'title']);
cleanup
Yuki Kimoto authored on 2011-03-21
2955

            
2956
Create column clause for myself. The follwoing column clause is created.
2957

            
2958
    book.author as author,
2959
    book.title as title
2960

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2963
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2964
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2965
        user => 'ken',
2966
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2967
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2968
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2969

            
2970
Create a new L<DBIx::Custom> object.
2971

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

            
2974
    my $not_exists = $dbi->not_exists;
2975

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2979
=head2 C<order>
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2980

            
2981
    my $order = $dbi->order;
2982

            
2983
Create a new L<DBIx::Custom::Order> object.
2984

            
cleanup
yuki-kimoto authored on 2010-10-17
2985
=head2 C<register_filter>
2986

            
update pod
Yuki Kimoto authored on 2011-03-13
2987
    $dbi->register_filter(
2988
        # Time::Piece object to database DATE format
2989
        tp_to_date => sub {
2990
            my $tp = shift;
2991
            return $tp->strftime('%Y-%m-%d');
2992
        },
2993
        # database DATE format to Time::Piece object
2994
        date_to_tp => sub {
2995
           my $date = shift;
2996
           return Time::Piece->strptime($date, '%Y-%m-%d');
2997
        }
2998
    );
cleanup
yuki-kimoto authored on 2010-10-17
2999
    
update pod
Yuki Kimoto authored on 2011-03-13
3000
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3001

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3002
=head2 C<type_rule>
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3003

            
3004
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3005
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
3006
            date => sub { ... },
3007
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3008
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3009
        into2 => {
3010
            date => sub { ... },
3011
            datetime => sub { ... }
3012
        },
3013
        from1 => {
3014
            # DATE
3015
            9 => sub { ... },
3016
            # DATETIME or TIMESTAMP
3017
            11 => sub { ... },
3018
        }
3019
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3020
            # DATE
3021
            9 => sub { ... },
3022
            # DATETIME or TIMESTAMP
3023
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3024
        }
3025
    );
3026

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3042
=over 4
3043

            
3044
=item 1. column name
3045

            
3046
    issue_date
3047
    issue_datetime
3048

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

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

            
3053
    book.issue_date
3054
    book.issue_datetime
3055

            
3056
=back
3057

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

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

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

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

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

            
3070
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3071
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3072
            [qw/DATE DATETIME/] => sub { ... },
3073
        ],
3074
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3075

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3078
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3079
        table  => 'book',
3080
        column => ['author', 'title'],
3081
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3082
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3083
    
updated document
Yuki Kimoto authored on 2011-06-09
3084
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3085

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

            
3088
=over 4
3089

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

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

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

            
3096
=item C<bind_type>
3097

            
3098
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3099
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3100
=item C<column>
3101
    
updated document
Yuki Kimoto authored on 2011-06-09
3102
    column => 'author'
3103
    column => ['author', 'title']
3104

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3113
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3114
        {book => [qw/author title/]},
3115
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3116
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3117

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

            
3120
    book.author as "book.author",
3121
    book.title as "book.title",
3122
    person.name as "person.name",
3123
    person.age as "person.age"
3124

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

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

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

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

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

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

            
3140
=item C<id>
3141

            
3142
    id => 4
3143
    id => [4, 5]
3144

            
3145
ID corresponding to C<primary_key>.
3146
You can select rows by C<id> and C<primary_key>.
3147

            
3148
    $dbi->select(
3149
        parimary_key => ['id1', 'id2'],
3150
        id => [4, 5],
3151
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3152
    );
3153

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3156
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3157
        where => {id1 => 4, id2 => 5},
3158
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3159
    );
3160
    
updated document
Yuki Kimoto authored on 2011-06-09
3161
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3162

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

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

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

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

            
3175
    prefix => 'SQL_CALC_FOUND_ROWS'
3176

            
3177
Prefix of column cluase
3178

            
3179
    select SQL_CALC_FOUND_ROWS title, author from book;
3180

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

            
3183
    join => [
3184
        'left outer join company on book.company_id = company_id',
3185
        'left outer join location on company.location_id = location.id'
3186
    ]
3187
        
3188
Join clause. If column cluase or where clause contain table name like "company.name",
3189
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3190

            
3191
    $dbi->select(
3192
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3193
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3194
        where => {'company.name' => 'Orange'},
3195
        join => [
3196
            'left outer join company on book.company_id = company.id',
3197
            'left outer join location on company.location_id = location.id'
3198
        ]
3199
    );
3200

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3204
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3205
    from book
3206
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3207
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3208

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3209
You can specify two table by yourself. This is useful when join parser can't parse
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3210
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3211

            
3212
    $dbi->select(
3213
        table => 'book',
3214
        column => ['company.location_id as location_id'],
3215
        where => {'company.name' => 'Orange'},
3216
        join => [
3217
            {
3218
                clause => 'left outer join location on company.location_id = location.id',
3219
                table => ['company', 'location']
3220
            }
3221
        ]
3222
    );
3223

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

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

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3235
=item C<after_build_sql>
updated pod
Yuki Kimoto authored on 2011-06-08
3236

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3237
Same as C<execute> method's C<after_build_sql> option
updated pod
Yuki Kimoto authored on 2011-06-08
3238

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3243
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3244

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3245
=item C<type_rule_off>
updated pod
Yuki Kimoto authored on 2011-06-08
3246

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3249
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3250

            
3251
    type_rule1_off => 1
3252

            
3253
Same as C<execute> method's C<type_rule1_off> option.
3254

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3255
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3256

            
3257
    type_rule2_off => 1
3258

            
3259
Same as C<execute> method's C<type_rule2_off> option.
3260

            
updated document
Yuki Kimoto authored on 2011-06-09
3261
=item C<where>
3262
    
3263
    # Hash refrence
3264
    where => {author => 'Ken', 'title' => 'Perl'}
3265
    
3266
    # DBIx::Custom::Where object
3267
    where => $dbi->where(
3268
        clause => ['and', 'author = :author', 'title like :title'],
3269
        param  => {author => 'Ken', title => '%Perl%'}
3270
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3271
    
3272
    # Array reference 1 (array reference, hash referenc). same as above
3273
    where => [
3274
        ['and', 'author = :author', 'title like :title'],
3275
        {author => 'Ken', title => '%Perl%'}
3276
    ];    
3277
    
3278
    # Array reference 2 (String, hash reference)
3279
    where => [
3280
        'title like :title',
3281
        {title => '%Perl%'}
3282
    ]
3283
    
3284
    # String
3285
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3286

            
updated document
Yuki Kimoto authored on 2011-06-09
3287
Where clause.
3288
    
update pod
Yuki Kimoto authored on 2011-03-12
3289
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3290

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

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

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

            
3297
If you want to set constant value to row data, use scalar reference
3298
as parameter value.
3299

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3304
=over 4
3305

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

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

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

            
3312
Same as C<execute> method's C<bind_type> option.
3313

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3320
    id => 4
3321
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3322

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3326
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3327
        {title => 'Perl', author => 'Ken'}
3328
        parimary_key => ['id1', 'id2'],
3329
        id => [4, 5],
3330
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3331
    );
update pod
Yuki Kimoto authored on 2011-03-13
3332

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3335
    $dbi->update(
3336
        {title => 'Perl', author => 'Ken'}
3337
        where => {id1 => 4, id2 => 5},
3338
        table => 'book'
3339
    );
update pod
Yuki Kimoto authored on 2011-03-13
3340

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

            
3343
    prefix => 'or replace'
3344

            
3345
prefix before table name section
3346

            
3347
    update or replace book
3348

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

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

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3360
=item C<after_build_sql>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3361

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3362
Same as C<execute> method's C<after_build_sql> option.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3363

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3370
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
3371

            
3372
    timestamp => 1
3373

            
3374
If this value is set to 1,
3375
automatically updated timestamp column is set based on
3376
C<timestamp> attribute's C<update> value.
3377

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3378
=item C<type_rule_off>
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3379

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3382
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3383

            
3384
    type_rule1_off => 1
3385

            
3386
Same as C<execute> method's C<type_rule1_off> option.
3387

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3388
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3389

            
3390
    type_rule2_off => 1
3391

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

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

            
3396
Same as C<select> method's C<where> option.
3397

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3398
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
3399

            
3400
    wrap => {price => sub { "max($_[0])" }}
3401

            
3402
placeholder wrapped string.
3403

            
3404
If the following statement
3405

            
3406
    $dbi->update({price => 100}, table => 'book',
3407
      {price => sub { "$_[0] + 5" }});
3408

            
3409
is executed, the following SQL is executed.
3410

            
3411
    update book set price =  ? + 5;
3412

            
updated pod
Yuki Kimoto authored on 2011-06-08
3413
=back
update pod
Yuki Kimoto authored on 2011-03-13
3414

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

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

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

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

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

            
3426
Create update parameter tag.
3427

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3430
=head2 C<update_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3431

            
3432
    $dbi->update_timestamp(updated_at => sub { localtime });
3433

            
3434
Parameter for timestamp columns when C<update> method is executed
3435
with C<timestamp> option.
3436

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

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

            
3444
Create a new L<DBIx::Custom::Where> object.
3445

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3453
=head2 C<show_datatype>
update pod
Yuki Kimoto authored on 2011-08-10
3454

            
3455
    $dbi->show_datatype($table);
3456

            
3457
Show data type of the columns of specified table.
3458

            
3459
    book
3460
    title: 5
3461
    issue_date: 91
3462

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

            
- removed EXPERIMENTAL the f...
Yuki Kimoto authored on 2011-09-12
3465
=head2 C<show_tables>
test cleanup
Yuki Kimoto authored on 2011-08-15
3466

            
3467
    $dbi->show_tables;
3468

            
3469
Show tables.
3470

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3471
=head2 C<show_typename>
update pod
Yuki Kimoto authored on 2011-08-10
3472

            
3473
    $dbi->show_typename($table);
3474

            
3475
Show type name of the columns of specified table.
3476

            
3477
    book
3478
    title: varchar
3479
    issue_date: date
3480

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3483
=head1 ENVIRONMENTAL VARIABLES
3484

            
3485
=head2 C<DBIX_CUSTOM_DEBUG>
3486

            
3487
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3488
executed SQL and bind values are printed to STDERR.
3489

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

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3494
=head1 DEPRECATED FUNCTIONALITY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3495

            
3496
L<DBIx::Custom>
3497

            
3498
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3499
    default_dbi_option # will be removed 2017/1/1
3500
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3501
    data_source # will be removed at 2017/1/1
3502
    dbi_options # will be removed at 2017/1/1
3503
    filter_check # will be removed at 2017/1/1
3504
    reserved_word_quote # will be removed at 2017/1/1
3505
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3506
    
3507
    # Methods
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3508
    assign_param # will be removed at 2017/1/1
3509
    update_param # will be removed at 2017/1/1
3510
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3511
    create_query # will be removed at 2017/1/1
3512
    apply_filter # will be removed at 2017/1/1
3513
    select_at # will be removed at 2017/1/1
3514
    delete_at # will be removed at 2017/1/1
3515
    update_at # will be removed at 2017/1/1
3516
    insert_at # will be removed at 2017/1/1
3517
    register_tag # will be removed at 2017/1/1
3518
    default_bind_filter # will be removed at 2017/1/1
3519
    default_fetch_filter # will be removed at 2017/1/1
3520
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3521
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3522
    register_tag_processor # will be removed at 2017/1/1
3523
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3524
    
3525
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3526
    select method relation option # will be removed at 2017/1/1
3527
    select method param option # will be removed at 2017/1/1
3528
    select method column option [COLUMN, as => ALIAS] format
3529
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3530
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3531
    
3532
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3533
    execute("select * from {= title}"); # execute method's
3534
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3535
                                        # will be removed at 2017/1/1
3536
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3537

            
3538
L<DBIx::Custom::Model>
3539

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3540
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3541
    filter # will be removed at 2017/1/1
3542
    name # will be removed at 2017/1/1
3543
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3544

            
3545
L<DBIx::Custom::Query>
3546
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3547
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3548
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3549
    table # will be removed at 2017/1/1
3550
    filters # will be removed at 2017/1/1
3551
    
3552
    # Methods
3553
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3554

            
3555
L<DBIx::Custom::QueryBuilder>
3556
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3557
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3558
    tags # will be removed at 2017/1/1
3559
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3560
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3561
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3562
    register_tag # will be removed at 2017/1/1
3563
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3564
    
3565
    # Others
3566
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3567
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3568

            
3569
L<DBIx::Custom::Result>
3570
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3571
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3572
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3573
    
3574
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3575
    end_filter # will be removed at 2017/1/1
3576
    remove_end_filter # will be removed at 2017/1/1
3577
    remove_filter # will be removed at 2017/1/1
3578
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3579

            
3580
L<DBIx::Custom::Tag>
3581

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3584
=head1 BACKWARDS COMPATIBILITY POLICY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3585

            
3586
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3587
except for attribute method.
3588
You can check all DEPRECATED functionalities by document.
3589
DEPRECATED functionality is removed after five years,
3590
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
3591
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3592

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

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

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

            
3599
C<< <kimoto.yuki at gmail.com> >>
3600

            
3601
L<http://github.com/yuki-kimoto/DBIx-Custom>
3602

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3603
=head1 AUTHOR
3604

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

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

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

            
3611
This program is free software; you can redistribute it and/or modify it
3612
under the same terms as Perl itself.
3613

            
3614
=cut