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

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
4
our $VERSION = '0.1730';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
659
sub insert_timestamp {
660
    my $self = shift;
661
    
662
    if (@_) {
663
        $self->{insert_timestamp} = [@_];
664
        
665
        return $self;
666
    }
667
    return $self->{insert_timestamp};
668
}
669

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
670
sub include_model {
671
    my ($self, $name_space, $model_infos) = @_;
672
    
cleanup
Yuki Kimoto authored on 2011-04-02
673
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
674
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
675
    
676
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
677
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
678

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
737
sub mapper {
738
    my $self = shift;
739
    return DBIx::Custom::Mapper->new(@_);
740
}
741

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
742
sub merge_param {
743
    my ($self, @params) = @_;
744
    
cleanup
Yuki Kimoto authored on 2011-04-02
745
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
746
    my $merge = {};
747
    foreach my $param (@params) {
748
        foreach my $column (keys %$param) {
749
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
750
            
751
            if (exists $merge->{$column}) {
752
                $merge->{$column} = [$merge->{$column}]
753
                  unless ref $merge->{$column} eq 'ARRAY';
754
                push @{$merge->{$column}},
755
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
756
            }
757
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
758
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
759
            }
760
        }
761
    }
762
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
763
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
764
}
765

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
766
sub model {
767
    my ($self, $name, $model) = @_;
768
    
cleanup
Yuki Kimoto authored on 2011-04-02
769
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
770
    if ($model) {
771
        $self->models->{$name} = $model;
772
        return $self;
773
    }
774
    
775
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
776
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
777
      unless $self->models->{$name};
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
780
    return $self->models->{$name};
781
}
782

            
cleanup
Yuki Kimoto authored on 2011-03-21
783
sub mycolumn {
784
    my ($self, $table, $columns) = @_;
785
    
cleanup
Yuki Kimoto authored on 2011-04-02
786
    # Create column clause
787
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
788
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
789
    push @column, $self->_q($table) . "." . $self->_q($_) .
790
      " as " . $self->_q($_)
791
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
792
    
793
    return join (', ', @column);
794
}
795

            
added dbi_options attribute
kimoto authored on 2010-12-20
796
sub new {
797
    my $self = shift->SUPER::new(@_);
798
    
cleanup
Yuki Kimoto authored on 2011-04-02
799
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
800
    my @attrs = keys %$self;
801
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
802
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
803
          unless $self->can($attr);
804
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
805

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
806
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
807
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
808
        '?'     => \&DBIx::Custom::Tag::placeholder,
809
        '='     => \&DBIx::Custom::Tag::equal,
810
        '<>'    => \&DBIx::Custom::Tag::not_equal,
811
        '>'     => \&DBIx::Custom::Tag::greater_than,
812
        '<'     => \&DBIx::Custom::Tag::lower_than,
813
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
814
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
815
        'like'  => \&DBIx::Custom::Tag::like,
816
        'in'    => \&DBIx::Custom::Tag::in,
817
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
818
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
819
    };
820
    
821
    return $self;
822
}
823

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

            
826
sub order {
827
    my $self = shift;
828
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
829
}
830

            
cleanup
yuki-kimoto authored on 2010-10-17
831
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
832
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
833
    
834
    # Register filter
835
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
836
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
837
    
cleanup
Yuki Kimoto authored on 2011-04-02
838
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
839
}
packaging one directory
yuki-kimoto authored on 2009-11-16
840

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
918
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
919
    unshift @$tables,
920
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
921
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
922
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
923
    my $where_clause = '';
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
924
    $where = $self->_create_param_from_id($id, $primary_key, $tables->[-1])
925
      if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
926
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
927
        $where_clause = "where " . $where->[0];
928
        $where_param = $where->[1];
929
    }
930
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
931
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
932
        $where_param = keys %$where_param
933
                     ? $self->merge_param($where_param, $where->param)
934
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
935
        
936
        # String where
937
        $where_clause = $where->to_string;
938
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
939
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
940
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
941
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
942
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
943
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
944
    # Push join
