DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3541 lines | 92.187kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
4
our $VERSION = '0.1733';
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-10-21
239
    my $where            = $args{where} || {};
240
    my $allow_delete_all = $args{allow_delete_all};
241
    my $where_param      = $args{where_param} || {};
242
    my $id = $args{id};
243
    my $primary_key = $args{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
244
    croak "update method primary_key option " .
245
          "must be specified when id is specified " . _subname
246
      if defined $id && !defined $primary_key;
247
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
248
    my $prefix = $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
249
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
250
    # Where
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
251
    $where = $self->_create_param_from_id($id, $primary_key, $table)
252
      if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
253
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
254
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
255
        $where_clause = "where " . $where->[0];
256
        $where_param = $where->[1];
257
    }
258
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
259
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
260
        $where_param = keys %$where_param
261
                     ? $self->merge_param($where_param, $where->param)
262
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
263
        
264
        # String where
265
        $where_clause = $where->to_string;
266
    }
267
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
268
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
269
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
270

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
413
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
414
    
415
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
416
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
417
    
cleanup
Yuki Kimoto authored on 2011-04-02
418
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
419
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
420
    my $main_table = @{$tables}[-1];
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
421

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

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

            
548
        return $result;
549
    }
cleanup
Yuki Kimoto authored on 2011-04-02
550
    
551
    # Not select statement
552
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
553
}
554

            
added test
Yuki Kimoto authored on 2011-08-16
555
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
556
    my ($self, %args) = @_;
557
    
558
    my $exclude = delete $args{exclude};
559
    croak qq/"$_" is wrong option/ for keys %args;
560
    
added test
Yuki Kimoto authored on 2011-08-16
561
    my $table_info = [];
562
    $self->each_table(
563
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
564
        exclude => $exclude
565
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
566
    
cleanup test
Yuki Kimoto authored on 2011-08-16
567
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
568
}
569

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
570
sub get_column_info {
571
    my ($self, %args) = @_;
572
    
573
    my $exclude_table = delete $args{exclude_table};
574
    croak qq/"$_" is wrong option/ for keys %args;
575
    
576
    my $column_info = [];
577
    $self->each_column(
578
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
579
        exclude_table => $exclude_table
580
    );
581
    
582
    return [
583
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
584
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
585
}
586

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
587
sub helper {
588
    my $self = shift;
589
    
590
    # Register method
591
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
592
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
593
    
594
    return $self;
595
}
596

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
621
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
622
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
623
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
624
        $param = $self->merge_param($id_param, $param);
625
    }
626

            
cleanup
Yuki Kimoto authored on 2011-04-02
627
    # Insert statement
micro optimization
Yuki Kimoto authored on 2011-09-30
628
    my $sql;
629
    $sql .= "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
630
    $sql .= "$args{prefix} " if defined $args{prefix};
631
    $sql .= "into " . $self->_q($args{table}) . " "
632
      . $self->values_clause($param, {wrap => $args{wrap}}) . " ";
packaging one directory
yuki-kimoto authored on 2009-11-16
633
    
634
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
635
    return $self->execute($sql, $param, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
636
}
637

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
638
sub update_or_insert {
639
    my $self = shift;
640

            
641
    # Arguments
642
    my $param  = shift;
643
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
644
    my $id = $args{id};
645
    my $primary_key = $args{primary_key};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
646
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
647
    croak "update_or_insert method need primary_key option " .
648
          "when id is specified" . _subname
649
      if defined $id && !defined $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
650
    my $table  = $args{table};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
651
    croak qq{"table" option must be specified } . _subname
652
      unless defined $table;
cleanup
Yuki Kimoto authored on 2011-10-21
653
    my $select_option = $args{select_option};
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
654
    
655
    my $rows = $self->select(table => $table, id => $id,
656
        primary_key => $primary_key, %$select_option)->all;
657
    
658
    croak "selected row count must be one or zero" . _subname
659
      if @$rows > 1;
660
    
661
    my $row = $rows->[0];
662
    my @options = (table => $table);
663
    push @options, id => $id, primary_key => $primary_key if defined $id;
664
    push @options, %args;
665
    
666
    if ($row) {
667
        return $self->update($param, @options);
668
    }
669
    else {
670
        return $self->insert($param, @options);
671
    }
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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
781
sub model {
782
    my ($self, $name, $model) = @_;
783
    
cleanup
Yuki Kimoto authored on 2011-04-02
784
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
785
    if ($model) {
786
        $self->models->{$name} = $model;
787
        return $self;
788
    }
789
    
790
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
791
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
792
      unless $self->models->{$name};
793
    
cleanup
Yuki Kimoto authored on 2011-04-02
794
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
795
    return $self->models->{$name};
796
}
797

            
cleanup
Yuki Kimoto authored on 2011-03-21
798
sub mycolumn {
799
    my ($self, $table, $columns) = @_;
800
    
cleanup
Yuki Kimoto authored on 2011-04-02
801
    # Create column clause
802
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
803
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
804
    push @column, $self->_q($table) . "." . $self->_q($_) .
805
      " as " . $self->_q($_)
806
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
807
    
808
    return join (', ', @column);
809
}
810

            
added dbi_options attribute
kimoto authored on 2010-12-20
811
sub new {
812
    my $self = shift->SUPER::new(@_);
813
    
cleanup
Yuki Kimoto authored on 2011-04-02
814
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
815
    my @attrs = keys %$self;
816
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
817
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
818
          unless $self->can($attr);
819
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
820

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
821
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
822
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
823
        '?'     => \&DBIx::Custom::Tag::placeholder,
824
        '='     => \&DBIx::Custom::Tag::equal,
825
        '<>'    => \&DBIx::Custom::Tag::not_equal,
826
        '>'     => \&DBIx::Custom::Tag::greater_than,
827
        '<'     => \&DBIx::Custom::Tag::lower_than,
828
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
829
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
830
        'like'  => \&DBIx::Custom::Tag::like,
831
        'in'    => \&DBIx::Custom::Tag::in,
832
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
833
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
834
    };
835
    
836
    return $self;
837
}
838

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

            
841
sub order {
842
    my $self = shift;
843
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
844
}
845

            
cleanup
yuki-kimoto authored on 2010-10-17
846
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
847
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
848
    
