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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
4
our $VERSION = '0.1732';
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 $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
241
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
242
    my $id = delete $args{id};
243
    my $primary_key = delete $args{primary_key};
244
    croak "update method primary_key option " .
245
          "must be specified when id is specified " . _subname
246
      if defined $id && !defined $primary_key;
247
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
248
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
249
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
250
    # Where
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
251
    $where = $self->_create_param_from_id($id, $primary_key, $table)
252
      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 ";
packaging one directory
yuki-kimoto authored on 2009-11-16
276
    
277
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
278
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
279
}
280

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
423
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
424
    
425
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
426
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
427
    
cleanup
Yuki Kimoto authored on 2011-04-02
428
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
429
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
430
    my $main_table = @{$tables}[-1];
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
431

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

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

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

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

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

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
597
sub helper {
598
    my $self = shift;
599
    
600
    # Register method
601
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
602
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
603
    
604
    return $self;
605
}
606

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
639
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
640
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
641
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
642
        $param = $self->merge_param($id_param, $param);
643
    }
644

            
cleanup
Yuki Kimoto authored on 2011-04-02
645
    # Insert statement
micro optimization
Yuki Kimoto authored on 2011-09-30
646
    my $sql;
647
    $sql .= "insert ";
648
    $sql .= "$prefix " if defined $prefix;
649
    $sql .= "into " . $self->_q($table) . " "
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
650
      . $self->values_clause($param, {wrap => $wrap}) . " ";
packaging one directory
yuki-kimoto authored on 2009-11-16
651
    
652
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
653
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
654
}
655

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
656
sub update_or_insert {
657
    my $self = shift;
658

            
659
    # Arguments
660
    my $param  = shift;
661
    my %args = @_;
662
    my $id = delete $args{id};
663
    my $primary_key = delete $args{primary_key};
664
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
665
    croak "update_or_insert method need primary_key option " .
666
          "when id is specified" . _subname
667
      if defined $id && !defined $primary_key;
668
    my $table  = delete $args{table};
669
    croak qq{"table" option must be specified } . _subname
670
      unless defined $table;
671
    my $select_option = delete $args{select_option};
672
    
673
    my $rows = $self->select(table => $table, id => $id,
674
        primary_key => $primary_key, %$select_option)->all;
675
    
676
    croak "selected row count must be one or zero" . _subname
677
      if @$rows > 1;
678
    
679
    my $row = $rows->[0];
680
    my @options = (table => $table);
681
    push @options, id => $id, primary_key => $primary_key if defined $id;
682
    push @options, %args;
683
    
684
    if ($row) {
685
        return $self->update($param, @options);
686
    }
687
    else {
688
        return $self->insert($param, @options);
689
    }
690
}
691

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
692
sub insert_timestamp {
693
    my $self = shift;
694
    
695
    if (@_) {
696
        $self->{insert_timestamp} = [@_];
697
        
698
        return $self;
699
    }
700
    return $self->{insert_timestamp};
701
}
702

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
703
sub include_model {
704
    my ($self, $name_space, $model_infos) = @_;
705
    
cleanup
Yuki Kimoto authored on 2011-04-02
706
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
707
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
708
    
709
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
710
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
711

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
712
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
713
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
714
          if $name_space =~ /[^\w:]/;
715
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
716
        croak qq{Name space module "$name_space.pm" is needed. $@ }
717
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
718
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
719
        
720
        # Search model modules
721
        my $path = $INC{"$name_space.pm"};
722
        $path =~ s/\.pm$//;
723
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
724
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
725
        $model_infos = [];
726
        while (my $module = readdir $dh) {
727
            push @$model_infos, $module
728
              if $module =~ s/\.pm$//;
729
        }
730
        close $dh;
731
    }
732
    
cleanup
Yuki Kimoto authored on 2011-04-02
733
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
734
    foreach my $model_info (@$model_infos) {
735
        
cleanup
Yuki Kimoto authored on 2011-04-02
736
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
737
        my $model_class;
738
        my $model_name;
739
        my $model_table;
740
        if (ref $model_info eq 'HASH') {
741
            $model_class = $model_info->{class};
742
            $model_name  = $model_info->{name};
743
            $model_table = $model_info->{table};
744
            
745
            $model_name  ||= $model_class;
746
            $model_table ||= $model_name;
747
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
748
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
749
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
750
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
751
          if $mclass =~ /[^\w:]/;
752
        unless ($mclass->can('isa')) {
753
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
754
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
755
        }
756
        
cleanup
Yuki Kimoto authored on 2011-04-02
757
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
758
        my $args = {};
759
        $args->{model_class} = $mclass if $mclass;
760
        $args->{name}        = $model_name if $model_name;
761
        $args->{table}       = $model_table if $model_table;
762
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
763
    }
764
    
765
    return $self;
766
}
767

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
770
sub mapper {
771
    my $self = shift;
772
    return DBIx::Custom::Mapper->new(@_);
773
}
774

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
775
sub merge_param {
776
    my ($self, @params) = @_;
777
    
cleanup
Yuki Kimoto authored on 2011-04-02
778
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
779
    my $merge = {};
780
    foreach my $param (@params) {
781
        foreach my $column (keys %$param) {
782
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
783
            
784
            if (exists $merge->{$column}) {
785
                $merge->{$column} = [$merge->{$column}]
786
                  unless ref $merge->{$column} eq 'ARRAY';
787
                push @{$merge->{$column}},
788
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
789
            }
790
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
791
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
792
            }
793
        }
794
    }
795
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
796
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
797
}
798

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
799
sub model {
800
    my ($self, $name, $model) = @_;
801
    
cleanup
Yuki Kimoto authored on 2011-04-02
802
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
803
    if ($model) {
804
        $self->models->{$name} = $model;
805
        return $self;
806
    }
807
    
808
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
809
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
810
      unless $self->models->{$name};
811
    
cleanup
Yuki Kimoto authored on 2011-04-02
812
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
813
    return $self->models->{$name};
814
}
815

            
cleanup
Yuki Kimoto authored on 2011-03-21
816
sub mycolumn {
817
    my ($self, $table, $columns) = @_;
818
    
cleanup
Yuki Kimoto authored on 2011-04-02
819
    # Create column clause
820
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
821
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
822
    push @column, $self->_q($table) . "." . $self->_q($_) .
823
      " as " . $self->_q($_)
824
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
825
    
826
    return join (', ', @column);
827
}
828

            
added dbi_options attribute
kimoto authored on 2010-12-20
829
sub new {
830
    my $self = shift->SUPER::new(@_);
831
    
cleanup
Yuki Kimoto authored on 2011-04-02
832
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
833
    my @attrs = keys %$self;
834
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
835
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
836
          unless $self->can($attr);
837
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
838

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
839
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
840
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
841
        '?'     => \&DBIx::Custom::Tag::placeholder,
842
        '='     => \&DBIx::Custom::Tag::equal,
843
        '<>'    => \&DBIx::Custom::Tag::not_equal,
844
        '>'     => \&DBIx::Custom::Tag::greater_than,
845
        '<'     => \&DBIx::Custom::Tag::lower_than,
846
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
847
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
848
        'like'  => \&DBIx::Custom::Tag::like,
849
        'in'    => \&DBIx::Custom::Tag::in,
850
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
851
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
852
    };
853
    
854
    return $self;
855
}
856

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

            
859
sub order {
860
    my $self = shift;
861
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
862
}
863

            
cleanup
yuki-kimoto authored on 2010-10-17
864
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
865
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
866
    
867
    # Register filter
868
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
869
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
870
    