micro optimization
Yuki Kimoto authored on 2011-09-30
945
    $self->_push_join(\$sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
946
    
cleanup
Yuki Kimoto authored on 2011-03-09
947
    # Add where clause
micro optimization
Yuki Kimoto authored on 2011-09-30
948
    $sql .= "$where_clause ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
949
    
cleanup
Yuki Kimoto authored on 2011-03-08
950
    # Relation(DEPRECATED!);
micro optimization
Yuki Kimoto authored on 2011-09-30
951
    $self->_push_relation(\$sql, $tables, $relation, $where_clause eq '' ? 1 : 0)
952
      if $relation;
cleanup
Yuki Kimoto authored on 2011-03-08
953
    
cleanup
Yuki Kimoto authored on 2011-04-02
954
    # Append
micro optimization
Yuki Kimoto authored on 2011-09-30
955
    $sql .= $append if defined $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
956
    
957
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
958
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
959
    
960
    return $result;
961
}
962

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
963
sub setup_model {
964
    my $self = shift;
965
    
cleanup
Yuki Kimoto authored on 2011-04-02
966
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
967
    $self->each_column(
968
        sub {
969
            my ($self, $table, $column, $column_info) = @_;
970
            if (my $model = $self->models->{$table}) {
971
                push @{$model->columns}, $column;
972
            }
973
        }
974
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
975
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
976
}
977

            
update pod
Yuki Kimoto authored on 2011-08-10
978
sub show_datatype {
979
    my ($self, $table) = @_;
980
    croak "Table name must be specified" unless defined $table;
981
    print "$table\n";
982
    
983
    my $result = $self->select(table => $table, where => "'0' <> '0'");
984
    my $sth = $result->sth;
985

            
986
    my $columns = $sth->{NAME};
987
    my $data_types = $sth->{TYPE};
988
    
989
    for (my $i = 0; $i < @$columns; $i++) {
990
        my $column = $columns->[$i];
991
        my $data_type = $data_types->[$i];
992
        print "$column: $data_type\n";
993
    }
994
}
995

            
996
sub show_typename {
997
    my ($self, $t) = @_;
998
    croak "Table name must be specified" unless defined $t;
999
    print "$t\n";
1000
    
1001
    $self->each_column(sub {
1002
        my ($self, $table, $column, $infos) = @_;
1003
        return unless $table eq $t;
1004
        my $typename = $infos->{TYPE_NAME};
1005
        print "$column: $typename\n";
1006
    });
1007
    
1008
    return $self;
1009
}
1010

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1011
sub show_tables {
1012
    my $self = shift;
1013
    
1014
    my %tables;
1015
    $self->each_table(sub { $tables{$_[1]}++ });
1016
    print join("\n", sort keys %tables) . "\n";
1017
    return $self;
1018
}
1019

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1020
sub type_rule {
1021
    my $self = shift;
1022
    
1023
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1024
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1025
        
1026
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1027
        foreach my $i (1 .. 2) {
1028
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1029
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1030
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1031
            $self->{type_rule} = $type_rule;
1032
            $self->{"_$into"} = {};
1033
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1034
                croak qq{type name of $into section must be lower case}
1035
                  if $type_name =~ /[A-Z]/;
1036
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1037
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1038
            $self->each_column(sub {
1039
                my ($dbi, $table, $column, $column_info) = @_;
1040
                
1041
                my $type_name = lc $column_info->{TYPE_NAME};
1042
                if ($type_rule->{$into} &&
1043
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1044
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1045
                    return unless exists $type_rule->{$into}->{$type_name};
1046
                    if  (defined $filter && ref $filter ne 'CODE') 
1047
                    {
1048
                        my $fname = $filter;
1049
                        croak qq{Filter "$fname" is not registered" } . _subname
1050
                          unless exists $self->filters->{$fname};
1051
                        
1052
                        $filter = $self->filters->{$fname};
1053
                    }
1054

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1055
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1056
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1057
                }
1058
            });
1059
        }
1060

            
1061
        # From
1062
        foreach my $i (1 .. 2) {
1063
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1064
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1065
                croak qq{data type of from$i section must be lower case or number}
1066
                  if $data_type =~ /[A-Z]/;
1067
                my $fname = $type_rule->{"from$i"}{$data_type};
1068
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1069
                    croak qq{Filter "$fname" is not registered" } . _subname
1070
                      unless exists $self->filters->{$fname};
1071
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1072
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1073
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1074
            }
1075
        }
1076
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1077
        return $self;
1078
    }
1079
    
1080
    return $self->{type_rule} || {};
1081
}
1082

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1086
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1087
    my $param;
1088
    $param = shift if @_ % 2;
1089
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1090
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1091
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1092
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1093
    my $p = delete $args{param} || {};
1094
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1095
    my $where = delete $args{where} || {};
1096
    my $where_param = delete $args{where_param} || {};
1097
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1098
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1099
    my $id = delete $args{id};
1100
    my $primary_key = delete $args{primary_key};
1101
    croak "update method primary_key option " .
1102
          "must be specified when id is specified " . _subname
1103
      if defined $id && !defined $primary_key;
1104
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1105
    my $prefix = delete $args{prefix};
updated pod
Yuki Kimoto authored on 2011-09-02
1106
    my $wrap = delete $args{wrap};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1107
    my $timestamp = $args{timestamp};
1108
    
1109
    # Timestamp
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1110
    if ($timestamp && (my $update_timestamp = $self->update_timestamp)) {
1111
        my $columns = $update_timestamp->[0];
1112
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1113
        my $value = $update_timestamp->[1];
1114
        $value = $value->() if ref $value eq 'CODE';
1115
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1116
    }
1117

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

            
1121
    # Where
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1122
    $where = $self->_create_param_from_id($id, $primary_key, $table)
1123
      if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1124
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1125
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1126
        $where_clause = "where " . $where->[0];
1127
        $where_param = $where->[1];
1128
    }
1129
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1130
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1131
        $where_param = keys %$where_param
1132
                     ? $self->merge_param($where_param, $where->param)
1133
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1134
        
1135
        # String where
1136
        $where_clause = $where->to_string;
1137
    }
1138
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1139
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1140
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1141
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1142
    # Merge param
1143
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1144
    
cleanup
Yuki Kimoto authored on 2011-04-02
1145
    # Update statement
micro optimization
Yuki Kimoto authored on 2011-09-30
1146
    my $sql;
1147
    $sql .= "update ";
1148
    $sql .= "$prefix " if defined $prefix;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1149
    $sql .= $self->_q($table) . " set $assign_clause $where_clause ";
micro optimization
Yuki Kimoto authored on 2011-09-30
1150
    $sql .= $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
1151
    
cleanup
yuki-kimoto authored on 2010-10-17
1152
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1153
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1154
}
1155

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1158
sub update_timestamp {
1159
    my $self = shift;
1160
    
1161
    if (@_) {
1162
        $self->{update_timestamp} = [@_];
1163
        
1164
        return $self;
1165
    }
1166
    return $self->{update_timestamp};
1167
}
1168

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1169
sub values_clause {
1170
    my ($self, $param, $opts) = @_;
1171
    
1172
    my $wrap = $opts->{wrap} || {};
1173
    
1174
    # Create insert parameter tag
1175
    my $safety = $self->safety_character;
1176
    my @columns;
1177
    my @placeholders;
1178
    foreach my $column (sort keys %$param) {
1179
        croak qq{"$column" is not safety column name } . _subname
1180
          unless $column =~ /^[$safety\.]+$/;
1181
        my $column_quote = $self->_q($column);
1182
        $column_quote =~ s/\./$self->_q(".")/e;
1183
        push @columns, $column_quote;
1184
        
1185
        my $func = $wrap->{$column} || sub { $_[0] };
1186
        push @placeholders,
1187
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1188
        : $func->(":$column");
1189
    }
1190
    
1191
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1192
           '(' . join(', ', @placeholders) . ')'
1193
}
1194

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

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

            
1223
        # Create query
