DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3620 lines | 93.324kb
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) {
cleanup
Yuki Kimoto authored on 2011-06-08
632
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
633
        $param = $self->merge_param($id_param, $param);
634
    }
635

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1698
    return $tag;
1699
}
1700

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2035
=item *
2036

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

            
2039
=item *
2040

            
2041
Connection manager support
2042

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

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

            
2049
=item *
2050

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

            
2053
=item *
2054

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2257
You can set the following data.
2258

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2340
Get rows count.
2341

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

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

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

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

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

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

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

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

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

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

            
2370
Execute delete statement.
2371

            
2372
The following opitons are available.
2373

            
2374
=over 4
2375

            
2376
=item C<append>
2377

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

            
2380
=item C<filter>
2381

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

            
2384
=item C<id>
2385

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

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

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

            
2398
The above is same as the followin one.
2399

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

            
2402
=item C<prefix>
2403

            
2404
    prefix => 'some'
2405

            
2406
prefix before table name section.
2407

            
2408
    delete some from book
2409

            
2410
=item C<query>
2411

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

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

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

            
2418
=item C<table>
2419

            
2420
    table => 'book'
2421

            
2422
Table name.
2423

            
2424
=item C<where>
2425

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

            
2428
=item C<primary_key>
2429

            
2430
See C<id> option.
2431

            
2432
=item C<bind_type>
2433

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

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

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

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

            
2442
    type_rule1_off => 1
2443

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

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

            
2448
    type_rule2_off => 1
2449

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

            
2452
=back
2453

            
2454
=head2 C<delete_all>
2455

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2538
=over 4
2539

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

            
2542
Specify database bind data type.
2543

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

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

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

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

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

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

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

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

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

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

            
2589
The above is same as the followin one.
2590

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

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

            
2598
    query => 1
2599

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

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

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

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

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

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

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

            
2635
See C<id> option.
2636

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

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

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

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

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

            
2653
The following SQL is executed.
2654

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

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

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

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

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

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

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

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

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

            
2683
    type_rule_off => 1
2684

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

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

            
2689
    type_rule1_off => 1
2690

            
2691
Turn C<into1> type rule off.
2692

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

            
2695
    type_rule2_off => 1
2696

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2753
=item C<id>
2754

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

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

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

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

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

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

            
2777
    prefix => 'or replace'
2778

            
2779
prefix before table name section
2780

            
2781
    insert or replace into book
2782

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

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

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

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

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

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

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

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

            
2800
    table => 'book'
2801

            
2802
Table name.
2803

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

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

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

            
2810
    timestamp => 1
2811

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

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

            
2818
    type_rule1_off => 1
2819

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

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

            
2824
    type_rule2_off => 1
2825

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

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

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

            
2832
placeholder wrapped string.
2833

            
2834
If the following statement
2835

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

            
2839
is executed, the following SQL is executed.
2840

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

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

            
2845
=over 4
2846

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2912
    my $like_value = $dbi->like_value
2913

            
2914
Constant code reference for the like value.
2915

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

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

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

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

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

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

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

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

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

            
2934
    $dbi->method(
2935
        update_or_insert => sub {
2936
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2937
            
2938
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2939
        },
2940
        find_or_create   => sub {
2941
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2942
            
2943
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2944
        }
2945
    );
2946

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3050
=item 1. column name
3051

            
3052
    issue_date
3053
    issue_datetime
3054

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

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

            
3059
    book.issue_date
3060
    book.issue_datetime
3061

            
3062
=back
3063

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

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

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

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

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

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

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

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

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

            
3094
=over 4
3095

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

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

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

            
3102
=item C<bind_type>
3103

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3146
=item C<id>
3147

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

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

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

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

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

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

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

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

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

            
3181
    prefix => 'SQL_CALC_FOUND_ROWS'
3182

            
3183
Prefix of column cluase
3184

            
3185
    select SQL_CALC_FOUND_ROWS title, author from book;
3186

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3257
    type_rule1_off => 1
3258

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

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

            
3263
    type_rule2_off => 1
3264

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3349
    prefix => 'or replace'
3350

            
3351
prefix before table name section
3352

            
3353
    update or replace book
3354

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

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

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

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

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

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

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

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

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

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

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

            
3378
    timestamp => 1
3379

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

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

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

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

            
3390
    type_rule1_off => 1
3391

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

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

            
3396
    type_rule2_off => 1
3397

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

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

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

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

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

            
3408
placeholder wrapped string.
3409

            
3410
If the following statement
3411

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

            
3415
is executed, the following SQL is executed.
3416

            
3417
    update book set price =  ? + 5;
3418

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

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

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

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

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

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

            
3432
Create update parameter tag.
3433

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3465
    book
3466
    title: 5
3467
    issue_date: 91
3468

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

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

            
3473
    $dbi->show_tables;
3474

            
3475
Show tables.
3476

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

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

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

            
3483
    book
3484
    title: varchar
3485
    issue_date: date
3486

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

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

            
3491
=head2 C<DBIX_CUSTOM_DEBUG>
3492

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

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

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

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

            
3502
L<DBIx::Custom>
3503

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

            
3544
L<DBIx::Custom::Model>
3545

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

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

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

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

            
3586
L<DBIx::Custom::Tag>
3587

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

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

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

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

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

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

            
3605
C<< <kimoto.yuki at gmail.com> >>
3606

            
3607
L<http://github.com/yuki-kimoto/DBIx-Custom>
3608

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3609
=head1 AUTHOR
3610

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

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

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

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

            
3620
=cut