cleanup
Yuki Kimoto authored on 2011-04-02
871
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
872
}
packaging one directory
yuki-kimoto authored on 2009-11-16
873

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
992
sub setup_model {
993
    my $self = shift;
994
    
cleanup
Yuki Kimoto authored on 2011-04-02
995
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
996
    $self->each_column(
997
        sub {
998
            my ($self, $table, $column, $column_info) = @_;
999
            if (my $model = $self->models->{$table}) {
1000
                push @{$model->columns}, $column;
1001
            }
1002
        }
1003
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1004
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1005
}
1006

            
update pod
Yuki Kimoto authored on 2011-08-10
1007
sub show_datatype {
1008
    my ($self, $table) = @_;
1009
    croak "Table name must be specified" unless defined $table;
1010
    print "$table\n";
1011
    
1012
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1013
    my $sth = $result->sth;
1014

            
1015
    my $columns = $sth->{NAME};
1016
    my $data_types = $sth->{TYPE};
1017
    
1018
    for (my $i = 0; $i < @$columns; $i++) {
1019
        my $column = $columns->[$i];
1020
        my $data_type = $data_types->[$i];
1021
        print "$column: $data_type\n";
1022
    }
1023
}
1024

            
1025
sub show_typename {
1026
    my ($self, $t) = @_;
1027
    croak "Table name must be specified" unless defined $t;
1028
    print "$t\n";
1029
    
1030
    $self->each_column(sub {
1031
        my ($self, $table, $column, $infos) = @_;
1032
        return unless $table eq $t;
1033
        my $typename = $infos->{TYPE_NAME};
1034
        print "$column: $typename\n";
1035
    });
1036
    
1037
    return $self;
1038
}
1039

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1040
sub show_tables {
1041
    my $self = shift;
1042
    
1043
    my %tables;
1044
    $self->each_table(sub { $tables{$_[1]}++ });
1045
    print join("\n", sort keys %tables) . "\n";
1046
    return $self;
1047
}
1048

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1084
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1085
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1086
                }
1087
            });
1088
        }
1089

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

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

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

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1185
sub update_timestamp {
1186
    my $self = shift;
1187
    
1188
    if (@_) {
1189
        $self->{update_timestamp} = [@_];
1190
        
1191
        return $self;
1192
    }
1193
    return $self->{update_timestamp};
1194
}
1195

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1196
sub values_clause {
1197
    my ($self, $param, $opts) = @_;
1198
    
1199
    my $wrap = $opts->{wrap} || {};
1200
    
1201
    # Create insert parameter tag
1202
    my $safety = $self->safety_character;
1203
    my @columns;
1204
    my @placeholders;
1205
    foreach my $column (sort keys %$param) {
1206
        croak qq{"$column" is not safety column name } . _subname
1207
          unless $column =~ /^[$safety\.]+$/;
1208
        my $column_quote = $self->_q($column);
1209
        $column_quote =~ s/\./$self->_q(".")/e;
1210
        push @columns, $column_quote;
1211
        
1212
        my $func = $wrap->{$column} || sub { $_[0] };
1213
        push @placeholders,
1214
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1215
        : $func->(":$column");
1216
    }
1217
    
1218
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1219
           '(' . join(', ', @placeholders) . ')'
1220
}
1221

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1224
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1225
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1226
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1227
    
updated pod
Yuki Kimoto authored on 2011-06-21
1228
    # Cache
1229
    my $cache = $self->cache;
1230
    
1231
    # Query
1232
    my $query;
1233
    
1234
    # Get cached query
1235
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1236
        
updated pod
Yuki Kimoto authored on 2011-06-21
1237
        # Get query
1238
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1239
        
updated pod
Yuki Kimoto authored on 2011-06-21
1240
        # Create query
1241
        if ($q) {
1242
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1243
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1244
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1245
    }
1246
    
1247
    # Create query
1248
    unless ($query) {
1249

            
1250
        # Create query
1251
        my $builder = $self->query_builder;
1252
        $query = $builder->build_query($source);
1253

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

            
1260
        # Save query to cache
1261
        $self->cache_method->(
1262
            $self, $source,
1263
            {
1264
                sql     => $query->sql, 
1265
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1266
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1267
            }
1268
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1269
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1270

            
1271
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1272
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1273
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1274
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1275
        $query->sql($sql);
1276
    }
1277
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1278
    # Save sql
1279
    $self->last_sql($query->sql);
1280
    
updated pod
Yuki Kimoto authored on 2011-06-21
1281
    # Prepare statement handle
1282
    my $sth;
1283
    eval { $sth = $self->dbh->prepare($query->{sql})};
1284
    
1285
    if ($@) {
1286
        $self->_croak($@, qq{. Following SQL is executed.\n}
1287
                        . qq{$query->{sql}\n} . _subname);
1288
    }
1289
    
1290
    # Set statement handle
1291
    $query->sth($sth);
1292
    
1293
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1294
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1295
    
1296
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1297
}
1298

            
cleanup
Yuki Kimoto authored on 2011-04-02
1299
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1300
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1301
    
cleanup
Yuki Kimoto authored on 2011-04-02
1302
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1303
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1304
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1305
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1306
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1307
        
1308
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1309
        my $value;
1310
        if(ref $params->{$column} eq 'ARRAY') {
1311
            my $i = $count->{$column} || 0;
1312
            $i += $not_exists->{$column} || 0;
1313
            my $found;
1314
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1315
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1316
                    $not_exists->{$column}++;
1317
                }
1318
                else  {
1319
                    $value = $params->{$column}->[$k];
1320
                    $found = 1;
1321
                    last
1322
                }
1323
            }
1324
            next unless $found;
1325
        }
1326
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1327
        
cleanup
Yuki Kimoto authored on 2011-01-12
1328
        # Filter
1329
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1330
        $value = $f->($value) if $f;
1331
        
1332
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1333
        foreach my $i (1 .. 2) {
1334
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1335
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1336
            $value = $tf->($value) if $tf;
1337
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1338
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1339
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1340
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1341
        
1342
        # Count up 
1343
        $count->{$column}++;
1344
    }
1345
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1346
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1347
}
1348

            
cleanup
Yuki Kimoto authored on 2011-06-08
1349
sub _create_param_from_id {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1350
    my ($self, $id, $primary_keys, $table) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1351
    
cleanup
Yuki Kimoto authored on 2011-06-08
1352
    # Create parameter
1353
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1354
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1355
        $id = [$id] unless ref $id;
1356
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1357
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1358
          unless !ref $id || ref $id eq 'ARRAY';
1359
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1360
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1361
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1362
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1363
           my $key = $primary_keys->[$i];
1364
           $key = "$table." . $key if $table;
1365
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1366
        }
1367
    }
1368
    