1224
        my $builder = $self->query_builder;
1225
        $query = $builder->build_query($source);
1226

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

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

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

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1399
sub _need_tables {
1400
    my ($self, $tree, $need_tables, $tables) = @_;
1401
    
cleanup
Yuki Kimoto authored on 2011-04-02
1402
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1403
    foreach my $table (@$tables) {
1404
        if ($tree->{$table}) {
1405
            $need_tables->{$table} = 1;
1406
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1407
        }
1408
    }
1409
}
1410

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1411
sub _option {
1412
    my $self = shift;
1413
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1414
    warn "dbi_options is DEPRECATED! use option instead\n"
1415
      if keys %{$self->dbi_options};
1416
    warn "dbi_option is DEPRECATED! use option instead\n"
1417
      if keys %{$self->dbi_option};
1418
    return $option;
1419
}
1420

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1491
sub _quote {
1492
    my $self = shift;
1493
    
1494
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1495
         : defined $self->quote ? $self->quote
1496
         : '';
1497
}
1498

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

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

            
1531
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1532
}
1533

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1670
# DEPRECATED!
1671
has 'data_source';
1672
has dbi_options => sub { {} };
1673
has filter_check  => 1;
1674
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1675
has dbi_option => sub { {} };
1676
has default_dbi_option => sub {
1677
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1678
    return shift->default_option;
1679
};
1680

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1681
# DEPRECATED!
1682
sub method {
1683
    warn "method is DEPRECATED! use helper instead";
1684
    return shift->helper(@_);
1685
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1686

            
1687
# DEPRECATED!
1688
sub assign_param {
1689
    my $self = shift;
1690
    warn "assing_param is DEPRECATED! use assign_clause instead";
1691
    return $self->assign_clause(@_);
1692
}
1693

            
1694
# DEPRECATED
1695
sub update_param {
1696
    my ($self, $param, $opts) = @_;
1697
    
1698
    warn "update_param is DEPRECATED! use assing_clause instead.";
1699
    
1700
    # Create update parameter tag
1701
    my $tag = $self->assign_clause($param, $opts);
1702
    $tag = "set $tag" unless $opts->{no_set};
1703

            
1704
    return $tag;
1705
}
1706

            
updated pod
Yuki Kimoto authored on 2011-06-21
1707
# DEPRECATED!
1708
sub create_query {
1709
    warn "create_query is DEPRECATED! use query option of each method";
1710
    shift->_create_query(@_);
1711
}
1712

            
cleanup
Yuki Kimoto authored on 2011-06-13
1713
# DEPRECATED!
1714
sub apply_filter {
1715
    my $self = shift;
1716
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1717
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1718
    return $self->_apply_filter(@_);
1719
}
1720

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1728
    # Arguments
1729
    my $primary_keys = delete $args{primary_key};
1730
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1731
    my $where = delete $args{where};
1732
    my $param = delete $args{param};
1733
    
1734
    # Check arguments
1735
    foreach my $name (keys %args) {
1736
        croak qq{"$name" is wrong option } . _subname
1737
          unless $SELECT_AT_ARGS{$name};
1738
    }
1739
    
1740
    # Table
1741
    croak qq{"table" option must be specified } . _subname
1742
      unless $args{table};
1743
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1744
    
1745
    # Create where parameter
1746
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1747
    
1748
    return $self->select(where => $where_param, %args);
1749
}
1750

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

            
1756
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1757
    
1758
    # Arguments
1759
    my $primary_keys = delete $args{primary_key};
1760
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1761
    my $where = delete $args{where};
1762
    
1763
    # Check arguments
1764
    foreach my $name (keys %args) {
1765
        croak qq{"$name" is wrong option } . _subname
1766
          unless $DELETE_AT_ARGS{$name};
1767
    }
1768
    
1769
    # Create where parameter
1770
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1771
    
1772
    return $self->delete(where => $where_param, %args);
1773
}
1774

            
cleanup
Yuki Kimoto authored on 2011-06-08
1775
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1776
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1777
sub update_at {
1778
    my $self = shift;
1779

            
1780
    warn "update_at is DEPRECATED! use update and id option instead";
1781
    
1782
    # Arguments
1783
    my $param;
1784
    $param = shift if @_ % 2;
1785
    my %args = @_;
1786
    my $primary_keys = delete $args{primary_key};
1787
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1788
    my $where = delete $args{where};
1789
    my $p = delete $args{param} || {};
1790
    $param  ||= $p;
1791
    
1792
    # Check arguments
1793
    foreach my $name (keys %args) {
1794
        croak qq{"$name" is wrong option } . _subname
1795
          unless $UPDATE_AT_ARGS{$name};
1796
    }
1797
    
1798
    # Create where parameter
1799
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1800
    
1801
    return $self->update(where => $where_param, param => $param, %args);
1802
}
1803

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1804
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1805
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1806
sub insert_at {
1807
    my $self = shift;
1808
    
1809
    warn "insert_at is DEPRECATED! use insert and id option instead";
1810
    
1811
    # Arguments
1812
    my $param;
1813
    $param = shift if @_ % 2;
1814
    my %args = @_;
1815
    my $primary_key = delete $args{primary_key};
1816
    $primary_key = [$primary_key] unless ref $primary_key;
1817
    my $where = delete $args{where};
1818
    my $p = delete $args{param} || {};
1819
    $param  ||= $p;
1820
    
1821
    # Check arguments
1822
    foreach my $name (keys %args) {
1823
        croak qq{"$name" is wrong option } . _subname
1824
          unless $INSERT_AT_ARGS{$name};
1825
    }
1826
    
1827
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1828
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1829
    $param = $self->merge_param($where_param, $param);
1830
    
1831
    return $self->insert(param => $param, %args);
1832
}
1833

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

            
1847
# DEPRECATED!
1848
sub register_tag_processor {
1849
    my $self = shift;
1850
    warn "register_tag_processor is DEPRECATED!";
1851
    # Merge tag
1852
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1853
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1854
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1855
}
1856

            
cleanup
Yuki Kimoto authored on 2011-01-25
1857
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1858
sub default_bind_filter {
1859
    my $self = shift;
1860
    
cleanup
Yuki Kimoto authored on 2011-06-13
1861
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1862
    
cleanup
Yuki Kimoto authored on 2011-01-12
1863
    if (@_) {
1864
        my $fname = $_[0];
1865
        
1866
        if (@_ && !$fname) {
1867
            $self->{default_out_filter} = undef;
1868
        }
1869
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1870
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1871
              unless exists $self->filters->{$fname};
1872
        
1873
            $self->{default_out_filter} = $self->filters->{$fname};
1874
        }
1875
        return $self;
1876
    }