849
    # Register filter
850
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
851
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
852
    
cleanup
Yuki Kimoto authored on 2011-04-02
853
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
854
}
packaging one directory
yuki-kimoto authored on 2009-11-16
855

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
975
sub setup_model {
976
    my $self = shift;
977
    
cleanup
Yuki Kimoto authored on 2011-04-02
978
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
979
    $self->each_column(
980
        sub {
981
            my ($self, $table, $column, $column_info) = @_;
982
            if (my $model = $self->models->{$table}) {
983
                push @{$model->columns}, $column;
984
            }
985
        }
986
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
987
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
988
}
989

            
update pod
Yuki Kimoto authored on 2011-08-10
990
sub show_datatype {
991
    my ($self, $table) = @_;
992
    croak "Table name must be specified" unless defined $table;
993
    print "$table\n";
994
    
995
    my $result = $self->select(table => $table, where => "'0' <> '0'");
996
    my $sth = $result->sth;
997

            
998
    my $columns = $sth->{NAME};
999
    my $data_types = $sth->{TYPE};
1000
    
1001
    for (my $i = 0; $i < @$columns; $i++) {
1002
        my $column = $columns->[$i];
1003
        my $data_type = $data_types->[$i];
1004
        print "$column: $data_type\n";
1005
    }
1006
}
1007

            
1008
sub show_typename {
1009
    my ($self, $t) = @_;
1010
    croak "Table name must be specified" unless defined $t;
1011
    print "$t\n";
1012
    
1013
    $self->each_column(sub {
1014
        my ($self, $table, $column, $infos) = @_;
1015
        return unless $table eq $t;
1016
        my $typename = $infos->{TYPE_NAME};
1017
        print "$column: $typename\n";
1018
    });
1019
    
1020
    return $self;
1021
}
1022

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1023
sub show_tables {
1024
    my $self = shift;
1025
    
1026
    my %tables;
1027
    $self->each_table(sub { $tables{$_[1]}++ });
1028
    print join("\n", sort keys %tables) . "\n";
1029
    return $self;
1030
}
1031

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1067
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1068
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1069
                }
1070
            });
1071
        }
1072

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

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

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

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1168
sub update_timestamp {
1169
    my $self = shift;
1170
    
1171
    if (@_) {
1172
        $self->{update_timestamp} = [@_];
1173
        
1174
        return $self;
1175
    }
1176
    return $self->{update_timestamp};
1177
}
1178

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1207
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1208
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1209
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1210
    
updated pod
Yuki Kimoto authored on 2011-06-21
1211
    # Cache
1212
    my $cache = $self->cache;
1213
    
1214
    # Query
1215
    my $query;
1216
    
1217
    # Get cached query
1218
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1219
        
updated pod
Yuki Kimoto authored on 2011-06-21
1220
        # Get query
1221
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1222
        
updated pod
Yuki Kimoto authored on 2011-06-21
1223
        # Create query
1224
        if ($q) {
1225
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1226
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1227
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1228
    }
1229
    
1230
    # Create query