cleanup
Yuki Kimoto authored on 2011-06-08
1369
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1370
}
1371

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1372
sub _connect {
1373
    my $self = shift;
1374
    
1375
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1376
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1377
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1378
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1379
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1380
    croak qq{"dsn" must be specified } . _subname
1381
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1382
    my $user        = $self->user;
1383
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1384
    my $option = $self->_option;
1385
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1386
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1387
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1388
    my $dbh;
1389
    eval {
1390
        $dbh = DBI->connect(
1391
            $dsn,
1392
            $user,
1393
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1394
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1395
        );
1396
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1397
    
1398
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1399
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1400
    
1401
    return $dbh;
1402
}
1403

            
cleanup
yuki-kimoto authored on 2010-10-17
1404
sub _croak {
1405
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1406
    
1407
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1408
    $append ||= "";
1409
    
1410
    # Verbose
1411
    if ($Carp::Verbose) { croak $error }
1412
    
1413
    # Not verbose
1414
    else {
1415
        
1416
        # Remove line and module infromation
1417
        my $at_pos = rindex($error, ' at ');
1418
        $error = substr($error, 0, $at_pos);
1419
        $error =~ s/\s+$//;
1420
        croak "$error$append";
1421
    }
1422
}
1423

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1426
sub _need_tables {
1427
    my ($self, $tree, $need_tables, $tables) = @_;
1428
    
cleanup
Yuki Kimoto authored on 2011-04-02
1429
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1430
    foreach my $table (@$tables) {
1431
        if ($tree->{$table}) {
1432
            $need_tables->{$table} = 1;
1433
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1434
        }
1435
    }
1436
}
1437

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1438
sub _option {
1439
    my $self = shift;
1440
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1441
    warn "dbi_options is DEPRECATED! use option instead\n"
1442
      if keys %{$self->dbi_options};
1443
    warn "dbi_option is DEPRECATED! use option instead\n"
1444
      if keys %{$self->dbi_option};
1445
    return $option;
1446
}
1447

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1448
sub _push_join {
1449
    my ($self, $sql, $join, $join_tables) = @_;
1450
    
cleanup
Yuki Kimoto authored on 2011-04-02
1451
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1452
    return unless @$join;
1453
    
cleanup
Yuki Kimoto authored on 2011-04-02
1454
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1455
    my $tree = {};
1456
    for (my $i = 0; $i < @$join; $i++) {
1457
        
cleanup
Yuki Kimoto authored on 2011-07-28
1458
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1459
        my $join_clause;;
1460
        my $option;
1461
        if (ref $join->[$i] eq 'HASH') {
1462
            $join_clause = $join->[$i]->{clause};
1463
            $option = {table => $join->[$i]->{table}};
1464
        }
1465
        else {
1466
            $join_clause = $join->[$i];
1467
            $option = {};
1468
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1469

            
1470
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1471
        my $table1;
1472
        my $table2;
1473
        if (my $table = $option->{table}) {
1474
            $table1 = $table->[0];
1475
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1476
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1477
        else {
1478
            my $q = $self->_quote;
1479
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1480
            $j_clause =~ s/'.+?'//g;
1481
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1482
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1483
            
1484
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1485
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1486
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1487
            for my $clause (@j_clauses) {
1488
                if ($clause =~ $join_re) {
1489
                    $table1 = $1;
1490
                    $table2 = $2;
1491
                    last;
1492
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1493
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1494
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1495
        croak qq{join clause must have two table name after "on" keyword. } .
1496
              qq{"$join_clause" is passed }  . _subname
1497
          unless defined $table1 && defined $table2;
1498
        croak qq{right side table of "$join_clause" must be unique }
1499
            . _subname
1500
          if exists $tree->{$table2};
1501
        croak qq{Same table "$table1" is specified} . _subname
1502
          if $table1 eq $table2;
1503
        $tree->{$table2}
1504
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1505
    }
1506
    
cleanup
Yuki Kimoto authored on 2011-04-02
1507
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1508
    my $need_tables = {};
1509
    $self->_need_tables($tree, $need_tables, $join_tables);
1510
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1511
    
1512
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1513
    foreach my $need_table (@need_tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1514
        $$sql .= $tree->{$need_table}{join} . ' ';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1515
    }
1516
}
cleanup
Yuki Kimoto authored on 2011-03-08
1517

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1518
sub _quote {
1519
    my $self = shift;
1520
    
1521
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1522
         : defined $self->quote ? $self->quote
1523
         : '';
1524
}
1525

            
cleanup
Yuki Kimoto authored on 2011-07-29
1526
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1527
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1528
    
1529
    my $quote = $self->_quote;
1530
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1531
    my $p;
1532
    if (defined $quote && length $quote > 1) {
1533
        $p = substr($quote, 1, 1);
1534
    }
1535
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1536
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1537
    if ($quotemeta) {
1538
        $q = quotemeta($q);
1539
        $p = quotemeta($p);
1540
    }
1541
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1542
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1543
}
1544

            
cleanup
Yuki Kimoto authored on 2011-04-02
1545
sub _remove_duplicate_table {
1546
    my ($self, $tables, $main_table) = @_;
1547
    
1548
    # Remove duplicate table
1549
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1550
    delete $tables{$main_table} if $main_table;
1551
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1552
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1553
    if (my $q = $self->_quote) {
1554
        $q = quotemeta($q);
1555
        $_ =~ s/[$q]//g for @$new_tables;
1556
    }
1557

            
1558
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1559
}
1560

            
cleanup
Yuki Kimoto authored on 2011-04-02
1561
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1562
    my ($self, $source) = @_;
1563
    
cleanup
Yuki Kimoto authored on 2011-04-02
1564
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1565
    my $tables = [];
1566
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1567
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1568
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1569
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1570
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1571
    while ($source =~ /$table_re/g) {
1572
        push @$tables, $1;
1573
    }
1574
    
1575
    return $tables;
1576
}
1577

            
cleanup
Yuki Kimoto authored on 2011-04-02
1578
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1579
    my ($self, $where) = @_;
1580
    
cleanup
Yuki Kimoto authored on 2011-04-02
1581
    my $obj;
1582
    
1583
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1584
    if (ref $where eq 'HASH') {
1585
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1586
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1587
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1588
            my $table;
1589
            my $c;
1590
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1591
                $table = $1;
1592
                $c = $2;
1593
            }
1594
            
1595
            my $table_quote;
1596
            $table_quote = $self->_q($table) if defined $table;
1597
            my $column_quote = $self->_q($c);
1598
            $column_quote = $table_quote . '.' . $column_quote
1599
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1600
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1601
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1602
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1603
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1604
    
1605
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1606
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1607
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1608
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1609
    
updated pod
Yuki Kimoto authored on 2011-06-21
1610
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1611
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1612
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1613
            clause => $where->[0],
1614
            param  => $where->[1]
1615
        );
1616
    }
1617
    
cleanup
Yuki Kimoto authored on 2011-04-02
1618
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1619
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1620
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1621
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1622
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1623
    
cleanup
Yuki Kimoto authored on 2011-04-02
1624
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1625
}
1626

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

            
1630
    # Initialize filters
1631
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1632
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1633
    $self->{filter}{out} ||= {};
1634
    $self->{filter}{in} ||= {};
1635
    $self->{filter}{end} ||= {};
1636
    
1637
    # Usage
1638
    my $usage = "Usage: \$dbi->apply_filter(" .
1639
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1640
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1641
    
1642
    # Apply filter
1643
    for (my $i = 0; $i < @cinfos; $i += 2) {
1644
        
1645
        # Column
1646
        my $column = $cinfos[$i];
1647
        if (ref $column eq 'ARRAY') {
1648
            foreach my $c (@$column) {
1649
                push @cinfos, $c, $cinfos[$i + 1];
1650
            }
1651
            next;
1652
        }
1653
        
1654
        # Filter infomation
1655
        my $finfo = $cinfos[$i + 1] || {};
1656
        croak "$usage (table: $table) " . _subname
1657
          unless  ref $finfo eq 'HASH';
1658
        foreach my $ftype (keys %$finfo) {
1659
            croak "$usage (table: $table) " . _subname
1660
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1661
        }
1662
        
1663
        # Set filters
1664
        foreach my $way (qw/in out end/) {
1665
        
1666
            # Filter
1667
            my $filter = $finfo->{$way};
1668
            
1669
            # Filter state
1670
            my $state = !exists $finfo->{$way} ? 'not_exists'
1671
                      : !defined $filter        ? 'not_defined'
1672
                      : ref $filter eq 'CODE'   ? 'code'
1673
                      : 'name';
1674
            
1675
            # Filter is not exists
1676
            next if $state eq 'not_exists';
1677
            
1678
            # Check filter name
1679
            croak qq{Filter "$filter" is not registered } . _subname
1680
              if  $state eq 'name'
1681
               && ! exists $self->filters->{$filter};
1682
            
1683
            # Set filter
1684
            my $f = $state eq 'not_defined' ? undef
1685
                  : $state eq 'code'        ? $filter
1686
                  : $self->filters->{$filter};
1687
            $self->{filter}{$way}{$table}{$column} = $f;
1688
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1689
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1690
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1691
        }
1692
    }
1693
    
1694
    return $self;
1695
}
1696

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1697
# DEPRECATED!
1698
has 'data_source';
1699
has dbi_options => sub { {} };
1700
has filter_check  => 1;
1701
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1702
has dbi_option => sub { {} };
1703
has default_dbi_option => sub {
1704
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1705
    return shift->default_option;
1706
};
1707

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1708
# DEPRECATED!
1709
sub method {
1710
    warn "method is DEPRECATED! use helper instead";
1711
    return shift->helper(@_);
1712
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1713

            
1714
# DEPRECATED!
1715
sub assign_param {
1716
    my $self = shift;
1717
    warn "assing_param is DEPRECATED! use assign_clause instead";
1718
    return $self->assign_clause(@_);
1719
}
1720

            
1721
# DEPRECATED
1722
sub update_param {
1723
    my ($self, $param, $opts) = @_;
1724
    
1725
    warn "update_param is DEPRECATED! use assing_clause instead.";
1726
    
1727
    # Create update parameter tag
1728
    my $tag = $self->assign_clause($param, $opts);
1729
    $tag = "set $tag" unless $opts->{no_set};
1730

            
1731
    return $tag;
1732
}
1733

            
updated pod
Yuki Kimoto authored on 2011-06-21
1734
# DEPRECATED!
1735
sub create_query {
1736
    warn "create_query is DEPRECATED! use query option of each method";
1737
    shift->_create_query(@_);
1738
}
1739

            
cleanup
Yuki Kimoto authored on 2011-06-13
1740
# DEPRECATED!
1741
sub apply_filter {
1742
    my $self = shift;
1743
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1744
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1745
    return $self->_apply_filter(@_);
1746
}
1747

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1755
    # Arguments
1756
    my $primary_keys = delete $args{primary_key};
1757
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1758
    my $where = delete $args{where};
1759
    my $param = delete $args{param};
1760
    
1761
    # Check arguments
1762
    foreach my $name (keys %args) {
1763
        croak qq{"$name" is wrong option } . _subname
1764
          unless $SELECT_AT_ARGS{$name};
1765
    }
1766
    
1767
    # Table
1768
    croak qq{"table" option must be specified } . _subname
1769
      unless $args{table};
1770
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1771
    
1772
    # Create where parameter
1773
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1774
    
1775
    return $self->select(where => $where_param, %args);
1776
}
1777

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

            
1783
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1784
    