1877
    
1878
    return $self->{default_out_filter};
1879
}
1880

            
cleanup
Yuki Kimoto authored on 2011-01-25
1881
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1882
sub default_fetch_filter {
1883
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1884

            
cleanup
Yuki Kimoto authored on 2011-06-13
1885
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1886
    
1887
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1888
        my $fname = $_[0];
1889

            
cleanup
Yuki Kimoto authored on 2011-01-12
1890
        if (@_ && !$fname) {
1891
            $self->{default_in_filter} = undef;
1892
        }
1893
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1894
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1895
              unless exists $self->filters->{$fname};
1896
        
1897
            $self->{default_in_filter} = $self->filters->{$fname};
1898
        }
1899
        
1900
        return $self;
1901
    }
1902
    
many changed
Yuki Kimoto authored on 2011-01-23
1903
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1904
}
1905

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1906
# DEPRECATED!
1907
sub insert_param {
1908
    my $self = shift;
1909
    warn "insert_param is DEPRECATED! use values_clause instead";
1910
    return $self->values_clause(@_);
1911
}
1912

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1913
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1914
sub insert_param_tag {
1915
    warn "insert_param_tag is DEPRECATED! " .
1916
         "use insert_param instead!";
1917
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1918
}
1919

            
1920
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1921
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1922
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1923
         "use update_param instead";
1924
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1925
}
cleanup
Yuki Kimoto authored on 2011-03-08
1926
# DEPRECATED!
1927
sub _push_relation {
1928
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1929
    
1930
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1931
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1932
        foreach my $rcolumn (keys %$relation) {
1933
            my $table1 = (split (/\./, $rcolumn))[0];
1934
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1935
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1936
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1937
        }
1938
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1939
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1940
}
1941

            
1942
# DEPRECATED!
1943
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1944
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1945
    
1946
    if (keys %{$relation || {}}) {
1947
        foreach my $rcolumn (keys %$relation) {
1948
            my $table1 = (split (/\./, $rcolumn))[0];
1949
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1950
            my $table1_exists;
1951
            my $table2_exists;
1952
            foreach my $table (@$tables) {
1953
                $table1_exists = 1 if $table eq $table1;
1954
                $table2_exists = 1 if $table eq $table2;
1955
            }
1956
            unshift @$tables, $table1 unless $table1_exists;
1957
            unshift @$tables, $table2 unless $table2_exists;
1958
        }
1959
    }
1960
}
1961

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1964
=head1 NAME
1965

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1970
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1971
    
1972
    # Connect
1973
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1974
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1975
        user => 'ken',
1976
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1977
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1978
    );
cleanup
yuki-kimoto authored on 2010-08-05
1979

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1980
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1981
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1982
    
1983
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1984
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1985
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1986
    
1987
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1988
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1989

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2039
Named place holder support
2040

            
2041
=item *
2042

            
cleanup
Yuki Kimoto authored on 2011-07-29
2043
Model support
2044

            
2045
=item *
2046

            
2047
Connection manager support
2048

            
2049
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2050

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

            
2055
=item *
2056

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

            
2059
=item *
2060

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

            
2063
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2064

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2072
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2073
L<DBIx::Custom::Result>,
2074
L<DBIx::Custom::Query>,
2075
L<DBIx::Custom::Where>,
2076
L<DBIx::Custom::Model>,
2077
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2078

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

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

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

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

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

            
2092
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2093
        "dbi:mysql:database=$database",
2094
        $user,
2095
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2096
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2097
    );
2098
    
updated pod
Yuki Kimoto authored on 2011-06-21
2099
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2100

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

            
2104
    my $dbi = DBIx::Custom->connect(
2105
      dsn => $dsn, user => $user, password => $password, connector => 1);
2106
    
2107
    my $connector = $dbi->connector; # DBIx::Connector
