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

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
630
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
631
    if (defined $id) {
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
632
        warn "insert method's id option is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-08
633
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
634
        $param = $self->merge_param($id_param, $param);
635
    }
636

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1184
sub update_timestamp {
1185
    my $self = shift;
1186
    
1187
    if (@_) {
1188
        $self->{update_timestamp} = [@_];
1189
        
1190
        return $self;
1191
    }
1192
    return $self->{update_timestamp};
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

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

            
1682
# DEPRECATED!
1683
sub assign_param {
1684
    my $self = shift;
1685
    warn "assing_param is DEPRECATED! use assign_clause instead";
1686
    return $self->assign_clause(@_);
1687
}
1688

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

            
1699
    return $tag;
1700
}
1701

            
updated pod
Yuki Kimoto authored on 2011-06-21
1702
# DEPRECATED!
1703
sub create_query {
1704
    warn "create_query is DEPRECATED! use query option of each method";
1705
    shift->_create_query(@_);
1706
}
1707

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1770
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1771
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1772
sub update_at {
1773
    my $self = shift;
1774

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1876
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1877
sub default_fetch_filter {
1878
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1879

            
cleanup
Yuki Kimoto authored on 2011-06-13
1880
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1881
    
1882
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1883
        my $fname = $_[0];
1884

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1901
# DEPRECATED!
1902
sub insert_param {
1903
    my $self = shift;
1904
    warn "insert_param is DEPRECATED! use values_clause instead";
1905
    return $self->values_clause(@_);
1906
}
1907

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1959
=head1 NAME
1960

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2034
Named place holder support
2035

            
2036
=item *
2037

            
cleanup
Yuki Kimoto authored on 2011-07-29
2038
Model support
2039

            
2040
=item *
2041

            
2042
Connection manager support
2043

            
2044
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2045

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

            
2050
=item *
2051

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

            
2054
=item *
2055

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

            
2058
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2059

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2067
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2068
L<DBIx::Custom::Result>,
2069
L<DBIx::Custom::Query>,
2070
L<DBIx::Custom::Where>,
2071
L<DBIx::Custom::Model>,
2072
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2073

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

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

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

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

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

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

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

            
2099
    my $dbi = DBIx::Custom->connect(
2100
      dsn => $dsn, user => $user, password => $password, connector => 1);
2101
    
2102
    my $connector = $dbi->connector; # DBIx::Connector
2103

            
2104
Note that L<DBIx::Connector> must be installed.
2105

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

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

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

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2129
    {
2130
        RaiseError => 1,
2131
        PrintError => 0,
2132
        AutoCommit => 1,
2133
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2134

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

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

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

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

            
2144
    my $last_sql = $dbi->last_sql;
2145
    $dbi = $dbi->last_sql($last_sql);
2146

            
2147
Get last successed SQL executed by C<execute> method.
2148

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2156
=head2 C<password>
2157

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2178
You can set quote pair.
2179

            
2180
    $dbi->quote('[]');
2181

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2191
    my $safety_character = $dbi->safety_character;
2192
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2193

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

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

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

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

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

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

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

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

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

            
2219
    my $tag_parse = $dbi->tag_parse(0);
2220
    $dbi = $dbi->tag_parse;
2221

            
2222
Enable DEPRECATED tag parsing functionality, default to 1.
2223
If you want to disable tag parsing functionality, set to 0.
2224

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

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

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

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

            
2234
    my $user_column_info = $dbi->user_column_info;
2235
    $dbi = $dbi->user_column_info($user_column_info);
2236

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

            
2239
    [
2240
        {table => 'book', column => 'title', info => {...}},
2241
        {table => 'author', column => 'name', info => {...}}
2242
    ]
2243

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

            
2246
    my $user_column_info
2247
      = $dbi->get_column_info(exclude_table => qr/^system/);
2248
    $dbi->user_column_info($user_column_info);
2249

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

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

            
2255
    my $user_table_info = $dbi->user_table_info;
2256
    $dbi = $dbi->user_table_info($user_table_info);
2257

            
2258
You can set the following data.
2259

            
2260
    [
2261
        {table => 'book', info => {...}},
2262
        {table => 'author', info => {...}}
2263
    ]
2264

            
2265
Usually, you can set return value of C<get_table_info>.
2266

            
2267
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2268
    $dbi->user_table_info($user_table_info);
2269

            
2270
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2271
to find table info.
2272

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2309
Create column clause. The follwoing column clause is created.
2310

            
2311
    book.author as "book.author",
2312
    book.title as "book.title"
2313

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

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

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

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

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

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

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

            
2341
Get rows count.
2342

            
2343
Options is same as C<select> method's ones.
2344

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

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

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

            
2358
   $dbi->model('book')->select(...);
2359

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

            
2362
    my $dbh = $dbi->dbh;
2363

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

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

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

            
2371
Execute delete statement.
2372

            
2373
The following opitons are available.
2374

            
2375
=over 4
2376

            
2377
=item C<append>
2378

            
2379
Same as C<select> method's C<append> option.
2380

            
2381
=item C<filter>
2382

            
2383
Same as C<execute> method's C<filter> option.
2384

            
2385
=item C<id>
2386

            
2387
    id => 4
2388
    id => [4, 5]
2389

            
2390
ID corresponding to C<primary_key>.
2391
You can delete rows by C<id> and C<primary_key>.
2392

            
2393
    $dbi->delete(
2394
        parimary_key => ['id1', 'id2'],
2395
        id => [4, 5],
2396
        table => 'book',
2397
    );
2398

            
2399
The above is same as the followin one.
2400

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

            
2403
=item C<prefix>
2404

            
2405
    prefix => 'some'
2406

            
2407
prefix before table name section.
2408

            
2409
    delete some from book
2410

            
2411
=item C<query>
2412

            
2413
Same as C<execute> method's C<query> option.
2414

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

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

            
2419
=item C<table>
2420

            
2421
    table => 'book'
2422

            
2423
Table name.
2424

            
2425
=item C<where>
2426

            
2427
Same as C<select> method's C<where> option.
2428

            
2429
=item C<primary_key>
2430

            
2431
See C<id> option.
2432

            
2433
=item C<bind_type>
2434

            
2435
Same as C<execute> method's C<bind_type> option.
2436

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

            
2439
Same as C<execute> method's C<type_rule_off> option.
2440

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

            
2443
    type_rule1_off => 1
2444

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

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

            
2449
    type_rule2_off => 1
2450

            
2451
Same as C<execute> method's C<type_rule2_off> option.
2452

            
2453
=back
2454

            
2455
=head2 C<delete_all>
2456

            
2457
    $dbi->delete_all(table => $table);
2458

            
2459
Execute delete statement for all rows.
2460
Options is same as C<delete>.
2461

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

            
2464
    $dbi->each_column(
2465
        sub {
2466
            my ($dbi, $table, $column, $column_info) = @_;
2467
            
2468
            my $type = $column_info->{TYPE_NAME};
2469
            
2470
            if ($type eq 'DATE') {
2471
                # ...
2472
            }
2473
        }
2474
    );
2475

            
2476
Iterate all column informations of all table from database.
2477
Argument is callback when one column is found.
2478
Callback receive four arguments, dbi object, table name,
2479
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2480

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

            
2483
    $dbi->each_table(
2484
        sub {
2485
            my ($dbi, $table, $table_info) = @_;
2486
            
2487
            my $table_name = $table_info->{TABLE_NAME};
2488
        }
2489
    );
2490

            
2491
Iterate all table informationsfrom database.
2492
Argument is callback when one table is found.
2493
Callback receive three arguments, dbi object, table name,
2494
table information.
2495

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2525
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2526
    select * from book where :title{=} and :author{like}
2527
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2528
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2529
    select * from where title = ? and author like ?;
2530

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

            
2535
    select * from where title = "aa\\:bb";
2536

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

            
2539
=over 4
2540

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

            
2543
Specify database bind data type.
2544

            
2545
    bind_type => [image => DBI::SQL_BLOB]
2546
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2547

            
2548
This is used to bind parameter by C<bind_param> of statment handle.
2549

            
2550
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2551

            
update pod
Yuki Kimoto authored on 2011-03-13
2552
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2553
    
2554
    filter => {
2555
        title  => sub { uc $_[0] }
2556
        author => sub { uc $_[0] }
2557
    }
update pod
Yuki Kimoto authored on 2011-03-13
2558

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

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

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

            
2577
    id => 4
2578
    id => [4, 5]
2579

            
2580
ID corresponding to C<primary_key>.
2581
You can delete rows by C<id> and C<primary_key>.
2582

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

            
2590
The above is same as the followin one.
2591

            
2592
    $dbi->execute(
2593
        "select * from book where id1 = :id1 and id2 = :id2",
2594
        {id1 => 4, id2 => 5}
2595
    );
2596

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

            
2599
    query => 1
2600

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

            
2604
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2605
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2606
    my $columns = $query->columns;
2607
    
2608
If you want to execute SQL fast, you can do the following way.
2609

            
2610
    my $query;
2611
    foreach my $row (@$rows) {
2612
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2613
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2614
    }
2615

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

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

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

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

            
2636
See C<id> option.
2637

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

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

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

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

            
2646
    $dbi->select(
2647
        table => 'book',
2648
        column => 'distinct(name)',
2649
        after_build_sql => sub {
2650
            "select count(*) from ($_[0]) as t1"
2651
        }
2652
    );
2653

            
2654
The following SQL is executed.
2655

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2658
=item C<table>
2659
    
2660
    table => 'author'
2661

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

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

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

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

            
2676
    table_alias => {user => 'hiker'}
2677

            
2678
Table alias. Key is real table name, value is alias table name.
2679
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2680
on alias table name.
2681

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

            
2684
    type_rule_off => 1
2685

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

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

            
2690
    type_rule1_off => 1
2691

            
2692
Turn C<into1> type rule off.
2693

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

            
2696
    type_rule2_off => 1
2697

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

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

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

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

            
2706
get column infomation except for one which match C<exclude_table> pattern.
2707

            
2708
    [
2709
        {table => 'book', column => 'title', info => {...}},
2710
        {table => 'author', column => 'name' info => {...}}
2711
    ]
2712

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

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

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

            
2719
    [
2720
        {table => 'book', info => {...}},
2721
        {table => 'author', info => {...}}
2722
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2723

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2726
=head2 C<insert>
2727

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

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

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

            
2736
    {date => \"NOW()"}
2737

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

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

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

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

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

            
2748
Same as C<execute> method's C<bind_type> option.
2749

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

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

            
2754
=item C<id>
2755

            
updated document
Yuki Kimoto authored on 2011-06-09
2756
    id => 4
2757
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2758

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

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

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

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

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

            
2778
    prefix => 'or replace'
2779

            
2780
prefix before table name section
2781

            
2782
    insert or replace into book
2783

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

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

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

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

            
2793
Same as C<execute> method's C<query> option.
2794

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

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

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

            
2801
    table => 'book'
2802

            
2803
Table name.
2804

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

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

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

            
2811
    timestamp => 1
2812

            
2813
If this value is set to 1,
2814
automatically created timestamp column is set based on
2815
C<timestamp> attribute's C<insert> value.
2816

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

            
2819
    type_rule1_off => 1
2820

            
2821
Same as C<execute> method's C<type_rule1_off> option.
2822

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

            
2825
    type_rule2_off => 1
2826

            
2827
Same as C<execute> method's C<type_rule2_off> option.
2828

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

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

            
2833
placeholder wrapped string.
2834

            
2835
If the following statement
2836

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

            
2840
is executed, the following SQL is executed.
2841

            
2842
    insert into book price values ( ? + 5 );
2843

            
update pod
Yuki Kimoto authored on 2011-03-13
2844
=back
2845

            
2846
=over 4
2847

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2863
    lib / MyModel.pm
2864
        / MyModel / book.pm
2865
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2866

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

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

            
2871
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2872
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2873
    
2874
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2875

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2880
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2881
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2882
    
2883
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2884

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2887
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2888
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2889
    
2890
    1;
2891
    
updated pod
Yuki Kimoto authored on 2011-06-21
2892
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2893

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

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

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

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

            
2903
    $dbi->insert_timestamp(
2904
      [qw/created_at updated_at/] => sub { localtime });
2905

            
2906
Parameter for timestamp columns when C<insert> method is executed
2907
with C<timestamp> option.
2908

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

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

            
2913
    my $like_value = $dbi->like_value
2914

            
2915
Constant code reference for the like value.
2916

            
2917
    sub { "%$_[0]%" }
2918

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

            
2921
    my $mapper = $dbi->mapper(param => $param);
2922

            
2923
Create a new L<DBIx::Custom::Mapper> object.
2924

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

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

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

            
2931
    {key1 => [1, 1], key2 => 2}
2932

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

            
2935
    $dbi->method(
2936
        update_or_insert => sub {
2937
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2938
            
2939
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2940
        },
2941
        find_or_create   => 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
    );
2947

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

            
2950
    $dbi->update_or_insert;
2951
    $dbi->find_or_create;
2952

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

            
2955
    my $model = $dbi->model('book');
2956

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

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

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

            
2963
Create column clause for myself. The follwoing column clause is created.
2964

            
2965
    book.author as author,
2966
    book.title as title
2967

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

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

            
2977
Create a new L<DBIx::Custom> object.
2978

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

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

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

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

            
2988
    my $order = $dbi->order;
2989

            
2990
Create a new L<DBIx::Custom::Order> object.
2991

            
cleanup
yuki-kimoto authored on 2010-10-17
2992
=head2 C<register_filter>
2993

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3049
=over 4
3050

            
3051
=item 1. column name
3052

            
3053
    issue_date
3054
    issue_datetime
3055

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

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

            
3060
    book.issue_date
3061
    book.issue_datetime
3062

            
3063
=back
3064

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

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

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

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

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

            
3077
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3078
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3079
            [qw/DATE DATETIME/] => sub { ... },
3080
        ],
3081
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3082

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

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

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

            
3095
=over 4
3096

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

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

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

            
3103
=item C<bind_type>
3104

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3120
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3121
        {book => [qw/author title/]},
3122
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3123
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3124

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

            
3127
    book.author as "book.author",
3128
    book.title as "book.title",
3129
    person.name as "person.name",
3130
    person.age as "person.age"
3131

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

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

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

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

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

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

            
3147
=item C<id>
3148

            
3149
    id => 4
3150
    id => [4, 5]
3151

            
3152
ID corresponding to C<primary_key>.
3153
You can select rows by C<id> and C<primary_key>.
3154

            
3155
    $dbi->select(
3156
        parimary_key => ['id1', 'id2'],
3157
        id => [4, 5],
3158
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3159
    );
3160

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

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

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

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

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

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

            
3182
    prefix => 'SQL_CALC_FOUND_ROWS'
3183

            
3184
Prefix of column cluase
3185

            
3186
    select SQL_CALC_FOUND_ROWS title, author from book;
3187

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3211
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3212
    from book
3213
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3214
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3215

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3216
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
3217
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3218

            
3219
    $dbi->select(
3220
        table => 'book',
3221
        column => ['company.location_id as location_id'],
3222
        where => {'company.name' => 'Orange'},
3223
        join => [
3224
            {
3225
                clause => 'left outer join location on company.location_id = location.id',
3226
                table => ['company', 'location']
3227
            }
3228
        ]
3229
    );
3230

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3250
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3251

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

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

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

            
3258
    type_rule1_off => 1
3259

            
3260
Same as C<execute> method's C<type_rule1_off> option.
3261

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

            
3264
    type_rule2_off => 1
3265

            
3266
Same as C<execute> method's C<type_rule2_off> option.
3267

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3294
Where clause.
3295
    
update pod
Yuki Kimoto authored on 2011-03-12
3296
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3297

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

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

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

            
3304
If you want to set constant value to row data, use scalar reference
3305
as parameter value.
3306

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3311
=over 4
3312

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

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

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

            
3319
Same as C<execute> method's C<bind_type> option.
3320

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3327
    id => 4
3328
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3329

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3342
    $dbi->update(
3343
        {title => 'Perl', author => 'Ken'}
3344
        where => {id1 => 4, id2 => 5},
3345
        table => 'book'
3346
    );
update pod
Yuki Kimoto authored on 2011-03-13
3347

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

            
3350
    prefix => 'or replace'
3351

            
3352
prefix before table name section
3353

            
3354
    update or replace book
3355

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

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

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

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

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

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

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

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

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

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

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

            
3379
    timestamp => 1
3380

            
3381
If this value is set to 1,
3382
automatically updated timestamp column is set based on
3383
C<timestamp> attribute's C<update> value.
3384

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

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

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

            
3391
    type_rule1_off => 1
3392

            
3393
Same as C<execute> method's C<type_rule1_off> option.
3394

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

            
3397
    type_rule2_off => 1
3398

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

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

            
3403
Same as C<select> method's C<where> option.
3404

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

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

            
3409
placeholder wrapped string.
3410

            
3411
If the following statement
3412

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

            
3416
is executed, the following SQL is executed.
3417

            
3418
    update book set price =  ? + 5;
3419

            
updated pod
Yuki Kimoto authored on 2011-06-08
3420
=back
update pod
Yuki Kimoto authored on 2011-03-13
3421

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

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

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

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

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

            
3433
Create update parameter tag.
3434

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

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

            
3439
    $dbi->update_timestamp(updated_at => sub { localtime });
3440

            
3441
Parameter for timestamp columns when C<update> method is executed
3442
with C<timestamp> option.
3443

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

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

            
3451
Create a new L<DBIx::Custom::Where> object.
3452

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

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

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

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

            
3462
    $dbi->show_datatype($table);
3463

            
3464
Show data type of the columns of specified table.
3465

            
3466
    book
3467
    title: 5
3468
    issue_date: 91
3469

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

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

            
3474
    $dbi->show_tables;
3475

            
3476
Show tables.
3477

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

            
3480
    $dbi->show_typename($table);
3481

            
3482
Show type name of the columns of specified table.
3483

            
3484
    book
3485
    title: varchar
3486
    issue_date: date
3487

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

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

            
3492
=head2 C<DBIX_CUSTOM_DEBUG>
3493

            
3494
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3495
executed SQL and bind values are printed to STDERR.
3496

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

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

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

            
3503
L<DBIx::Custom>
3504

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

            
3546
L<DBIx::Custom::Model>
3547

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3548
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3549
    filter # will be removed at 2017/1/1
3550
    name # will be removed at 2017/1/1
3551
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3552

            
3553
L<DBIx::Custom::Query>
3554
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3555
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3556
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3557
    table # will be removed at 2017/1/1
3558
    filters # will be removed at 2017/1/1
3559
    
3560
    # Methods
3561
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3562

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

            
3577
L<DBIx::Custom::Result>
3578
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3579
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3580
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3581
    
3582
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3583
    end_filter # will be removed at 2017/1/1
3584
    remove_end_filter # will be removed at 2017/1/1
3585
    remove_filter # will be removed at 2017/1/1
3586
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3587

            
3588
L<DBIx::Custom::Tag>
3589

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

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

            
3594
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3595
except for attribute method.
3596
You can check all DEPRECATED functionalities by document.
3597
DEPRECATED functionality is removed after five years,
3598
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
3599
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3600

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

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

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

            
3607
C<< <kimoto.yuki at gmail.com> >>
3608

            
3609
L<http://github.com/yuki-kimoto/DBIx-Custom>
3610

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3611
=head1 AUTHOR
3612

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

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

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

            
3619
This program is free software; you can redistribute it and/or modify it
3620
under the same terms as Perl itself.
3621

            
3622
=cut