1785
    # Arguments
1786
    my $primary_keys = delete $args{primary_key};
1787
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1788
    my $where = delete $args{where};
1789
    
1790
    # Check arguments
1791
    foreach my $name (keys %args) {
1792
        croak qq{"$name" is wrong option } . _subname
1793
          unless $DELETE_AT_ARGS{$name};
1794
    }
1795
    
1796
    # Create where parameter
1797
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1798
    
1799
    return $self->delete(where => $where_param, %args);
1800
}
1801

            
cleanup
Yuki Kimoto authored on 2011-06-08
1802
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1803
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1804
sub update_at {
1805
    my $self = shift;
1806

            
1807
    warn "update_at is DEPRECATED! use update and id option instead";
1808
    
1809
    # Arguments
1810
    my $param;
1811
    $param = shift if @_ % 2;
1812
    my %args = @_;
1813
    my $primary_keys = delete $args{primary_key};
1814
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1815
    my $where = delete $args{where};
1816
    my $p = delete $args{param} || {};
1817
    $param  ||= $p;
1818
    
1819
    # Check arguments
1820
    foreach my $name (keys %args) {
1821
        croak qq{"$name" is wrong option } . _subname
1822
          unless $UPDATE_AT_ARGS{$name};
1823
    }
1824
    
1825
    # Create where parameter
1826
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1827
    
1828
    return $self->update(where => $where_param, param => $param, %args);
1829
}
1830

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1831
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1832
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1833
sub insert_at {
1834
    my $self = shift;
1835
    
1836
    warn "insert_at is DEPRECATED! use insert and id option instead";
1837
    
1838
    # Arguments
1839
    my $param;
1840
    $param = shift if @_ % 2;
1841
    my %args = @_;
1842
    my $primary_key = delete $args{primary_key};
1843
    $primary_key = [$primary_key] unless ref $primary_key;
1844
    my $where = delete $args{where};
1845
    my $p = delete $args{param} || {};
1846
    $param  ||= $p;
1847
    
1848
    # Check arguments
1849
    foreach my $name (keys %args) {
1850
        croak qq{"$name" is wrong option } . _subname
1851
          unless $INSERT_AT_ARGS{$name};
1852
    }
1853
    
1854
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1855
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1856
    $param = $self->merge_param($where_param, $param);
1857
    
1858
    return $self->insert(param => $param, %args);
1859
}
1860

            
added warnings
Yuki Kimoto authored on 2011-06-07
1861
# DEPRECATED!
1862
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1863
    my $self = shift;
1864
    
added warnings
Yuki Kimoto authored on 2011-06-07
1865
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1866
    
1867
    # Merge tag
1868
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1869
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1870
    
1871
    return $self;
1872
}
1873

            
1874
# DEPRECATED!
1875
sub register_tag_processor {
1876
    my $self = shift;
1877
    warn "register_tag_processor is DEPRECATED!";
1878
    # Merge tag
1879
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1880
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1881
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1882
}
1883

            
cleanup
Yuki Kimoto authored on 2011-01-25
1884
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1885
sub default_bind_filter {
1886
    my $self = shift;
1887
    
cleanup
Yuki Kimoto authored on 2011-06-13
1888
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1889
    
cleanup
Yuki Kimoto authored on 2011-01-12
1890
    if (@_) {
1891
        my $fname = $_[0];
1892
        
1893
        if (@_ && !$fname) {
1894
            $self->{default_out_filter} = undef;
1895
        }
1896
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1897
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1898
              unless exists $self->filters->{$fname};
1899
        
1900
            $self->{default_out_filter} = $self->filters->{$fname};
1901
        }
1902
        return $self;
1903
    }
1904
    
1905
    return $self->{default_out_filter};
1906
}
1907

            
cleanup
Yuki Kimoto authored on 2011-01-25
1908
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1909
sub default_fetch_filter {
1910
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1911

            
cleanup
Yuki Kimoto authored on 2011-06-13
1912
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1913
    
1914
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1915
        my $fname = $_[0];
1916

            
cleanup
Yuki Kimoto authored on 2011-01-12
1917
        if (@_ && !$fname) {
1918
            $self->{default_in_filter} = undef;
1919
        }
1920
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1921
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1922
              unless exists $self->filters->{$fname};
1923
        
1924
            $self->{default_in_filter} = $self->filters->{$fname};
1925
        }
1926
        
1927
        return $self;
1928
    }
1929
    
many changed
Yuki Kimoto authored on 2011-01-23
1930
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1931
}
1932

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1933
# DEPRECATED!
1934
sub insert_param {
1935
    my $self = shift;
1936
    warn "insert_param is DEPRECATED! use values_clause instead";
1937
    return $self->values_clause(@_);
1938
}
1939

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1940
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1941
sub insert_param_tag {
1942
    warn "insert_param_tag is DEPRECATED! " .
1943
         "use insert_param instead!";
1944
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1945
}
1946

            
1947
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1948
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1949
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1950
         "use update_param instead";
1951
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1952
}
cleanup
Yuki Kimoto authored on 2011-03-08
1953
# DEPRECATED!
1954
sub _push_relation {
1955
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1956
    
1957
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1958
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1959
        foreach my $rcolumn (keys %$relation) {
1960
            my $table1 = (split (/\./, $rcolumn))[0];
1961
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1962
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1963
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1964
        }
1965
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1966
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1967
}
1968

            
1969
# DEPRECATED!
1970
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1971
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1972
    
1973
    if (keys %{$relation || {}}) {
1974
        foreach my $rcolumn (keys %$relation) {
1975
            my $table1 = (split (/\./, $rcolumn))[0];
1976
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1977
            my $table1_exists;
1978
            my $table2_exists;
1979
            foreach my $table (@$tables) {
1980
                $table1_exists = 1 if $table eq $table1;
1981
                $table2_exists = 1 if $table eq $table2;
1982
            }
1983
            unshift @$tables, $table1 unless $table1_exists;
1984
            unshift @$tables, $table2 unless $table2_exists;
1985
        }
1986
    }
1987
}
1988

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1991
=head1 NAME
1992

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1997
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1998
    
1999
    # Connect
2000
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2001
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2002
        user => 'ken',
2003
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2004
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2005
    );
cleanup
yuki-kimoto authored on 2010-08-05
2006

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2007
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
2008
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
2009
    
2010
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
2011
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
2012
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
2013
    
2014
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
2015
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
2016

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2021
    # Select, more complex
2022
    my $result = $dbi->select(
2023
        table  => 'book',
2024
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
2025
            {book => [qw/title author/]},
2026
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2027
        ],
2028
        where  => {'book.author' => 'Ken'},
2029
        join => ['left outer join company on book.company_id = company.id'],
2030
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
2031
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2032
    