1231
    unless ($query) {
1232

            
1233
        # Create query
1234
        my $builder = $self->query_builder;
1235
        $query = $builder->build_query($source);
1236

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

            
1243
        # Save query to cache
1244
        $self->cache_method->(
1245
            $self, $source,
1246
            {
1247
                sql     => $query->sql, 
1248
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1249
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1250
            }
1251
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1252
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1253

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1387
sub _croak {
1388
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1389
    
1390
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1391
    $append ||= "";
1392
    
1393
    # Verbose
1394
    if ($Carp::Verbose) { croak $error }
1395
    
1396
    # Not verbose
1397
    else {
1398
        
1399
        # Remove line and module infromation
1400
        my $at_pos = rindex($error, ' at ');
1401
        $error = substr($error, 0, $at_pos);
1402
        $error =~ s/\s+$//;
1403
        croak "$error$append";
1404
    }
1405
}
1406

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1409
sub _need_tables {
1410
    my ($self, $tree, $need_tables, $tables) = @_;
1411
    
cleanup
Yuki Kimoto authored on 2011-04-02
1412
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1413
    foreach my $table (@$tables) {
1414
        if ($tree->{$table}) {
1415
            $need_tables->{$table} = 1;
1416
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1417
        }
1418
    }
1419
}
1420

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1421
sub _option {
1422
    my $self = shift;
1423
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1424
    warn "dbi_options is DEPRECATED! use option instead\n"
1425
      if keys %{$self->dbi_options};
1426
    warn "dbi_option is DEPRECATED! use option instead\n"
1427
      if keys %{$self->dbi_option};
1428
    return $option;
1429
}
1430

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1431
sub _push_join {
1432
    my ($self, $sql, $join, $join_tables) = @_;
1433
    
cleanup
Yuki Kimoto authored on 2011-04-02
1434
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1435
    return unless @$join;
1436
    
cleanup
Yuki Kimoto authored on 2011-04-02
1437
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1438
    my $tree = {};
1439
    for (my $i = 0; $i < @$join; $i++) {
1440
        
cleanup
Yuki Kimoto authored on 2011-07-28
1441
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1442
        my $join_clause;;
1443
        my $option;
1444
        if (ref $join->[$i] eq 'HASH') {
1445
            $join_clause = $join->[$i]->{clause};
1446
            $option = {table => $join->[$i]->{table}};
1447
        }
1448
        else {
1449
            $join_clause = $join->[$i];
1450
            $option = {};
1451
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1452

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1501
sub _quote {
1502
    my $self = shift;
1503
    
1504
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1505
         : defined $self->quote ? $self->quote
1506
         : '';
1507
}
1508

            
cleanup
Yuki Kimoto authored on 2011-07-29
1509
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1510
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1511
    
1512
    my $quote = $self->_quote;
1513
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1514
    my $p;
1515
    if (defined $quote && length $quote > 1) {
1516
        $p = substr($quote, 1, 1);
1517
    }
1518
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1519
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1520
    if ($quotemeta) {
1521
        $q = quotemeta($q);
1522
        $p = quotemeta($p);
1523
    }
1524
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1525
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1526
}
1527

            
cleanup
Yuki Kimoto authored on 2011-04-02
1528
sub _remove_duplicate_table {
1529
    my ($self, $tables, $main_table) = @_;
1530
    
1531
    # Remove duplicate table
1532
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1533
    delete $tables{$main_table} if $main_table;
1534
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1535
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1536
    if (my $q = $self->_quote) {
1537
        $q = quotemeta($q);
1538
        $_ =~ s/[$q]//g for @$new_tables;
1539
    }
1540

            
1541
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1542
}
1543

            
cleanup
Yuki Kimoto authored on 2011-04-02
1544
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1545
    my ($self, $source) = @_;
1546
    
cleanup
Yuki Kimoto authored on 2011-04-02
1547
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1548
    my $tables = [];
1549
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1550
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1551
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1552
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1553
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1554
    while ($source =~ /$table_re/g) {
1555
        push @$tables, $1;
1556
    }
1557
    
1558
    return $tables;
1559
}
1560

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1680
# DEPRECATED!
1681
has 'data_source';
1682
has dbi_options => sub { {} };
1683
has filter_check  => 1;
1684
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1685
has dbi_option => sub { {} };
1686
has default_dbi_option => sub {
1687
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1688
    return shift->default_option;
1689
};
1690

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1691
# DEPRECATED!
1692
sub method {
1693
    warn "method is DEPRECATED! use helper instead";
1694
    return shift->helper(@_);
1695
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1696

            
1697
# DEPRECATED!
1698
sub assign_param {
1699
    my $self = shift;
1700
    warn "assing_param is DEPRECATED! use assign_clause instead";
1701
    return $self->assign_clause(@_);
1702
}
1703

            
1704
# DEPRECATED
1705
sub update_param {
1706
    my ($self, $param, $opts) = @_;
1707
    
1708
    warn "update_param is DEPRECATED! use assing_clause instead.";
1709
    
1710
    # Create update parameter tag
1711
    my $tag = $self->assign_clause($param, $opts);
1712
    $tag = "set $tag" unless $opts->{no_set};
1713

            
1714
    return $tag;
1715
}
1716

            
updated pod
Yuki Kimoto authored on 2011-06-21
1717
# DEPRECATED!
1718
sub create_query {
1719
    warn "create_query is DEPRECATED! use query option of each method";
1720
    shift->_create_query(@_);
1721
}
1722

            
cleanup
Yuki Kimoto authored on 2011-06-13
1723
# DEPRECATED!
1724
sub apply_filter {
1725
    my $self = shift;
1726
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1727
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1728
    return $self->_apply_filter(@_);
1729
}
1730

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1731
# DEPRECATED!
1732
sub select_at {
1733
    my ($self, %args) = @_;
1734

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1737
    # Arguments
1738
    my $primary_keys = delete $args{primary_key};
1739
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1740
    my $where = delete $args{where};
1741
    my $param = delete $args{param};
1742
    
1743
    # Table
1744
    croak qq{"table" option must be specified } . _subname
1745
      unless $args{table};
1746
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1747
    
1748
    # Create where parameter
1749
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1750
    
1751
    return $self->select(where => $where_param, %args);
1752
}
1753

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1754
# DEPRECATED!
1755
sub delete_at {
1756
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1757

            
1758
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1759
    
1760
    # Arguments
1761
    my $primary_keys = delete $args{primary_key};
1762
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1763
    my $where = delete $args{where};
1764
    
1765
    # Create where parameter
1766
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1767
    
1768
    return $self->delete(where => $where_param, %args);
1769
}
1770

            
cleanup
Yuki Kimoto authored on 2011-06-08
1771
# DEPRECATED!
1772
sub update_at {
1773
    my $self = shift;
1774

            
1775
    warn "update_at is DEPRECATED! use update and id option instead";
1776
    
1777
    # Arguments
1778
    my $param;
1779
    $param = shift if @_ % 2;
1780
    my %args = @_;
1781
    my $primary_keys = delete $args{primary_key};
1782
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1783
    my $where = delete $args{where};
1784
    my $p = delete $args{param} || {};
1785
    $param  ||= $p;
1786
    
1787
    # Create where parameter
1788
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1789
    
1790
    return $self->update(where => $where_param, param => $param, %args);
1791
}
1792

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1793
# DEPRECATED!
1794
sub insert_at {
1795
    my $self = shift;
1796
    
1797
    warn "insert_at is DEPRECATED! use insert and id option instead";
1798
    
1799
    # Arguments
1800
    my $param;
1801
    $param = shift if @_ % 2;
1802
    my %args = @_;
1803
    my $primary_key = delete $args{primary_key};
1804
    $primary_key = [$primary_key] unless ref $primary_key;
1805
    my $where = delete $args{where};
1806
    my $p = delete $args{param} || {};
1807
    $param  ||= $p;
1808
    
1809
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1810
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1811
    $param = $self->merge_param($where_param, $param);
1812
    
1813
    return $self->insert(param => $param, %args);
1814
}
1815

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1863
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1864
sub default_fetch_filter {
1865
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1866

            
cleanup
Yuki Kimoto authored on 2011-06-13
1867
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1868
    
1869
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1870
        my $fname = $_[0];
1871

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1888
# DEPRECATED!
1889
sub insert_param {
1890
    my $self = shift;
1891
    warn "insert_param is DEPRECATED! use values_clause instead";
1892
    return $self->values_clause(@_);
1893
}
1894

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1895
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1896
sub insert_param_tag {
1897
    warn "insert_param_tag is DEPRECATED! " .
1898
         "use insert_param instead!";
1899
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1900
}
1901

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1946
=head1 NAME
1947

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2021
Named place holder support
2022

            
2023
=item *
2024

            
cleanup
Yuki Kimoto authored on 2011-07-29
2025
Model support
2026

            
2027
=item *
2028

            
2029
Connection manager support
2030

            
2031
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2032

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

            
2037
=item *
2038

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

            
2041
=item *
2042

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

            
2045
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2046

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2054
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2055
L<DBIx::Custom::Result>,
2056
L<DBIx::Custom::Query>,
2057
L<DBIx::Custom::Where>,
2058
L<DBIx::Custom::Model>,
2059
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2060

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

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

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

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

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

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

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

            
2086
    my $dbi = DBIx::Custom->connect(
2087
      dsn => $dsn, user => $user, password => $password, connector => 1);
2088
    
2089
    my $connector = $dbi->connector; # DBIx::Connector
2090

            
2091
Note that L<DBIx::Connector> must be installed.
2092

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2108
    {
2109
        RaiseError => 1,
2110
        PrintError => 0,
2111
        AutoCommit => 1,
2112
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2113

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

            
2116
    my $exclude_table = $dbi->exclude_table;
2117
    $dbi = $dbi->exclude_table(qr/pg_/);
2118

            
2119
Excluded table regex.
2120
C<each_column>, C<each_table>, C<type_rule>,
2121
and C<setup_model> methods ignore matching tables.
2122

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

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

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

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

            
2132
    my $last_sql = $dbi->last_sql;
2133
    $dbi = $dbi->last_sql($last_sql);
2134

            
2135
Get last successed SQL executed by C<execute> method.
2136

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

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

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

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

            
2146
    my $option = $dbi->option;
2147
    $dbi = $dbi->option($option);
2148

            
2149
L<DBI> option, used when C<connect> method is executed.
2150
Each value in option override the value of C<default_option>.
2151

            
cleanup
yuki-kimoto authored on 2010-10-17
2152
=head2 C<password>
2153

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2174
You can set quote pair.
2175

            
2176
    $dbi->quote('[]');
2177

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2187
    my $safety_character = $dbi->safety_character;
2188
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2189

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

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

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

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

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

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

            
2206
    my $tag_parse = $dbi->tag_parse(0);
2207
    $dbi = $dbi->tag_parse;
2208

            
2209
Enable DEPRECATED tag parsing functionality, default to 1.
2210
If you want to disable tag parsing functionality, set to 0.
2211

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

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

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

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

            
2221
    my $user_column_info = $dbi->user_column_info;
2222
    $dbi = $dbi->user_column_info($user_column_info);
2223

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

            
2226
    [
2227
        {table => 'book', column => 'title', info => {...}},
2228
        {table => 'author', column => 'name', info => {...}}
2229
    ]
2230

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

            
2233
    my $user_column_info
2234
      = $dbi->get_column_info(exclude_table => qr/^system/);
2235
    $dbi->user_column_info($user_column_info);
2236

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

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

            
2242
    my $user_table_info = $dbi->user_table_info;
2243
    $dbi = $dbi->user_table_info($user_table_info);
2244

            
2245
You can set the following data.
2246

            
2247
    [
2248
        {table => 'book', info => {...}},
2249
        {table => 'author', info => {...}}
2250
    ]
2251

            
2252
Usually, you can set return value of C<get_table_info>.
2253

            
2254
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2255
    $dbi->user_table_info($user_table_info);
2256

            
2257
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2258
to find table info.
2259

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2296
Create column clause. The follwoing column clause is created.
2297

            
2298
    book.author as "book.author",
2299
    book.title as "book.title"
2300

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

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

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

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

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

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

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

            
2328
Get rows count.
2329

            
2330
Options is same as C<select> method's ones.
2331

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2334
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2335
        table => 'book',
2336
        primary_key => 'id',
2337
        join => [
2338
            'inner join company on book.comparny_id = company.id'
2339
        ],
2340
    );
2341

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

            
2345
   $dbi->model('book')->select(...);
2346

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

            
2349
    my $dbh = $dbi->dbh;
2350

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

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

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

            
2358
Execute delete statement.
2359

            
2360
The following opitons are available.
2361

            
cleanup
Yuki Kimoto authored on 2011-10-20
2362
B<OPTIONS>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2363

            
cleanup
Yuki Kimoto authored on 2011-10-20
2364
C<delete> method use all of C<execute> method's options,
2365
and use the following new ones.
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2366

            
cleanup
Yuki Kimoto authored on 2011-10-20
2367
=over 4
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2368

            
2369
=item C<id>
2370

            
2371
    id => 4
2372
    id => [4, 5]
2373

            
2374
ID corresponding to C<primary_key>.
2375
You can delete rows by C<id> and C<primary_key>.
2376

            
2377
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2378
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2379
        id => [4, 5],
2380
        table => 'book',
2381
    );
2382

            
2383
The above is same as the followin one.
2384

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

            
2387
=item C<prefix>
2388

            
2389
    prefix => 'some'
2390

            
2391
prefix before table name section.
2392

            
2393
    delete some from book
2394

            
2395
=item C<table>
2396

            
2397
    table => 'book'
2398

            
2399
Table name.
2400

            
2401
=item C<where>
2402

            
2403
Same as C<select> method's C<where> option.
2404

            
2405
=back
2406

            
2407
=head2 C<delete_all>
2408

            
2409
    $dbi->delete_all(table => $table);
2410

            
2411
Execute delete statement for all rows.
2412
Options is same as C<delete>.
2413

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

            
2416
    $dbi->each_column(
2417
        sub {
2418
            my ($dbi, $table, $column, $column_info) = @_;
2419
            
2420
            my $type = $column_info->{TYPE_NAME};
2421
            
2422
            if ($type eq 'DATE') {
2423
                # ...
2424
            }
2425
        }
2426
    );
2427

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

            
2433
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2434
infromation, you can improve the performance of C<each_column> in
2435
the following way.
2436

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

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

            
2443
    $dbi->each_table(
2444
        sub {
2445
            my ($dbi, $table, $table_info) = @_;
2446
            
2447
            my $table_name = $table_info->{TABLE_NAME};
2448
        }
2449
    );
2450

            
improved pod
Yuki Kimoto authored on 2011-10-14
2451
Iterate all table informationsfrom in database.
2452
Argument is callback which is executed when one table is found.
2453
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2454
C<table information>.
2455

            
2456
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2457
infromation, you can improve the performance of C<each_table> in
2458
the following way.
2459

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

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

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

            
2471
    my $result = $dbi->execute(
2472
      "select * from book where title = :book.title and author like :book.author",
2473
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2474
    );
2475

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2482
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2483
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2484
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2485
    select * from book where title = :title and author like :author
2486
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2487
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2488
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2489

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2490
You can specify operator with named placeholder
fixed pod
Yuki Kimoto authored on 2011-10-20
2491
by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2492

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2493
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2494
    select * from book where :title{=} and :author{like}
2495
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2496
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2497
    select * from where title = ? and author like ?;
2498

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

            
2503
    select * from where title = "aa\\:bb";
2504

            
cleanup
Yuki Kimoto authored on 2011-10-20
2505
B<OPTIONS>
2506

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

            
2509
=over 4
2510

            
cleanup
Yuki Kimoto authored on 2011-10-20
2511
=item C<append>
2512

            
2513
    append => 'order by name'
2514

            
2515
Append some statement after SQL.
2516

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

            
2519
Specify database bind data type.
2520

            
2521
    bind_type => [image => DBI::SQL_BLOB]
2522
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2523

            
2524
This is used to bind parameter by C<bind_param> of statment handle.
2525

            
2526
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2527

            
update pod
Yuki Kimoto authored on 2011-03-13
2528
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2529
    
2530
    filter => {
2531
        title  => sub { uc $_[0] }
2532
        author => sub { uc $_[0] }
2533
    }
update pod
Yuki Kimoto authored on 2011-03-13
2534

            
updated pod
Yuki Kimoto authored on 2011-06-09
2535
    # Filter name
2536
    filter => {
2537
        title  => 'upper_case',
2538
        author => 'upper_case'
2539
    }
2540
        
2541
    # At once
2542
    filter => [
2543
        [qw/title author/]  => sub { uc $_[0] }
2544
    ]
2545

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

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

            
2553
    id => 4
2554
    id => [4, 5]
2555

            
2556
ID corresponding to C<primary_key>.
2557
You can delete rows by C<id> and C<primary_key>.
2558

            
2559
    $dbi->execute(
2560
        "select * from book where id1 = :id1 and id2 = :id2",
2561
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2562
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2563
        id => [4, 5],
2564
    );
2565

            
2566
The above is same as the followin one.
2567

            
2568
    $dbi->execute(
2569
        "select * from book where id1 = :id1 and id2 = :id2",
2570
        {id1 => 4, id2 => 5}
2571
    );
2572

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

            
2575
    query => 1
2576

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

            
2580
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2581
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2582
    my $columns = $query->columns;
2583
    
2584
If you want to execute SQL fast, you can do the following way.
2585

            
2586
    my $query;
2587
    foreach my $row (@$rows) {
2588
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2589
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2590
    }
2591

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

            
2595
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
2596
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2597
    
2598
    my $query;
2599
    my $sth;
2600
    foreach my $row (@$rows) {
2601
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2602
      $sth ||= $query->sth;
2603
      $sth->execute(map { $row->{$_} } sort keys %$row);
2604
    }
2605

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2612
    primary_key => 'id'
2613
    primary_key => ['id1', 'id2']
2614

            
2615
Priamry key. This is used when C<id> option find primary key.
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2616

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

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

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

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

            
2625
    $dbi->select(
2626
        table => 'book',
2627
        column => 'distinct(name)',
2628
        after_build_sql => sub {
2629
            "select count(*) from ($_[0]) as t1"
2630
        }
2631
    );
2632

            
2633
The following SQL is executed.
2634

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2637
=item C<table>
2638
    
2639
    table => 'author'
2640

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2648
    # Same
2649
    $dbi->execute(
2650
      "select * from book where title = :book.title and author = :book.author",
2651
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2652

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2655
    table_alias => {user => 'worker'}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2656

            
2657
Table alias. Key is real table name, value is alias table name.
2658
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2659
on alias table name.
2660

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

            
2663
    type_rule_off => 1
2664

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

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

            
2669
    type_rule1_off => 1
2670

            
2671
Turn C<into1> type rule off.
2672

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

            
2675
    type_rule2_off => 1
2676

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

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

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

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

            
2685
get column infomation except for one which match C<exclude_table> pattern.
2686

            
2687
    [
2688
        {table => 'book', column => 'title', info => {...}},
2689
        {table => 'author', column => 'name' info => {...}}
2690
    ]
2691

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

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

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

            
2698
    [
2699
        {table => 'book', info => {...}},
2700
        {table => 'author', info => {...}}
2701
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2702

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

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

            
2707
    $dbi->helper(
2708
        update_or_insert => sub {
2709
            my $self = shift;
2710
            
2711
            # Process
2712
        },
2713
        find_or_create   => sub {
2714
            my $self = shift;
2715
            
2716
            # Process
2717
        }
2718
    );
2719

            
2720
Register helper. These helper is called directly from L<DBIx::Custom> object.
2721

            
2722
    $dbi->update_or_insert;
2723
    $dbi->find_or_create;
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-10-20
2737
B<options>
2738

            
cleanup
Yuki Kimoto authored on 2011-10-20
2739
C<insert> method use all of C<execute> method's options,
cleanup
Yuki Kimoto authored on 2011-10-20
2740
and use the following new ones.
update pod
Yuki Kimoto authored on 2011-03-13
2741

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2746
    id => 4
2747
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2748

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

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

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

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

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

            
2768
    prefix => 'or replace'
2769

            
2770
prefix before table name section
2771

            
2772
    insert or replace into book
2773

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

            
2776
    table => 'book'
2777

            
2778
Table name.
2779

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

            
2782
    timestamp => 1
2783

            
2784
If this value is set to 1,
2785
automatically created timestamp column is set based on
2786
C<timestamp> attribute's C<insert> value.
2787

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

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

            
2792
placeholder wrapped string.
2793

            
2794
If the following statement
2795

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

            
2799
is executed, the following SQL is executed.
2800

            
2801
    insert into book price values ( ? + 5 );
2802

            
update pod
Yuki Kimoto authored on 2011-03-13
2803
=back
2804

            
2805
=over 4
2806

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2814
    lib / MyModel.pm
2815
        / MyModel / book.pm
2816
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2817

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

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

            
2822
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2823
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2824
    
2825
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2826

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2831
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2832
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2833
    
2834
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2835

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2838
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2839
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2840
    
2841
    1;
2842
    
updated pod
Yuki Kimoto authored on 2011-06-21
2843
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2844

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

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

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

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

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

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

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

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

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

            
2870
    my $like_value = $dbi->like_value
2871

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

            
2874
    sub { "%$_[0]%" }
2875

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

            
2878
    my $mapper = $dbi->mapper(param => $param);
2879

            
2880
Create a new L<DBIx::Custom::Mapper> object.
2881

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

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

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

            
2888
    {key1 => [1, 1], key2 => 2}
2889

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

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

            
2894
    my $model = $dbi->model('book');
2895

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

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

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

            
2903
Create column clause for myself. The follwoing column clause is created.
2904

            
2905
    book.author as author,
2906
    book.title as title
2907

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

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

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

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

            
2921
    my $not_exists = $dbi->not_exists;
2922

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

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

            
2928
    my $order = $dbi->order;
2929

            
2930
Create a new L<DBIx::Custom::Order> object.
2931

            
cleanup
yuki-kimoto authored on 2010-10-17
2932
=head2 C<register_filter>
2933

            
update pod
Yuki Kimoto authored on 2011-03-13
2934
    $dbi->register_filter(
2935
        # Time::Piece object to database DATE format
2936
        tp_to_date => sub {
2937
            my $tp = shift;
2938
            return $tp->strftime('%Y-%m-%d');
2939
        },
2940
        # database DATE format to Time::Piece object
2941
        date_to_tp => sub {
2942
           my $date = shift;
2943
           return Time::Piece->strptime($date, '%Y-%m-%d');
2944
        }
2945
    );
cleanup
yuki-kimoto authored on 2010-10-17
2946
    
update pod
Yuki Kimoto authored on 2011-03-13
2947
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2948

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2951
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2952
        table  => 'book',
2953
        column => ['author', 'title'],
2954
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2955
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2956
    
updated document
Yuki Kimoto authored on 2011-06-09
2957
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2958

            
cleanup
Yuki Kimoto authored on 2011-10-20
2959
B<OPTIONS>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2960

            
cleanup
Yuki Kimoto authored on 2011-10-20
2961
C<select> method use all of C<execute> method's options,
2962
and use the following new ones.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2963

            
cleanup
Yuki Kimoto authored on 2011-10-20
2964
=over 4
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2965

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2966
=item C<column>
2967
    
updated document
Yuki Kimoto authored on 2011-06-09
2968
    column => 'author'
2969
    column => ['author', 'title']
2970

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2979
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2980
        {book => [qw/author title/]},
2981
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2982
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2983

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

            
2986
    book.author as "book.author",
2987
    book.title as "book.title",
2988
    person.name as "person.name",
2989
    person.age as "person.age"
2990

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

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

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

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

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

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

            
3006
=item C<id>
3007

            
3008
    id => 4
3009
    id => [4, 5]
3010

            
3011
ID corresponding to C<primary_key>.
3012
You can select rows by C<id> and C<primary_key>.
3013

            
3014
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3015
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3016
        id => [4, 5],
3017
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3018
    );
3019

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3022
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3023
        where => {id1 => 4, id2 => 5},
3024
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3025
    );
3026
    
cleanup
Yuki Kimoto authored on 2011-10-20
3027
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3028

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

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

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

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

            
3041
    prefix => 'SQL_CALC_FOUND_ROWS'
3042

            
3043
Prefix of column cluase
3044

            
3045
    select SQL_CALC_FOUND_ROWS title, author from book;
3046

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

            
3049
    join => [
3050
        'left outer join company on book.company_id = company_id',
3051
        'left outer join location on company.location_id = location.id'
3052
    ]
3053
        
3054
Join clause. If column cluase or where clause contain table name like "company.name",
3055
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3056

            
3057
    $dbi->select(
3058
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3059
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3060
        where => {'company.name' => 'Orange'},
3061
        join => [
3062
            'left outer join company on book.company_id = company.id',
3063
            'left outer join location on company.location_id = location.id'
3064
        ]
3065
    );
3066

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3070
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3071
    from book
3072
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3073
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3074

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3075
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
3076
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3077

            
3078
    $dbi->select(
3079
        table => 'book',
3080
        column => ['company.location_id as location_id'],
3081
        where => {'company.name' => 'Orange'},
3082
        join => [
3083
            {
3084
                clause => 'left outer join location on company.location_id = location.id',
3085
                table => ['company', 'location']
3086
            }
3087
        ]
3088
    );
3089

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3094
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3095

            
updated document
Yuki Kimoto authored on 2011-06-09
3096
=item C<where>
3097
    
3098
    # Hash refrence
3099
    where => {author => 'Ken', 'title' => 'Perl'}
3100
    
3101
    # DBIx::Custom::Where object
3102
    where => $dbi->where(
3103
        clause => ['and', 'author = :author', 'title like :title'],
3104
        param  => {author => 'Ken', title => '%Perl%'}
3105
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3106
    
3107
    # Array reference 1 (array reference, hash referenc). same as above
3108
    where => [
3109
        ['and', 'author = :author', 'title like :title'],
3110
        {author => 'Ken', title => '%Perl%'}
3111
    ];    
3112
    
3113
    # Array reference 2 (String, hash reference)
3114
    where => [
3115
        'title like :title',
3116
        {title => '%Perl%'}
3117
    ]
3118
    
3119
    # String
3120
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3121

            
cleanup
Yuki Kimoto authored on 2011-10-20
3122
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3123
    
update pod
Yuki Kimoto authored on 2011-03-12
3124
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3125

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

            
3128
    $dbi->setup_model;
3129

            
3130
Setup all model objects.
3131
C<columns> of model object is automatically set, parsing database information.
3132

            
3133
=head2 C<type_rule>
3134

            
3135
    $dbi->type_rule(
3136
        into1 => {
3137
            date => sub { ... },
3138
            datetime => sub { ... }
3139
        },
3140
        into2 => {
3141
            date => sub { ... },
3142
            datetime => sub { ... }
3143
        },
3144
        from1 => {
3145
            # DATE
3146
            9 => sub { ... },
3147
            # DATETIME or TIMESTAMP
3148
            11 => sub { ... },
3149
        }
3150
        from2 => {
3151
            # DATE
3152
            9 => sub { ... },
3153
            # DATETIME or TIMESTAMP
3154
            11 => sub { ... },
3155
        }
3156
    );
3157

            
3158
Filtering rule when data is send into and get from database.
3159
This has a little complex problem.
3160

            
3161
In C<into1> and C<into2> you can specify
3162
type name as same as type name defined
3163
by create table, such as C<DATETIME> or C<DATE>.
3164

            
3165
Note that type name and data type don't contain upper case.
3166
If these contain upper case charactor, you convert it to lower case.
3167

            
3168
C<into2> is executed after C<into1>.
3169

            
3170
Type rule of C<into1> and C<into2> is enabled on the following
3171
column name.
3172

            
3173
=over 4
3174

            
3175
=item 1. column name
3176

            
3177
    issue_date
3178
    issue_datetime
3179

            
3180
This need C<table> option in each method.
3181

            
3182
=item 2. table name and column name, separator is dot
3183

            
3184
    book.issue_date
3185
    book.issue_datetime
3186

            
3187
=back
3188

            
3189
You get all type name used in database by C<available_typename>.
3190

            
3191
    print $dbi->available_typename;
3192

            
3193
In C<from1> and C<from2> you specify data type, not type name.
3194
C<from2> is executed after C<from1>.
3195
You get all data type by C<available_datatype>.
3196

            
3197
    print $dbi->available_datatype;
3198

            
3199
You can also specify multiple types at once.
3200

            
3201
    $dbi->type_rule(
3202
        into1 => [
3203
            [qw/DATE DATETIME/] => sub { ... },
3204
        ],
3205
    );
3206

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

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

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

            
3213
If you want to set constant value to row data, use scalar reference
3214
as parameter value.
3215

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3218
B<OPTIONS>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3219

            
cleanup
Yuki Kimoto authored on 2011-10-20
3220
C<update> method use all of C<execute> method's options,
3221
and use the following new ones.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3222

            
cleanup
Yuki Kimoto authored on 2011-10-20
3223
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3224

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3227
    id => 4
3228
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3229

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3233
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3234
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3235
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3236
        id => [4, 5],
3237
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3238
    );
update pod
Yuki Kimoto authored on 2011-03-13
3239

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3242
    $dbi->update(
3243
        {title => 'Perl', author => 'Ken'}
3244
        where => {id1 => 4, id2 => 5},
3245
        table => 'book'
3246
    );
update pod
Yuki Kimoto authored on 2011-03-13
3247

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

            
3250
    prefix => 'or replace'
3251

            
3252
prefix before table name section
3253

            
3254
    update or replace book
3255

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

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

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

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

            
3264
    timestamp => 1
3265

            
3266
If this value is set to 1,
3267
automatically updated timestamp column is set based on
3268
C<timestamp> attribute's C<update> value.
3269

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

            
3272
Same as C<select> method's C<where> option.
3273

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

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

            
3278
placeholder wrapped string.
3279

            
3280
If the following statement
3281

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

            
3285
is executed, the following SQL is executed.
3286

            
3287
    update book set price =  ? + 5;
3288

            
updated pod
Yuki Kimoto authored on 2011-06-08
3289
=back
update pod
Yuki Kimoto authored on 2011-03-13
3290

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3298
=head2 C<update_or_insert EXPERIMENTAL>
3299
    
3300
    # Where
3301
    $dbi->update_or_insert(
3302
        {id => 1, title => 'Perl'},
3303
        table => 'book',
3304
        where => {id => 1},
3305
        select_option => {append => 'for update'}
3306
    );
3307
    
3308
    # ID
3309
    $dbi->update_or_insert(
3310
        {title => 'Perl'},
3311
        table => 'book',
3312
        id => 1,
3313
        primary_key => 'id',
3314
        select_option => {append => 'for update'}
3315
    );
3316
    
3317
Update or insert.
3318

            
3319
In both examples, the following SQL is executed.
3320

            
3321
    # In case insert
3322
    insert into book (id, title) values (?, ?)
3323
    
3324
    # In case update
3325
    update book set (id = ?, title = ?) where book.id = ?
3326

            
3327
The following opitons are available adding to C<update> option.
3328

            
3329
=over 4
3330

            
3331
=item C<select_option>
3332

            
3333
    select_option => {append => 'for update'}
3334

            
3335
select method option,
3336
select method is used to check the row is already exists.
3337

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

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

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

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

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

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

            
3358
    $dbi->show_datatype($table);
3359

            
3360
Show data type of the columns of specified table.
3361

            
3362
    book
3363
    title: 5
3364
    issue_date: 91
3365

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

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

            
3370
    $dbi->show_tables;
3371

            
3372
Show tables.
3373

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

            
3376
    $dbi->show_typename($table);
3377

            
3378
Show type name of the columns of specified table.
3379

            
3380
    book
3381
    title: varchar
3382
    issue_date: date
3383

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

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

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

            
3390
Create values clause.
3391

            
3392
    (title, author) values (title = :title, age = :age);
3393

            
3394
You can use this in insert statement.
3395

            
3396
    my $insert_sql = "insert into book $values_clause";
3397

            
3398
=head2 C<where>
3399

            
3400
    my $where = $dbi->where(
3401
        clause => ['and', 'title = :title', 'author = :author'],
3402
        param => {title => 'Perl', author => 'Ken'}
3403
    );
3404

            
3405
Create a new L<DBIx::Custom::Where> object.
3406

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

            
3409
=head2 C<DBIX_CUSTOM_DEBUG>
3410

            
3411
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3412
executed SQL and bind values are printed to STDERR.
3413

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

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

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

            
3420
L<DBIx::Custom>
3421

            
3422
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3423
    default_dbi_option # will be removed 2017/1/1
3424
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3425
    data_source # will be removed at 2017/1/1
3426
    dbi_options # will be removed at 2017/1/1
3427
    filter_check # will be removed at 2017/1/1
3428
    reserved_word_quote # will be removed at 2017/1/1
3429
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3430
    
3431
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3432
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3433
    assign_param # will be removed at 2017/1/1
3434
    update_param # will be removed at 2017/1/1
3435
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3436
    create_query # will be removed at 2017/1/1
3437
    apply_filter # will be removed at 2017/1/1
3438
    select_at # will be removed at 2017/1/1
3439
    delete_at # will be removed at 2017/1/1
3440
    update_at # will be removed at 2017/1/1
3441
    insert_at # will be removed at 2017/1/1
3442
    register_tag # will be removed at 2017/1/1
3443
    default_bind_filter # will be removed at 2017/1/1
3444
    default_fetch_filter # will be removed at 2017/1/1
3445
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3446
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3447
    register_tag_processor # will be removed at 2017/1/1
3448
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3449
    
3450
    # Options
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3451
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3452
    select method relation option # will be removed at 2017/1/1
3453
    select method param option # will be removed at 2017/1/1
3454
    select method column option [COLUMN, as => ALIAS] format
3455
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3456
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3457
    
3458
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3459
    execute("select * from {= title}"); # execute method's
3460
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3461
                                        # will be removed at 2017/1/1
3462
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3463

            
3464
L<DBIx::Custom::Model>
3465

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3466
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3467
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3468
    filter # will be removed at 2017/1/1
3469
    name # will be removed at 2017/1/1
3470
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3471

            
3472
L<DBIx::Custom::Query>
3473
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3474
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3475
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3476
    table # will be removed at 2017/1/1
3477
    filters # will be removed at 2017/1/1
3478
    
3479
    # Methods
3480
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3481

            
3482
L<DBIx::Custom::QueryBuilder>
3483
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3484
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3485
    tags # will be removed at 2017/1/1
3486
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3488
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3489
    register_tag # will be removed at 2017/1/1
3490
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3491
    
3492
    # Others
3493
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3494
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3495

            
3496
L<DBIx::Custom::Result>
3497
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3498
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3499
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3500
    
3501
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3502
    end_filter # will be removed at 2017/1/1
3503
    remove_end_filter # will be removed at 2017/1/1
3504
    remove_filter # will be removed at 2017/1/1
3505
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3506

            
3507
L<DBIx::Custom::Tag>
3508

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

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

            
3513
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3514
except for attribute method.
3515
You can check all DEPRECATED functionalities by document.
3516
DEPRECATED functionality is removed after five years,
3517
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
3518
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3519

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

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

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

            
3526
C<< <kimoto.yuki at gmail.com> >>
3527

            
3528
L<http://github.com/yuki-kimoto/DBIx-Custom>
3529

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3530
=head1 AUTHOR
3531

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

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

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

            
3538
This program is free software; you can redistribute it and/or modify it
3539
under the same terms as Perl itself.
3540

            
3541
=cut