2108

            
2109
Note that L<DBIx::Connector> must be installed.
2110

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

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

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

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2134
    {
2135
        RaiseError => 1,
2136
        PrintError => 0,
2137
        AutoCommit => 1,
2138
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2139

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

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

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

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

            
2149
    my $last_sql = $dbi->last_sql;
2150
    $dbi = $dbi->last_sql($last_sql);
2151

            
2152
Get last successed SQL executed by C<execute> method.
2153

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2161
=head2 C<password>
2162

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2183
You can set quote pair.
2184

            
2185
    $dbi->quote('[]');
2186

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2196
    my $safety_character = $dbi->safety_character;
2197
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2198

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

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

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

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

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

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

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

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

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

            
2224
    my $tag_parse = $dbi->tag_parse(0);
2225
    $dbi = $dbi->tag_parse;
2226

            
2227
Enable DEPRECATED tag parsing functionality, default to 1.
2228
If you want to disable tag parsing functionality, set to 0.
2229

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

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

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

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

            
2239
    my $user_column_info = $dbi->user_column_info;
2240
    $dbi = $dbi->user_column_info($user_column_info);
2241

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

            
2244
    [
2245
        {table => 'book', column => 'title', info => {...}},
2246
        {table => 'author', column => 'name', info => {...}}
2247
    ]
2248

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

            
2251
    my $user_column_info
2252
      = $dbi->get_column_info(exclude_table => qr/^system/);
2253
    $dbi->user_column_info($user_column_info);
2254

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

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

            
2260
    my $user_table_info = $dbi->user_table_info;
2261
    $dbi = $dbi->user_table_info($user_table_info);
2262

            
2263
You can set the following data.
2264

            
2265
    [
2266
        {table => 'book', info => {...}},
2267
        {table => 'author', info => {...}}
2268
    ]
2269

            
2270
Usually, you can set return value of C<get_table_info>.
2271

            
2272
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2273
    $dbi->user_table_info($user_table_info);
2274

            
2275
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2276
to find table info.
2277

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2314
Create column clause. The follwoing column clause is created.
2315

            
2316
    book.author as "book.author",
2317
    book.title as "book.title"
2318

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2321
    # Separator is hyphen
2322
    $dbi->separator('-');
2323
    
2324
    book.author as "book-author",
2325
    book.title as "book-title"
2326
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2327
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2328

            
update pod
Yuki Kimoto authored on 2011-03-13
2329
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2330
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2331
        user => 'ken',
2332
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2333
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2334
    );
2335

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

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

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

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

            
2346
Get rows count.
2347

            
2348
Options is same as C<select> method's ones.
2349

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2352
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2353
        table => 'book',
2354
        primary_key => 'id',
2355
        join => [
2356
            'inner join company on book.comparny_id = company.id'
2357
        ],
2358
    );
2359

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

            
2363
   $dbi->model('book')->select(...);
2364

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

            
2367
    my $dbh = $dbi->dbh;
2368

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

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

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

            
2376
Execute delete statement.
2377

            
2378
The following opitons are available.
2379

            
2380
=over 4
2381

            
2382
=item C<append>
2383

            
2384
Same as C<select> method's C<append> option.
2385

            
2386
=item C<filter>
2387

            
2388
Same as C<execute> method's C<filter> option.
2389

            
2390
=item C<id>
2391

            
2392
    id => 4
2393
    id => [4, 5]
2394

            
2395
ID corresponding to C<primary_key>.
2396
You can delete rows by C<id> and C<primary_key>.
2397

            
2398
    $dbi->delete(
2399
        parimary_key => ['id1', 'id2'],
2400
        id => [4, 5],
2401
        table => 'book',
2402
    );
2403

            
2404
The above is same as the followin one.
2405

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

            
2408
=item C<prefix>
2409

            
2410
    prefix => 'some'
2411

            
2412
prefix before table name section.
2413

            
2414
    delete some from book
2415

            
2416
=item C<query>
2417

            
2418
Same as C<execute> method's C<query> option.
2419

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

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

            
2424
=item C<table>
2425

            
2426
    table => 'book'
2427

            
2428
Table name.
2429

            
2430
=item C<where>
2431

            
2432
Same as C<select> method's C<where> option.
2433

            
2434
=item C<primary_key>
2435

            
2436
See C<id> option.
2437

            
2438
=item C<bind_type>
2439

            
2440
Same as C<execute> method's C<bind_type> option.
2441

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

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

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

            
2448
    type_rule1_off => 1
2449

            
2450
Same as C<execute> method's C<type_rule1_off> option.
2451

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

            
2454
    type_rule2_off => 1
2455

            
2456
Same as C<execute> method's C<type_rule2_off> option.
2457

            
2458
=back
2459

            
2460
=head2 C<delete_all>
2461

            
2462
    $dbi->delete_all(table => $table);
2463

            
2464
Execute delete statement for all rows.
2465
Options is same as C<delete>.
2466

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

            
2469
    $dbi->each_column(
2470
        sub {
2471
            my ($dbi, $table, $column, $column_info) = @_;
2472
            
2473
            my $type = $column_info->{TYPE_NAME};
2474
            
2475
            if ($type eq 'DATE') {
2476
                # ...
2477
            }
2478
        }
2479
    );
2480

            
2481
Iterate all column informations of all table from database.
2482
Argument is callback when one column is found.
2483
Callback receive four arguments, dbi object, table name,
2484
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2485

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

            
2488
    $dbi->each_table(
2489
        sub {
2490
            my ($dbi, $table, $table_info) = @_;
2491
            
2492
            my $table_name = $table_info->{TABLE_NAME};
2493
        }
2494
    );
2495

            
2496
Iterate all table informationsfrom database.
2497
Argument is callback when one table is found.
2498
Callback receive three arguments, dbi object, table name,
2499
table information.
2500

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

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

            
2508
    my $result = $dbi->execute(
2509
      "select * from book where title = :book.title and author like :book.author",
2510
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2511
    );
2512

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2519
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2520
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2521
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2522
    select * from book where title = :title and author like :author
2523
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2524
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2525
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2526

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2530
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2531
    select * from book where :title{=} and :author{like}
2532
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2533
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2534
    select * from where title = ? and author like ?;
2535

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

            
2540
    select * from where title = "aa\\:bb";
2541

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

            
2544
=over 4
2545

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

            
2548
Specify database bind data type.
2549

            
2550
    bind_type => [image => DBI::SQL_BLOB]
2551
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2552

            
2553
This is used to bind parameter by C<bind_param> of statment handle.
2554

            
2555
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2556

            
update pod
Yuki Kimoto authored on 2011-03-13
2557
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2558
    
2559
    filter => {
2560
        title  => sub { uc $_[0] }
2561
        author => sub { uc $_[0] }
2562
    }
update pod
Yuki Kimoto authored on 2011-03-13
2563

            
updated pod
Yuki Kimoto authored on 2011-06-09
2564
    # Filter name
2565
    filter => {
2566
        title  => 'upper_case',
2567
        author => 'upper_case'
2568
    }
2569
        
2570
    # At once