removed register_format()
yuki-kimoto authored on 2010-05-26
2033
    # Fetch
2034
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2035
        
removed register_format()
yuki-kimoto authored on 2010-05-26
2036
    }
2037
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2038
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2039
    while (my $row = $result->fetch_hash) {
2040
        
2041
    }
2042
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2043
    # Execute SQL with parameter.
2044
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2045
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2046
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2047
    );
2048
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2049
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2050

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2066
Named place holder support
2067

            
2068
=item *
2069

            
cleanup
Yuki Kimoto authored on 2011-07-29
2070
Model support
2071

            
2072
=item *
2073

            
2074
Connection manager support
2075

            
2076
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2077

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

            
2082
=item *
2083

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

            
2086
=item *
2087

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

            
2090
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2091

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2099
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2100
L<DBIx::Custom::Result>,
2101
L<DBIx::Custom::Query>,
2102
L<DBIx::Custom::Where>,
2103
L<DBIx::Custom::Model>,
2104
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2105

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

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

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

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

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

            
2119
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2120
        "dbi:mysql:database=$database",
2121
        $user,
2122
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2123
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2124
    );
2125
    
updated pod
Yuki Kimoto authored on 2011-06-21
2126
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2127

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

            
2131
    my $dbi = DBIx::Custom->connect(
2132
      dsn => $dsn, user => $user, password => $password, connector => 1);
2133
    
2134
    my $connector = $dbi->connector; # DBIx::Connector
2135

            
2136
Note that L<DBIx::Connector> must be installed.
2137

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2153
    {
2154
        RaiseError => 1,
2155
        PrintError => 0,
2156
        AutoCommit => 1,
2157
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2158

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2159
=head2 C<exclude_table>
2160

            
2161
    my $exclude_table = $dbi->exclude_table;
2162
    $dbi = $dbi->exclude_table(qr/pg_/);
2163

            
2164
Excluded table regex.
2165
C<each_column>, C<each_table>, C<type_rule>,
2166
and C<setup_model> methods ignore matching tables.
2167

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

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

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

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

            
2177
    my $last_sql = $dbi->last_sql;
2178
    $dbi = $dbi->last_sql($last_sql);
2179

            
2180
Get last successed SQL executed by C<execute> method.
2181

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2189
=head2 C<option>
2190

            
2191
    my $option = $dbi->option;
2192
    $dbi = $dbi->option($option);
2193

            
2194
L<DBI> option, used when C<connect> method is executed.
2195
Each value in option override the value of C<default_option>.
2196

            
cleanup
yuki-kimoto authored on 2010-10-17
2197
=head2 C<password>
2198

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2219
You can set quote pair.
2220

            
2221
    $dbi->quote('[]');
2222

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2232
    my $safety_character = $dbi->safety_character;
2233
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2234

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

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

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

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

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

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

            
2251
    my $tag_parse = $dbi->tag_parse(0);
2252
    $dbi = $dbi->tag_parse;
2253

            
2254
Enable DEPRECATED tag parsing functionality, default to 1.
2255
If you want to disable tag parsing functionality, set to 0.
2256

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

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

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

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

            
2266
    my $user_column_info = $dbi->user_column_info;
2267
    $dbi = $dbi->user_column_info($user_column_info);
2268

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

            
2271
    [
2272
        {table => 'book', column => 'title', info => {...}},
2273
        {table => 'author', column => 'name', info => {...}}
2274
    ]
2275

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

            
2278
    my $user_column_info
2279
      = $dbi->get_column_info(exclude_table => qr/^system/);
2280
    $dbi->user_column_info($user_column_info);
2281

            
2282
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
2283
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2284

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

            
2287
    my $user_table_info = $dbi->user_table_info;
2288
    $dbi = $dbi->user_table_info($user_table_info);
2289

            
2290
You can set the following data.
2291

            
2292
    [
2293
        {table => 'book', info => {...}},
2294
        {table => 'author', info => {...}}
2295
    ]
2296

            
2297
Usually, you can set return value of C<get_table_info>.
2298

            
2299
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2300
    $dbi->user_table_info($user_table_info);
2301

            
2302
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2303
to find table info.
2304

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2341
Create column clause. The follwoing column clause is created.
2342

            
2343
    book.author as "book.author",
2344
    book.title as "book.title"
2345

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2348
    # Separator is hyphen
2349
    $dbi->separator('-');
2350
    
2351
    book.author as "book-author",
2352
    book.title as "book-title"
2353
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2354
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2355

            
update pod
Yuki Kimoto authored on 2011-03-13
2356
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2357
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2358
        user => 'ken',
2359
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2360
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2361
    );
2362

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

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

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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2371
    my $count = $dbi->count(table => 'book');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2372

            
2373
Get rows count.
2374

            
2375
Options is same as C<select> method's ones.
2376

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2379
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2380
        table => 'book',
2381
        primary_key => 'id',
2382
        join => [
2383
            'inner join company on book.comparny_id = company.id'
2384
        ],
2385
    );
2386

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

            
2390
   $dbi->model('book')->select(...);
2391

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

            
2394
    my $dbh = $dbi->dbh;
2395

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

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

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

            
2403
Execute delete statement.
2404

            
2405
The following opitons are available.
2406

            
2407
=over 4
2408

            
2409
=item C<append>
2410

            
2411
Same as C<select> method's C<append> option.
2412

            
2413
=item C<filter>
2414

            
2415
Same as C<execute> method's C<filter> option.
2416

            
2417
=item C<id>
2418

            
2419
    id => 4
2420
    id => [4, 5]
2421

            
2422
ID corresponding to C<primary_key>.
2423
You can delete rows by C<id> and C<primary_key>.
2424

            
2425
    $dbi->delete(
2426
        parimary_key => ['id1', 'id2'],
2427
        id => [4, 5],
2428
        table => 'book',
2429
    );
2430

            
2431
The above is same as the followin one.
2432

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

            
2435
=item C<prefix>
2436

            
2437
    prefix => 'some'
2438

            
2439
prefix before table name section.
2440

            
2441
    delete some from book
2442

            
2443
=item C<query>
2444

            
2445
Same as C<execute> method's C<query> option.
2446

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

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

            
2451
=item C<table>
2452

            
2453
    table => 'book'
2454

            
2455
Table name.
2456

            
2457
=item C<where>
2458

            
2459
Same as C<select> method's C<where> option.
2460

            
2461
=item C<primary_key>
2462

            
2463
See C<id> option.
2464

            
2465
=item C<bind_type>
2466

            
2467
Same as C<execute> method's C<bind_type> option.
2468

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

            
2471
Same as C<execute> method's C<type_rule_off> option.
2472

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

            
2475
    type_rule1_off => 1
2476

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

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

            
2481
    type_rule2_off => 1
2482

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

            
2485
=back
2486

            
2487
=head2 C<delete_all>
2488

            
2489
    $dbi->delete_all(table => $table);
2490

            
2491
Execute delete statement for all rows.
2492
Options is same as C<delete>.
2493

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

            
2496
    $dbi->each_column(
2497
        sub {
2498
            my ($dbi, $table, $column, $column_info) = @_;
2499
            
2500
            my $type = $column_info->{TYPE_NAME};
2501
            
2502
            if ($type eq 'DATE') {
2503
                # ...
2504
            }
2505
        }
2506
    );
2507

            
improved pod
Yuki Kimoto authored on 2011-10-14
2508
Iterate all column informations in database.
2509
Argument is callback which is executed when one column is found.
2510
Callback receive four arguments. C<DBIx::Custom object>, C<table name>,
2511
C<column name>, and C<column information>.
2512

            
2513
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2514
infromation, you can improve the performance of C<each_column> in
2515
the following way.
2516

            
2517
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
2518
    $dbi->user_column_info($column_info);
2519
    $dbi->each_column(sub { ... });
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2520

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

            
2523
    $dbi->each_table(
2524
        sub {
2525
            my ($dbi, $table, $table_info) = @_;
2526
            
2527
            my $table_name = $table_info->{TABLE_NAME};
2528
        }
2529
    );