2571
    filter => [
2572
        [qw/title author/]  => sub { uc $_[0] }
2573
    ]
2574

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

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

            
2582
    id => 4
2583
    id => [4, 5]
2584

            
2585
ID corresponding to C<primary_key>.
2586
You can delete rows by C<id> and C<primary_key>.
2587

            
2588
    $dbi->execute(
2589
        "select * from book where id1 = :id1 and id2 = :id2",
2590
        {},
2591
        parimary_key => ['id1', 'id2'],
2592
        id => [4, 5],
2593
    );
2594

            
2595
The above is same as the followin one.
2596

            
2597
    $dbi->execute(
2598
        "select * from book where id1 = :id1 and id2 = :id2",
2599
        {id1 => 4, id2 => 5}
2600
    );
2601

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

            
2604
    query => 1
2605

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

            
2609
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2610
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2611
    my $columns = $query->columns;
2612
    
2613
If you want to execute SQL fast, you can do the following way.
2614

            
2615
    my $query;
2616
    foreach my $row (@$rows) {
2617
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2618
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2619
    }
2620

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

            
2624
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
2625
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2626
    
2627
    my $query;
2628
    my $sth;
2629
    foreach my $row (@$rows) {
2630
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2631
      $sth ||= $query->sth;
2632
      $sth->execute(map { $row->{$_} } sort keys %$row);
2633
    }
2634

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

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

            
2641
See C<id> option.
2642

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

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

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

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

            
2651
    $dbi->select(
2652
        table => 'book',
2653
        column => 'distinct(name)',
2654
        after_build_sql => sub {
2655
            "select count(*) from ($_[0]) as t1"
2656
        }
2657
    );
2658

            
2659
The following SQL is executed.
2660

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2663
=item C<table>
2664
    
2665
    table => 'author'
2666

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2674
    # Same
2675
    $dbi->execute(
2676
      "select * from book where title = :book.title and author = :book.author",
2677
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2678

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

            
2681
    table_alias => {user => 'hiker'}
2682

            
2683
Table alias. Key is real table name, value is alias table name.
2684
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2685
on alias table name.
2686

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

            
2689
    type_rule_off => 1
2690

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

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

            
2695
    type_rule1_off => 1
2696

            
2697
Turn C<into1> type rule off.
2698

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

            
2701
    type_rule2_off => 1
2702

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

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

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

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

            
2711
get column infomation except for one which match C<exclude_table> pattern.
2712

            
2713
    [
2714
        {table => 'book', column => 'title', info => {...}},
2715
        {table => 'author', column => 'name' info => {...}}
2716
    ]
2717

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

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

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

            
2724
    [
2725
        {table => 'book', info => {...}},
2726
        {table => 'author', info => {...}}
2727
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2728

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2731
=head2 C<insert>
2732

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

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

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

            
2741
    {date => \"NOW()"}
2742

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

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

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

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

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

            
2753
Same as C<execute> method's C<bind_type> option.
2754

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

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

            
2759
=item C<id>
2760

            
updated document
Yuki Kimoto authored on 2011-06-09
2761
    id => 4
2762
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2763

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2767
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2768
        {title => 'Perl', author => 'Ken'}
2769
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2770
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2771
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2772
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2773

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

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

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

            
2783
    prefix => 'or replace'
2784

            
2785
prefix before table name section
2786

            
2787
    insert or replace into book
2788

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

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

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

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

            
2798
Same as C<execute> method's C<query> option.
2799

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

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

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

            
2806
    table => 'book'
2807

            
2808
Table name.
2809

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

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

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

            
2816
    timestamp => 1
2817

            
2818
If this value is set to 1,
2819
automatically created timestamp column is set based on
2820
C<timestamp> attribute's C<insert> value.
2821

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

            
2824
    type_rule1_off => 1
2825

            
2826
Same as C<execute> method's C<type_rule1_off> option.
2827

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

            
2830
    type_rule2_off => 1
2831

            
2832
Same as C<execute> method's C<type_rule2_off> option.
2833

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

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

            
2838
placeholder wrapped string.
2839

            
2840
If the following statement
2841

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

            
2845
is executed, the following SQL is executed.
2846

            
2847
    insert into book price values ( ? + 5 );
2848

            
update pod
Yuki Kimoto authored on 2011-03-13
2849
=back
2850

            
2851
=over 4
2852

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2868
    lib / MyModel.pm
2869
        / MyModel / book.pm
2870
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2871

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

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

            
2876
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2877
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2878
    
2879
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2880

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2885
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2886
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2887
    
2888
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2889

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2892
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2893
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2894
    
2895
    1;
2896
    
updated pod
Yuki Kimoto authored on 2011-06-21
2897
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2898

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

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

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

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

            
2908
    $dbi->insert_timestamp(
2909
      [qw/created_at updated_at/] => sub { localtime });
2910

            
2911
Parameter for timestamp columns when C<insert> method is executed
2912
with C<timestamp> option.
2913

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

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

            
2918
    my $like_value = $dbi->like_value
2919

            
2920
Constant code reference for the like value.
2921

            
2922
    sub { "%$_[0]%" }
2923

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

            
2926
    my $mapper = $dbi->mapper(param => $param);
2927

            
2928
Create a new L<DBIx::Custom::Mapper> object.
2929

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

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

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

            
2936
    {key1 => [1, 1], key2 => 2}
2937

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
2938
=head2 C<helper>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2939

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
2940
    $dbi->helper(
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2941
        update_or_insert => sub {
2942
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2943
            
2944
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2945
        },
2946
        find_or_create   => sub {
2947
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2948
            
2949
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2950
        }
2951
    );
2952

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
2953
Register helper. These helper is called directly from L<DBIx::Custom> object.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2954

            
2955
    $dbi->update_or_insert;
2956
    $dbi->find_or_create;
2957

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

            
2960
    my $model = $dbi->model('book');
2961

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

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

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

            
2968
Create column clause for myself. The follwoing column clause is created.
2969

            
2970
    book.author as author,
2971
    book.title as title
2972

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

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

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

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

            
2986
    my $not_exists = $dbi->not_exists;
2987

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

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

            
2993
    my $order = $dbi->order;
2994

            
2995
Create a new L<DBIx::Custom::Order> object.
2996

            
cleanup
yuki-kimoto authored on 2010-10-17
2997
=head2 C<register_filter>
2998

            
update pod
Yuki Kimoto authored on 2011-03-13
2999
    $dbi->register_filter(
3000
        # Time::Piece object to database DATE format
3001
        tp_to_date => sub {
3002
            my $tp = shift;
3003
            return $tp->strftime('%Y-%m-%d');
3004
        },
3005
        # database DATE format to Time::Piece object
3006
        date_to_tp => sub {
3007
           my $date = shift;
3008
           return Time::Piece->strptime($date, '%Y-%m-%d');
3009
        }
3010
    );
cleanup
yuki-kimoto authored on 2010-10-17
3011
    
update pod
Yuki Kimoto authored on 2011-03-13
3012
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3013

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

            
3016
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3017
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
3018
            date => sub { ... },
3019
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3020
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3021
        into2 => {
3022
            date => sub { ... },
3023
            datetime => sub { ... }
3024
        },
3025
        from1 => {
3026
            # DATE
3027
            9 => sub { ... },
3028
            # DATETIME or TIMESTAMP
3029
            11 => sub { ... },
3030
        }
3031
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3032
            # DATE
3033
            9 => sub { ... },
3034
            # DATETIME or TIMESTAMP
3035
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3036
        }
3037
    );