2530

            
improved pod
Yuki Kimoto authored on 2011-10-14
2531
Iterate all table informationsfrom in database.
2532
Argument is callback which is executed when one table is found.
2533
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2534
C<table information>.
2535

            
2536
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2537
infromation, you can improve the performance of C<each_table> in
2538
the following way.
2539

            
2540
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
2541
    $dbi->user_table_info($table_info);
2542
    $dbi->each_table(sub { ... });
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2543

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

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

            
2551
    my $result = $dbi->execute(
2552
      "select * from book where title = :book.title and author like :book.author",
2553
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2554
    );
2555

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2562
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2563
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2564
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2565
    select * from book where title = :title and author like :author
2566
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2567
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2568
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2569

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2573
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2574
    select * from book where :title{=} and :author{like}
2575
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2576
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2577
    select * from where title = ? and author like ?;
2578

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

            
2583
    select * from where title = "aa\\:bb";
2584

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

            
2587
=over 4
2588

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

            
2591
Specify database bind data type.
2592

            
2593
    bind_type => [image => DBI::SQL_BLOB]
2594
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2595

            
2596
This is used to bind parameter by C<bind_param> of statment handle.
2597

            
2598
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2599

            
update pod
Yuki Kimoto authored on 2011-03-13
2600
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2601
    
2602
    filter => {
2603
        title  => sub { uc $_[0] }
2604
        author => sub { uc $_[0] }
2605
    }
update pod
Yuki Kimoto authored on 2011-03-13
2606

            
updated pod
Yuki Kimoto authored on 2011-06-09
2607
    # Filter name
2608
    filter => {
2609
        title  => 'upper_case',
2610
        author => 'upper_case'
2611
    }
2612
        
2613
    # At once
2614
    filter => [
2615
        [qw/title author/]  => sub { uc $_[0] }
2616
    ]
2617

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

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

            
2625
    id => 4
2626
    id => [4, 5]
2627

            
2628
ID corresponding to C<primary_key>.
2629
You can delete rows by C<id> and C<primary_key>.
2630

            
2631
    $dbi->execute(
2632
        "select * from book where id1 = :id1 and id2 = :id2",
2633
        {},
2634
        parimary_key => ['id1', 'id2'],
2635
        id => [4, 5],
2636
    );
2637

            
2638
The above is same as the followin one.
2639

            
2640
    $dbi->execute(
2641
        "select * from book where id1 = :id1 and id2 = :id2",
2642
        {id1 => 4, id2 => 5}
2643
    );
2644

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

            
2647
    query => 1
2648

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

            
2652
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2653
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2654
    my $columns = $query->columns;
2655
    
2656
If you want to execute SQL fast, you can do the following way.
2657

            
2658
    my $query;
2659
    foreach my $row (@$rows) {
2660
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2661
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2662
    }
2663

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

            
2667
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
2668
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2669
    
2670
    my $query;
2671
    my $sth;
2672
    foreach my $row (@$rows) {
2673
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2674
      $sth ||= $query->sth;
2675
      $sth->execute(map { $row->{$_} } sort keys %$row);
2676
    }
2677

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

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

            
2684
See C<id> option.
2685

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

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

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

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

            
2694
    $dbi->select(
2695
        table => 'book',
2696
        column => 'distinct(name)',
2697
        after_build_sql => sub {
2698
            "select count(*) from ($_[0]) as t1"
2699
        }
2700
    );
2701

            
2702
The following SQL is executed.
2703

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2706
=item C<table>
2707
    
2708
    table => 'author'
2709

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2717
    # Same