3038

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3054
=over 4
3055

            
3056
=item 1. column name
3057

            
3058
    issue_date
3059
    issue_datetime
3060

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

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

            
3065
    book.issue_date
3066
    book.issue_datetime
3067

            
3068
=back
3069

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

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

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

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

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

            
3082
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3083
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3084
            [qw/DATE DATETIME/] => sub { ... },
3085
        ],
3086
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3087

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3090
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3091
        table  => 'book',
3092
        column => ['author', 'title'],
3093
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3094
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3095
    
updated document
Yuki Kimoto authored on 2011-06-09
3096
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3097

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

            
3100
=over 4
3101

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

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

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

            
3108
=item C<bind_type>
3109

            
3110
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3111
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3112
=item C<column>
3113
    
updated document
Yuki Kimoto authored on 2011-06-09
3114
    column => 'author'
3115
    column => ['author', 'title']
3116

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3125
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3126
        {book => [qw/author title/]},
3127
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3128
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3129

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

            
3132
    book.author as "book.author",
3133
    book.title as "book.title",
3134
    person.name as "person.name",
3135
    person.age as "person.age"
3136

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

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

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

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

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

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

            
3152
=item C<id>
3153

            
3154
    id => 4
3155
    id => [4, 5]
3156

            
3157
ID corresponding to C<primary_key>.
3158
You can select rows by C<id> and C<primary_key>.
3159

            
3160
    $dbi->select(
3161
        parimary_key => ['id1', 'id2'],
3162
        id => [4, 5],
3163
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3164
    );
3165

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3168
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3169
        where => {id1 => 4, id2 => 5},
3170
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3171
    );
3172
    
updated document
Yuki Kimoto authored on 2011-06-09
3173
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3174

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

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

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

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

            
3187
    prefix => 'SQL_CALC_FOUND_ROWS'
3188

            
3189
Prefix of column cluase
3190

            
3191
    select SQL_CALC_FOUND_ROWS title, author from book;
3192

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

            
3195
    join => [
3196
        'left outer join company on book.company_id = company_id',
3197
        'left outer join location on company.location_id = location.id'
3198
    ]
3199
        
3200
Join clause. If column cluase or where clause contain table name like "company.name",
3201
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3202

            
3203
    $dbi->select(
3204
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3205
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3206
        where => {'company.name' => 'Orange'},
3207
        join => [
3208
            'left outer join company on book.company_id = company.id',
3209
            'left outer join location on company.location_id = location.id'
3210
        ]
3211
    );
3212

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3216
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3217
    from book
3218
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3219
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3220

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3221
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
3222
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3223

            
3224
    $dbi->select(
3225
        table => 'book',
3226
        column => ['company.location_id as location_id'],
3227
        where => {'company.name' => 'Orange'},
3228
        join => [
3229
            {
3230
                clause => 'left outer join location on company.location_id = location.id',
3231
                table => ['company', 'location']
3232
            }
3233
        ]
3234
    );
3235

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3255
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3256

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

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

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

            
3263
    type_rule1_off => 1
3264

            
3265
Same as C<execute> method's C<type_rule1_off> option.
3266

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

            
3269
    type_rule2_off => 1
3270

            
3271
Same as C<execute> method's C<type_rule2_off> option.
3272

            
updated document
Yuki Kimoto authored on 2011-06-09
3273
=item C<where>
3274
    
3275
    # Hash refrence
3276
    where => {author => 'Ken', 'title' => 'Perl'}
3277
    
3278
    # DBIx::Custom::Where object
3279
    where => $dbi->where(
3280
        clause => ['and', 'author = :author', 'title like :title'],
3281
        param  => {author => 'Ken', title => '%Perl%'}
3282
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3283
    
3284
    # Array reference 1 (array reference, hash referenc). same as above
3285
    where => [
3286
        ['and', 'author = :author', 'title like :title'],
3287
        {author => 'Ken', title => '%Perl%'}
3288
    ];    
3289
    
3290
    # Array reference 2 (String, hash reference)
3291
    where => [
3292
        'title like :title',
3293
        {title => '%Perl%'}
3294
    ]
3295
    
3296
    # String
3297
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3298

            
updated document
Yuki Kimoto authored on 2011-06-09
3299
Where clause.
3300
    
update pod
Yuki Kimoto authored on 2011-03-12
3301
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3302

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

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

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

            
3309
If you want to set constant value to row data, use scalar reference
3310
as parameter value.
3311

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3316
=over 4
3317

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

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

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

            
3324
Same as C<execute> method's C<bind_type> option.
3325

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3332
    id => 4
3333
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3334

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3338
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3339
        {title => 'Perl', author => 'Ken'}
3340
        parimary_key => ['id1', 'id2'],
3341
        id => [4, 5],
3342
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3343
    );