2718
    $dbi->execute(
2719
      "select * from book where title = :book.title and author = :book.author",
2720
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2721

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

            
2724
    table_alias => {user => 'hiker'}
2725

            
2726
Table alias. Key is real table name, value is alias table name.
2727
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2728
on alias table name.
2729

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

            
2732
    type_rule_off => 1
2733

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

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

            
2738
    type_rule1_off => 1
2739

            
2740
Turn C<into1> type rule off.
2741

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

            
2744
    type_rule2_off => 1
2745

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

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

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

            
improved pod
Yuki Kimoto authored on 2011-10-14
2752
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2753

            
2754
get column infomation except for one which match C<exclude_table> pattern.
2755

            
2756
    [
2757
        {table => 'book', column => 'title', info => {...}},
2758
        {table => 'author', column => 'name' info => {...}}
2759
    ]
2760

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

            
improved pod
Yuki Kimoto authored on 2011-10-14
2763
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2764

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

            
2767
    [
2768
        {table => 'book', info => {...}},
2769
        {table => 'author', info => {...}}
2770
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2771

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2774
=head2 C<helper>
2775

            
2776
    $dbi->helper(
2777
        update_or_insert => sub {
2778
            my $self = shift;
2779
            
2780
            # Process
2781
        },
2782
        find_or_create   => sub {
2783
            my $self = shift;
2784
            
2785
            # Process
2786
        }
2787
    );
2788

            
2789
Register helper. These helper is called directly from L<DBIx::Custom> object.
2790

            
2791
    $dbi->update_or_insert;
2792
    $dbi->find_or_create;
2793

            
cleanup
yuki-kimoto authored on 2010-10-17
2794
=head2 C<insert>
2795

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

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

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

            
2804
    {date => \"NOW()"}
2805

            
cleanup
Yuki Kimoto authored on 2011-10-20
2806
B<options>
2807

            
2808
C<insert> method use all of C<execute> method options,
2809
and use the following new ones.
update pod
Yuki Kimoto authored on 2011-03-13
2810

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

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2817
=item C<id>
2818

            
updated document
Yuki Kimoto authored on 2011-06-09
2819
    id => 4
2820
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2821

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2825
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2826
        {title => 'Perl', author => 'Ken'}
2827
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2828
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2829
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2830
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2831

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

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

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

            
2841
    prefix => 'or replace'
2842

            
2843
prefix before table name section
2844

            
2845
    insert or replace into book
2846

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

            
2849
    table => 'book'
2850

            
2851
Table name.
2852

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

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

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

            
2859
    timestamp => 1
2860

            
2861
If this value is set to 1,
2862
automatically created timestamp column is set based on
2863
C<timestamp> attribute's C<insert> value.
2864

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

            
2867
    type_rule1_off => 1
2868

            
2869
Same as C<execute> method's C<type_rule1_off> option.
2870

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

            
2873
    type_rule2_off => 1
2874

            
2875
Same as C<execute> method's C<type_rule2_off> option.
2876

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

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

            
2881
placeholder wrapped string.
2882

            
2883
If the following statement
2884

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

            
2888
is executed, the following SQL is executed.
2889

            
2890
    insert into book price values ( ? + 5 );
2891

            
update pod
Yuki Kimoto authored on 2011-03-13
2892
=back
2893

            
2894
=over 4
2895

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2903
    lib / MyModel.pm
2904
        / MyModel / book.pm
2905
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2906

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

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

            
2911
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2912
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2913
    
2914
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2915

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2920
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2921
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2922
    
2923
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2924

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2927
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2928
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2929
    
2930
    1;
2931
    
updated pod
Yuki Kimoto authored on 2011-06-21
2932
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2933

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2943
$dbi->insert_timestamp(
2944
  [qw/created_at updated_at/]
2945
    => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
2946
);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2947

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2948
Timestamp value when C<insert> method is executed
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2949
with C<timestamp> option.
2950

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2951
If C<insert_timestamp> is set and C<insert> method is executed
2952
with C<timestamp> option, column C<created_at> and C<update_at>
2953
is automatically set to the value like "2010-10-11 10:12:54".
2954

            
2955
$dbi->insert($param, table => 'book', timestamp => 1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2956

            
cleanup
Yuki Kimoto authored on 2011-10-20
2957
=head2 C<like_value>
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2958

            
2959
    my $like_value = $dbi->like_value
2960

            
cleanup
Yuki Kimoto authored on 2011-10-20
2961
Code reference which return a value for the like value.
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2962

            
2963
    sub { "%$_[0]%" }
2964

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

            
2967
    my $mapper = $dbi->mapper(param => $param);
2968

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2975
Merge parameters. The following new parameter is created.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2976

            
2977
    {key1 => [1, 1], key2 => 2}
2978

            
cleanup
Yuki Kimoto authored on 2011-10-20
2979
If same keys contains, the value is converted to array reference.
2980

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

            
2983
    my $model = $dbi->model('book');
2984

            
cleanup
Yuki Kimoto authored on 2011-10-20
2985
Get a L<DBIx::Custom::Model> object
2986
create by C<create_model> or C<include_model>
update pod
Yuki Kimoto authored on 2011-03-13
2987

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

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

            
2992
Create column clause for myself. The follwoing column clause is created.
2993

            
2994
    book.author as author,
2995
    book.title as title
2996

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

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

            
3006
Create a new L<DBIx::Custom> object.
3007

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

            
3010
    my $not_exists = $dbi->not_exists;
3011

            
update pod
Yuki Kimoto authored on 2011-03-13
3012
DBIx::Custom::NotExists object, indicating the column is not exists.
cleanup
Yuki Kimoto authored on 2011-10-20
3013
This is used in C<param> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
3014

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

            
3017
    my $order = $dbi->order;
3018

            
3019
Create a new L<DBIx::Custom::Order> object.
3020

            
cleanup
yuki-kimoto authored on 2010-10-17
3021
=head2 C<register_filter>
3022

            
update pod
Yuki Kimoto authored on 2011-03-13
3023
    $dbi->register_filter(
3024
        # Time::Piece object to database DATE format
3025
        tp_to_date => sub {
3026
            my $tp = shift;
3027
            return $tp->strftime('%Y-%m-%d');
3028
        },
3029
        # database DATE format to Time::Piece object
3030
        date_to_tp => sub {
3031
           my $date = shift;
3032
           return Time::Piece->strptime($date, '%Y-%m-%d');
3033
        }
3034
    );
cleanup
yuki-kimoto authored on 2010-10-17
3035
    
update pod
Yuki Kimoto authored on 2011-03-13
3036
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3037

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3040
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3041
        table  => 'book',
3042
        column => ['author', 'title'],
3043
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3044
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3045
    
updated document
Yuki Kimoto authored on 2011-06-09
3046
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3047

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

            
3050
=over 4
3051

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

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

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

            
3058
=item C<bind_type>
3059

            
3060
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3061
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3062
=item C<column>
3063
    
updated document
Yuki Kimoto authored on 2011-06-09
3064
    column => 'author'
3065
    column => ['author', 'title']
3066

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3075
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3076
        {book => [qw/author title/]},
3077
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3078
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3079

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

            
3082
    book.author as "book.author",
3083
    book.title as "book.title",
3084
    person.name as "person.name",
3085
    person.age as "person.age"
3086

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

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

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

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

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

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

            
3102
=item C<id>
3103

            
3104
    id => 4
3105
    id => [4, 5]
3106

            
3107
ID corresponding to C<primary_key>.
3108
You can select rows by C<id> and C<primary_key>.
3109

            
3110
    $dbi->select(
3111
        parimary_key => ['id1', 'id2'],
3112
        id => [4, 5],
3113
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3114
    );
3115

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3118
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3119
        where => {id1 => 4, id2 => 5},
3120
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3121
    );
3122
    
updated document
Yuki Kimoto authored on 2011-06-09
3123
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3124

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

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

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

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

            
3137
    prefix => 'SQL_CALC_FOUND_ROWS'
3138

            
3139
Prefix of column cluase
3140

            
3141
    select SQL_CALC_FOUND_ROWS title, author from book;
3142

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

            
3145
    join => [
3146
        'left outer join company on book.company_id = company_id',
3147
        'left outer join location on company.location_id = location.id'
3148
    ]
3149
        
3150
Join clause. If column cluase or where clause contain table name like "company.name",
3151
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3152

            
3153
    $dbi->select(
3154
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3155
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3156
        where => {'company.name' => 'Orange'},
3157
        join => [
3158
            'left outer join company on book.company_id = company.id',
3159
            'left outer join location on company.location_id = location.id'
3160
        ]
3161
    );
3162

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3166
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3167
    from book
3168
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3169
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3170

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3171
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
3172
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3173

            
3174
    $dbi->select(
3175
        table => 'book',
3176
        column => ['company.location_id as location_id'],
3177
        where => {'company.name' => 'Orange'},
3178
        join => [
3179
            {
3180
                clause => 'left outer join location on company.location_id = location.id',
3181
                table => ['company', 'location']
3182
            }
3183
        ]
3184
    );
3185

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3205
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3206

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

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

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

            
3213
    type_rule1_off => 1
3214

            
3215
Same as C<execute> method's C<type_rule1_off> option.
3216

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

            
3219
    type_rule2_off => 1
3220

            
3221
Same as C<execute> method's C<type_rule2_off> option.
3222

            
updated document
Yuki Kimoto authored on 2011-06-09
3223
=item C<where>
3224
    
3225
    # Hash refrence
3226
    where => {author => 'Ken', 'title' => 'Perl'}
3227
    
3228
    # DBIx::Custom::Where object
3229
    where => $dbi->where(
3230
        clause => ['and', 'author = :author', 'title like :title'],
3231
        param  => {author => 'Ken', title => '%Perl%'}
3232
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3233
    
3234
    # Array reference 1 (array reference, hash referenc). same as above
3235
    where => [
3236
        ['and', 'author = :author', 'title like :title'],
3237
        {author => 'Ken', title => '%Perl%'}
3238
    ];    
3239
    
3240
    # Array reference 2 (String, hash reference)
3241
    where => [
3242
        'title like :title',
3243
        {title => '%Perl%'}
3244
    ]
3245
    
3246
    # String
3247
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3248

            
updated document
Yuki Kimoto authored on 2011-06-09
3249
Where clause.
3250
    
update pod
Yuki Kimoto authored on 2011-03-12
3251
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3252

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3253
=head2 C<setup_model>
3254

            
3255
    $dbi->setup_model;
3256

            
3257
Setup all model objects.
3258
C<columns> of model object is automatically set, parsing database information.
3259

            
3260
=head2 C<type_rule>
3261

            
3262
    $dbi->type_rule(
3263
        into1 => {
3264
            date => sub { ... },
3265
            datetime => sub { ... }
3266
        },
3267
        into2 => {
3268
            date => sub { ... },
3269
            datetime => sub { ... }
3270
        },
3271
        from1 => {
3272
            # DATE
3273
            9 => sub { ... },
3274
            # DATETIME or TIMESTAMP
3275
            11 => sub { ... },
3276
        }
3277
        from2 => {
3278
            # DATE
3279
            9 => sub { ... },
3280
            # DATETIME or TIMESTAMP
3281
            11 => sub { ... },
3282
        }
3283
    );
3284

            
3285
Filtering rule when data is send into and get from database.
3286
This has a little complex problem.
3287

            
3288
In C<into1> and C<into2> you can specify
3289
type name as same as type name defined
3290
by create table, such as C<DATETIME> or C<DATE>.
3291

            
3292
Note that type name and data type don't contain upper case.
3293
If these contain upper case charactor, you convert it to lower case.
3294

            
3295
C<into2> is executed after C<into1>.
3296

            
3297
Type rule of C<into1> and C<into2> is enabled on the following
3298
column name.
3299

            
3300
=over 4
3301

            
3302
=item 1. column name
3303

            
3304
    issue_date
3305
    issue_datetime
3306

            
3307
This need C<table> option in each method.
3308

            
3309
=item 2. table name and column name, separator is dot
3310

            
3311
    book.issue_date
3312
    book.issue_datetime
3313

            
3314
=back
3315

            
3316
You get all type name used in database by C<available_typename>.
3317

            
3318
    print $dbi->available_typename;
3319

            
3320
In C<from1> and C<from2> you specify data type, not type name.
3321
C<from2> is executed after C<from1>.
3322
You get all data type by C<available_datatype>.
3323

            
3324
    print $dbi->available_datatype;
3325

            
3326
You can also specify multiple types at once.
3327

            
3328
    $dbi->type_rule(
3329
        into1 => [
3330
            [qw/DATE DATETIME/] => sub { ... },
3331
        ],
3332
    );
3333

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

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

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

            
3340
If you want to set constant value to row data, use scalar reference
3341
as parameter value.
3342

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3347
=over 4
3348

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

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

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

            
3355
Same as C<execute> method's C<bind_type> option.
3356

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3363
    id => 4
3364
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3365

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3369
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3370
        {title => 'Perl', author => 'Ken'}
3371
        parimary_key => ['id1', 'id2'],
3372
        id => [4, 5],
3373
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3374
    );
update pod
Yuki Kimoto authored on 2011-03-13
3375

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3378
    $dbi->update(
3379
        {title => 'Perl', author => 'Ken'}
3380
        where => {id1 => 4, id2 => 5},
3381
        table => 'book'
3382
    );
update pod
Yuki Kimoto authored on 2011-03-13
3383

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

            
3386
    prefix => 'or replace'
3387

            
3388
prefix before table name section
3389

            
3390
    update or replace book
3391

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

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

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

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

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

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

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

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

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

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

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

            
3415
    timestamp => 1
3416

            
3417
If this value is set to 1,
3418
automatically updated timestamp column is set based on
3419
C<timestamp> attribute's C<update> value.
3420

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

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

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

            
3427
    type_rule1_off => 1
3428

            
3429
Same as C<execute> method's C<type_rule1_off> option.
3430

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

            
3433
    type_rule2_off => 1
3434

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

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

            
3439
Same as C<select> method's C<where> option.
3440

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

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

            
3445
placeholder wrapped string.
3446

            
3447
If the following statement
3448

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

            
3452
is executed, the following SQL is executed.
3453

            
3454
    update book set price =  ? + 5;
3455

            
updated pod
Yuki Kimoto authored on 2011-06-08
3456
=back
update pod
Yuki Kimoto authored on 2011-03-13
3457

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3458

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3466
=head2 C<update_or_insert EXPERIMENTAL>
3467
    
3468
    # Where
3469
    $dbi->update_or_insert(
3470
        {id => 1, title => 'Perl'},
3471
        table => 'book',
3472
        where => {id => 1},
3473
        select_option => {append => 'for update'}
3474
    );
3475
    
3476
    # ID
3477
    $dbi->update_or_insert(
3478
        {title => 'Perl'},
3479
        table => 'book',
3480
        id => 1,
3481
        primary_key => 'id',
3482
        select_option => {append => 'for update'}
3483
    );
3484
    
3485
Update or insert.
3486

            
3487
In both examples, the following SQL is executed.
3488

            
3489
    # In case insert
3490
    insert into book (id, title) values (?, ?)
3491
    
3492
    # In case update
3493
    update book set (id = ?, title = ?) where book.id = ?
3494

            
3495
The following opitons are available adding to C<update> option.
3496

            
3497
=over 4
3498

            
3499
=item C<select_option>
3500

            
3501
    select_option => {append => 'for update'}
3502

            
3503
select method option,
3504
select method is used to check the row is already exists.
3505

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3508
    $dbi->update_timestamp(
3509
      updated_at
3510
        => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
cleanup
Yuki Kimoto authored on 2011-03-09
3511
    );
fix tests
Yuki Kimoto authored on 2011-01-18
3512

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3513
Timestamp value when C<update> method is executed
3514
with C<timestamp> option.
cleanup
Yuki Kimoto authored on 2011-01-12
3515

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3516
If C<insert_timestamp> is set and C<insert> method is executed
3517
with C<timestamp> option, column C<update_at>
3518
is automatically set to the value like "2010-10-11 10:12:54".
cleanup
Yuki Kimoto authored on 2011-01-12
3519

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3520
>|perl|
3521
$dbi->update($param, table => 'book', timestamp => 1);
3522
||<
cleanup
Yuki Kimoto authored on 2011-01-12
3523

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

            
3526
    $dbi->show_datatype($table);
3527

            
3528
Show data type of the columns of specified table.
3529

            
3530
    book
3531
    title: 5
3532
    issue_date: 91
3533

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

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

            
3538
    $dbi->show_tables;
3539

            
3540
Show tables.
3541

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

            
3544
    $dbi->show_typename($table);
3545

            
3546
Show type name of the columns of specified table.
3547

            
3548
    book
3549
    title: varchar
3550
    issue_date: date
3551

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3554
=head2 C<values_clause>
3555

            
3556
    my $values_clause = $dbi->values_clause({title => 'a', age => 2});
3557

            
3558
Create values clause.
3559

            
3560
    (title, author) values (title = :title, age = :age);
3561

            
3562
You can use this in insert statement.
3563

            
3564
    my $insert_sql = "insert into book $values_clause";
3565

            
3566
=head2 C<where>
3567

            
3568
    my $where = $dbi->where(
3569
        clause => ['and', 'title = :title', 'author = :author'],
3570
        param => {title => 'Perl', author => 'Ken'}
3571
    );
3572

            
3573
Create a new L<DBIx::Custom::Where> object.
3574

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

            
3577
=head2 C<DBIX_CUSTOM_DEBUG>
3578

            
3579
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3580
executed SQL and bind values are printed to STDERR.
3581

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

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

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

            
3588
L<DBIx::Custom>
3589

            
3590
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3591
    default_dbi_option # will be removed 2017/1/1
3592
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3593
    data_source # will be removed at 2017/1/1
3594
    dbi_options # will be removed at 2017/1/1
3595
    filter_check # will be removed at 2017/1/1
3596
    reserved_word_quote # will be removed at 2017/1/1
3597
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3598
    
3599
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3600
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3601
    assign_param # will be removed at 2017/1/1
3602
    update_param # will be removed at 2017/1/1
3603
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3604
    create_query # will be removed at 2017/1/1
3605
    apply_filter # will be removed at 2017/1/1
3606
    select_at # will be removed at 2017/1/1
3607
    delete_at # will be removed at 2017/1/1
3608
    update_at # will be removed at 2017/1/1
3609
    insert_at # will be removed at 2017/1/1
3610
    register_tag # will be removed at 2017/1/1
3611
    default_bind_filter # will be removed at 2017/1/1
3612
    default_fetch_filter # will be removed at 2017/1/1
3613
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3614
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3615
    register_tag_processor # will be removed at 2017/1/1
3616
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3617
    
3618
    # Options
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3619
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3620
    select method relation option # will be removed at 2017/1/1
3621
    select method param option # will be removed at 2017/1/1
3622
    select method column option [COLUMN, as => ALIAS] format
3623
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3624
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3625
    
3626
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3627
    execute("select * from {= title}"); # execute method's
3628
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3629
                                        # will be removed at 2017/1/1
3630
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3631

            
3632
L<DBIx::Custom::Model>
3633

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3634
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3635
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3636
    filter # will be removed at 2017/1/1
3637
    name # will be removed at 2017/1/1
3638
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3639

            
3640
L<DBIx::Custom::Query>
3641
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3642
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3643
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3644
    table # will be removed at 2017/1/1
3645
    filters # will be removed at 2017/1/1
3646
    
3647
    # Methods
3648
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3649

            
3650
L<DBIx::Custom::QueryBuilder>
3651
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3652
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3653
    tags # will be removed at 2017/1/1
3654
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3655
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3656
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3657
    register_tag # will be removed at 2017/1/1
3658
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3659
    
3660
    # Others
3661
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3662
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3663

            
3664
L<DBIx::Custom::Result>
3665
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3666
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3667
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3668
    
3669
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3670
    end_filter # will be removed at 2017/1/1
3671
    remove_end_filter # will be removed at 2017/1/1
3672
    remove_filter # will be removed at 2017/1/1
3673
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3674

            
3675
L<DBIx::Custom::Tag>
3676

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

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

            
3681
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3682
except for attribute method.
3683
You can check all DEPRECATED functionalities by document.
3684
DEPRECATED functionality is removed after five years,
3685
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
3686
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3687

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

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

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

            
3694
C<< <kimoto.yuki at gmail.com> >>
3695

            
3696
L<http://github.com/yuki-kimoto/DBIx-Custom>
3697

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3698
=head1 AUTHOR
3699

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

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

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

            
3706
This program is free software; you can redistribute it and/or modify it
3707
under the same terms as Perl itself.
3708

            
3709
=cut