update pod
Yuki Kimoto authored on 2011-03-13
3344

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3347
    $dbi->update(
3348
        {title => 'Perl', author => 'Ken'}
3349
        where => {id1 => 4, id2 => 5},
3350
        table => 'book'
3351
    );
update pod
Yuki Kimoto authored on 2011-03-13
3352

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

            
3355
    prefix => 'or replace'
3356

            
3357
prefix before table name section
3358

            
3359
    update or replace book
3360

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

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

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

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

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

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

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

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

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

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

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

            
3384
    timestamp => 1
3385

            
3386
If this value is set to 1,
3387
automatically updated timestamp column is set based on
3388
C<timestamp> attribute's C<update> value.
3389

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

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

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

            
3396
    type_rule1_off => 1
3397

            
3398
Same as C<execute> method's C<type_rule1_off> option.
3399

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

            
3402
    type_rule2_off => 1
3403

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

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

            
3408
Same as C<select> method's C<where> option.
3409

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

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

            
3414
placeholder wrapped string.
3415

            
3416
If the following statement
3417

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

            
3421
is executed, the following SQL is executed.
3422

            
3423
    update book set price =  ? + 5;
3424

            
updated pod
Yuki Kimoto authored on 2011-06-08
3425
=back
update pod
Yuki Kimoto authored on 2011-03-13
3426

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

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

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

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

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

            
3438
Create update parameter tag.
3439

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

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

            
3444
    $dbi->update_timestamp(updated_at => sub { localtime });
3445

            
3446
Parameter for timestamp columns when C<update> method is executed
3447
with C<timestamp> option.
3448

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

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

            
3456
Create a new L<DBIx::Custom::Where> object.
3457

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

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

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

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

            
3467
    $dbi->show_datatype($table);
3468

            
3469
Show data type of the columns of specified table.
3470

            
3471
    book
3472
    title: 5
3473
    issue_date: 91
3474

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

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

            
3479
    $dbi->show_tables;
3480

            
3481
Show tables.
3482

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

            
3485
    $dbi->show_typename($table);
3486

            
3487
Show type name of the columns of specified table.
3488

            
3489
    book
3490
    title: varchar
3491
    issue_date: date
3492

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

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

            
3497
=head2 C<DBIX_CUSTOM_DEBUG>
3498

            
3499
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3500
executed SQL and bind values are printed to STDERR.
3501

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

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

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

            
3508
L<DBIx::Custom>
3509

            
3510
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3511
    default_dbi_option # will be removed 2017/1/1
3512
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3513
    data_source # will be removed at 2017/1/1
3514
    dbi_options # will be removed at 2017/1/1
3515
    filter_check # will be removed at 2017/1/1
3516
    reserved_word_quote # will be removed at 2017/1/1
3517
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3518
    
3519
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3520
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3521
    assign_param # will be removed at 2017/1/1
3522
    update_param # will be removed at 2017/1/1
3523
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3524
    create_query # will be removed at 2017/1/1
3525
    apply_filter # will be removed at 2017/1/1
3526
    select_at # will be removed at 2017/1/1
3527
    delete_at # will be removed at 2017/1/1
3528
    update_at # will be removed at 2017/1/1
3529
    insert_at # will be removed at 2017/1/1
3530
    register_tag # will be removed at 2017/1/1
3531
    default_bind_filter # will be removed at 2017/1/1
3532
    default_fetch_filter # will be removed at 2017/1/1
3533
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3534
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3535
    register_tag_processor # will be removed at 2017/1/1
3536
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3537
    
3538
    # Options
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3539
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3540
    select method relation option # will be removed at 2017/1/1
3541
    select method param option # will be removed at 2017/1/1
3542
    select method column option [COLUMN, as => ALIAS] format
3543
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3544
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3545
    
3546
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3547
    execute("select * from {= title}"); # execute method's
3548
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3549
                                        # will be removed at 2017/1/1
3550
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3551

            
3552
L<DBIx::Custom::Model>
3553

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3554
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3555
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3556
    filter # will be removed at 2017/1/1
3557
    name # will be removed at 2017/1/1
3558
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3559

            
3560
L<DBIx::Custom::Query>
3561
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3562
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3563
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3564
    table # will be removed at 2017/1/1
3565
    filters # will be removed at 2017/1/1
3566
    
3567
    # Methods
3568
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3569

            
3570
L<DBIx::Custom::QueryBuilder>
3571
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3572
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3573
    tags # will be removed at 2017/1/1
3574
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3575
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3576
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3577
    register_tag # will be removed at 2017/1/1
3578
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3579
    
3580
    # Others
3581
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3582
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3583

            
3584
L<DBIx::Custom::Result>
3585
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3586
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3587
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3588
    
3589
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3590
    end_filter # will be removed at 2017/1/1
3591
    remove_end_filter # will be removed at 2017/1/1
3592
    remove_filter # will be removed at 2017/1/1
3593
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3594

            
3595
L<DBIx::Custom::Tag>
3596

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

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

            
3601
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3602
except for attribute method.
3603
You can check all DEPRECATED functionalities by document.
3604
DEPRECATED functionality is removed after five years,
3605
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
3606
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3607

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

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

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

            
3614
C<< <kimoto.yuki at gmail.com> >>
3615

            
3616
L<http://github.com/yuki-kimoto/DBIx-Custom>
3617

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3618
=head1 AUTHOR
3619

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

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

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

            
3626
This program is free software; you can redistribute it and/or modify it
3627
under the same terms as Perl itself.
3628

            
3629
=cut