DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3538 lines | 92.055kb
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
cleanup
Yuki Kimoto authored on 2011-10-21
251
    $where = $self->_id_to_param($id, $primary_key, $table)
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
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) {
cleanup
Yuki Kimoto authored on 2011-10-21
423
        my $id_param = $self->_id_to_param($id, $primary_key, $main_table);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
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;
cleanup
Yuki Kimoto authored on 2011-10-21
602
    my %opt = @_;
603
    warn "insert method param option is DEPRECATED" if $opt{param};
604
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
605
    
606
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
607
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
608
        my $columns = $insert_timestamp->[0];
609
        $columns = [$columns] unless ref $columns eq 'ARRAY';
610
        my $value = $insert_timestamp->[1];
611
        $value = $value->() if ref $value eq 'CODE';
612
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
613
    }
cleanup
Yuki Kimoto authored on 2011-10-21
614
    
615
    # Merge id to parameter
616
    $param = $self->merge_param(
cleanup
Yuki Kimoto authored on 2011-10-21
617
        $self->_id_to_param($opt{id}, $opt{primary_key}), $param)
618
      if defined $opt{id};
cleanup
Yuki Kimoto authored on 2011-10-21
619
    
cleanup
Yuki Kimoto authored on 2011-04-02
620
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
621
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
622
    $sql .= "$opt{prefix} " if defined $opt{prefix};
623
    $sql .= "into " . $self->_q($opt{table}) . " "
624
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
packaging one directory
yuki-kimoto authored on 2009-11-16
625
    
626
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
627
    return $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
628
}
629

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
630
sub update_or_insert {
631
    my $self = shift;
632

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
666
sub insert_timestamp {
667
    my $self = shift;
668
    
669
    if (@_) {
670
        $self->{insert_timestamp} = [@_];
671
        
672
        return $self;
673
    }
674
    return $self->{insert_timestamp};
675
}
676

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
677
sub include_model {
678
    my ($self, $name_space, $model_infos) = @_;
679
    
cleanup
Yuki Kimoto authored on 2011-04-02
680
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
681
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
682
    
683
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
684
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
685

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
744
sub mapper {
745
    my $self = shift;
746
    return DBIx::Custom::Mapper->new(@_);
747
}
748

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

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

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

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

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

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

            
833
sub order {
834
    my $self = shift;
835
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
836
}
837

            
cleanup
yuki-kimoto authored on 2010-10-17
838
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
839
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
840
    
841
    # Register filter
842
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
843
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
844
    
cleanup
Yuki Kimoto authored on 2011-04-02
845
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
846
}
packaging one directory
yuki-kimoto authored on 2009-11-16
847

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1537
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1538
}
1539

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

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

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

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

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

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

            
1693
# DEPRECATED!
1694
sub assign_param {
1695
    my $self = shift;
1696
    warn "assing_param is DEPRECATED! use assign_clause instead";
1697
    return $self->assign_clause(@_);
1698
}
1699

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

            
1710
    return $tag;
1711
}
1712

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1727
# DEPRECATED!
1728
sub select_at {
1729
    my ($self, %args) = @_;
1730

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

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

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1750
# DEPRECATED!
1751
sub delete_at {
1752
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1753

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1767
# DEPRECATED!
1768
sub update_at {
1769
    my $self = shift;
1770

            
1771
    warn "update_at is DEPRECATED! use update and id option instead";
1772
    
1773
    # Arguments
1774
    my $param;
1775
    $param = shift if @_ % 2;
1776
    my %args = @_;
1777
    my $primary_keys = delete $args{primary_key};
1778
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1779
    my $where = delete $args{where};
1780
    my $p = delete $args{param} || {};
1781
    $param  ||= $p;
1782
    
1783
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1784
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1785
    
1786
    return $self->update(where => $where_param, param => $param, %args);
1787
}
1788

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1859
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1860
sub default_fetch_filter {
1861
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1862

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1942
=head1 NAME
1943

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-29
2009
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- 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
Create C<where> clause flexibly
- 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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2017
Named place holder support
2018

            
2019
=item *
2020

            
cleanup
Yuki Kimoto authored on 2011-07-29
2021
Model support
2022

            
2023
=item *
2024

            
2025
Connection manager support
2026

            
2027
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2028

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

            
2033
=item *
2034

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

            
2037
=item *
2038

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

            
2041
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2042

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

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

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

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

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

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

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

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

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

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

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

            
2082
    my $dbi = DBIx::Custom->connect(
2083
      dsn => $dsn, user => $user, password => $password, connector => 1);
2084
    
2085
    my $connector = $dbi->connector; # DBIx::Connector
2086

            
2087
Note that L<DBIx::Connector> must be installed.
2088

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

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

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

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

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

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

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

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

            
2112
    my $exclude_table = $dbi->exclude_table;
2113
    $dbi = $dbi->exclude_table(qr/pg_/);
2114

            
2115
Excluded table regex.
2116
C<each_column>, C<each_table>, C<type_rule>,
2117
and C<setup_model> methods ignore matching tables.
2118

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

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

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

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

            
2128
    my $last_sql = $dbi->last_sql;
2129
    $dbi = $dbi->last_sql($last_sql);
2130

            
2131
Get last successed SQL executed by C<execute> method.
2132

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

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

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

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

            
2142
    my $option = $dbi->option;
2143
    $dbi = $dbi->option($option);
2144

            
2145
L<DBI> option, used when C<connect> method is executed.
2146
Each value in option override the value of C<default_option>.
2147

            
cleanup
yuki-kimoto authored on 2010-10-17
2148
=head2 C<password>
2149

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2170
You can set quote pair.
2171

            
2172
    $dbi->quote('[]');
2173

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2183
    my $safety_character = $dbi->safety_character;
2184
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2185

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

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

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

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

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

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

            
2202
    my $tag_parse = $dbi->tag_parse(0);
2203
    $dbi = $dbi->tag_parse;
2204

            
2205
Enable DEPRECATED tag parsing functionality, default to 1.
2206
If you want to disable tag parsing functionality, set to 0.
2207

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

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

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

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

            
2217
    my $user_column_info = $dbi->user_column_info;
2218
    $dbi = $dbi->user_column_info($user_column_info);
2219

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

            
2222
    [
2223
        {table => 'book', column => 'title', info => {...}},
2224
        {table => 'author', column => 'name', info => {...}}
2225
    ]
2226

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

            
2229
    my $user_column_info
2230
      = $dbi->get_column_info(exclude_table => qr/^system/);
2231
    $dbi->user_column_info($user_column_info);
2232

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

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

            
2238
    my $user_table_info = $dbi->user_table_info;
2239
    $dbi = $dbi->user_table_info($user_table_info);
2240

            
2241
You can set the following data.
2242

            
2243
    [
2244
        {table => 'book', info => {...}},
2245
        {table => 'author', info => {...}}
2246
    ]
2247

            
2248
Usually, you can set return value of C<get_table_info>.
2249

            
2250
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2251
    $dbi->user_table_info($user_table_info);
2252

            
2253
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2254
to find table info.
2255

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2292
Create column clause. The follwoing column clause is created.
2293

            
2294
    book.author as "book.author",
2295
    book.title as "book.title"
2296

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

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

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

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

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

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

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

            
2324
Get rows count.
2325

            
2326
Options is same as C<select> method's ones.
2327

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

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

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

            
2341
   $dbi->model('book')->select(...);
2342

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

            
2345
    my $dbh = $dbi->dbh;
2346

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

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

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

            
2354
Execute delete statement.
2355

            
2356
The following opitons are available.
2357

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

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

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

            
2365
=item C<id>
2366

            
2367
    id => 4
2368
    id => [4, 5]
2369

            
2370
ID corresponding to C<primary_key>.
2371
You can delete rows by C<id> and C<primary_key>.
2372

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

            
2379
The above is same as the followin one.
2380

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

            
2383
=item C<prefix>
2384

            
2385
    prefix => 'some'
2386

            
2387
prefix before table name section.
2388

            
2389
    delete some from book
2390

            
2391
=item C<table>
2392

            
2393
    table => 'book'
2394

            
2395
Table name.
2396

            
2397
=item C<where>
2398

            
2399
Same as C<select> method's C<where> option.
2400

            
2401
=back
2402

            
2403
=head2 C<delete_all>
2404

            
2405
    $dbi->delete_all(table => $table);
2406

            
2407
Execute delete statement for all rows.
2408
Options is same as C<delete>.
2409

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

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

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

            
2429
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2430
infromation, you can improve the performance of C<each_column> in
2431
the following way.
2432

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

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

            
2439
    $dbi->each_table(
2440
        sub {
2441
            my ($dbi, $table, $table_info) = @_;
2442
            
2443
            my $table_name = $table_info->{TABLE_NAME};
2444
        }
2445
    );
2446

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

            
2452
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2453
infromation, you can improve the performance of C<each_table> in
2454
the following way.
2455

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

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

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

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

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

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

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

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

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

            
2499
    select * from where title = "aa\\:bb";
2500

            
cleanup
Yuki Kimoto authored on 2011-10-20
2501
B<OPTIONS>
2502

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

            
2505
=over 4
2506

            
cleanup
Yuki Kimoto authored on 2011-10-20
2507
=item C<append>
2508

            
2509
    append => 'order by name'
2510

            
2511
Append some statement after SQL.
2512

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

            
2515
Specify database bind data type.
2516

            
2517
    bind_type => [image => DBI::SQL_BLOB]
2518
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2519

            
2520
This is used to bind parameter by C<bind_param> of statment handle.
2521

            
2522
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2523

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

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

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

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

            
2549
    id => 4
2550
    id => [4, 5]
2551

            
2552
ID corresponding to C<primary_key>.
2553
You can delete rows by C<id> and C<primary_key>.
2554

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

            
2562
The above is same as the followin one.
2563

            
2564
    $dbi->execute(
2565
        "select * from book where id1 = :id1 and id2 = :id2",
2566
        {id1 => 4, id2 => 5}
2567
    );
2568

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

            
2571
    query => 1
2572

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2608
    primary_key => 'id'
2609
    primary_key => ['id1', 'id2']
2610

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

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

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

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

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

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

            
2629
The following SQL is executed.
2630

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2633
=item C<table>
2634
    
2635
    table => 'author'
2636

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

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

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

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

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

            
2653
Table alias. Key is real table name, value is alias table name.
2654
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2655
on alias table name.
2656

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

            
2659
    type_rule_off => 1
2660

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

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

            
2665
    type_rule1_off => 1
2666

            
2667
Turn C<into1> type rule off.
2668

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

            
2671
    type_rule2_off => 1
2672

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

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

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

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

            
2681
get column infomation except for one which match C<exclude_table> pattern.
2682

            
2683
    [
2684
        {table => 'book', column => 'title', info => {...}},
2685
        {table => 'author', column => 'name' info => {...}}
2686
    ]
2687

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

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

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

            
2694
    [
2695
        {table => 'book', info => {...}},
2696
        {table => 'author', info => {...}}
2697
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2698

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

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

            
2703
    $dbi->helper(
2704
        update_or_insert => sub {
2705
            my $self = shift;
2706
            
2707
            # Process
2708
        },
2709
        find_or_create   => sub {
2710
            my $self = shift;
2711
            
2712
            # Process
2713
        }
2714
    );
2715

            
2716
Register helper. These helper is called directly from L<DBIx::Custom> object.
2717

            
2718
    $dbi->update_or_insert;
2719
    $dbi->find_or_create;
2720

            
cleanup
yuki-kimoto authored on 2010-10-17
2721
=head2 C<insert>
2722

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

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

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

            
2731
    {date => \"NOW()"}
2732

            
cleanup
Yuki Kimoto authored on 2011-10-20
2733
B<options>
2734

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2742
    id => 4
2743
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2744

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

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

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

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

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

            
2764
    prefix => 'or replace'
2765

            
2766
prefix before table name section
2767

            
2768
    insert or replace into book
2769

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

            
2772
    table => 'book'
2773

            
2774
Table name.
2775

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

            
2778
    timestamp => 1
2779

            
2780
If this value is set to 1,
2781
automatically created timestamp column is set based on
2782
C<timestamp> attribute's C<insert> value.
2783

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

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

            
2788
placeholder wrapped string.
2789

            
2790
If the following statement
2791

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

            
2795
is executed, the following SQL is executed.
2796

            
2797
    insert into book price values ( ? + 5 );
2798

            
update pod
Yuki Kimoto authored on 2011-03-13
2799
=back
2800

            
2801
=over 4
2802

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2810
    lib / MyModel.pm
2811
        / MyModel / book.pm
2812
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2813

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2827
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2828
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2829
    
2830
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2831

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

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

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

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

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

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

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

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

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

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

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

            
2866
    my $like_value = $dbi->like_value
2867

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

            
2870
    sub { "%$_[0]%" }
2871

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

            
2874
    my $mapper = $dbi->mapper(param => $param);
2875

            
2876
Create a new L<DBIx::Custom::Mapper> object.
2877

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

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

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

            
2884
    {key1 => [1, 1], key2 => 2}
2885

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

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

            
2890
    my $model = $dbi->model('book');
2891

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

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

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

            
2899
Create column clause for myself. The follwoing column clause is created.
2900

            
2901
    book.author as author,
2902
    book.title as title
2903

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

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

            
2913
Create a new L<DBIx::Custom> object.
2914

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

            
2917
    my $not_exists = $dbi->not_exists;
2918

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

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

            
2924
    my $order = $dbi->order;
2925

            
2926
Create a new L<DBIx::Custom::Order> object.
2927

            
cleanup
yuki-kimoto authored on 2010-10-17
2928
=head2 C<register_filter>
2929

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2975
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2976
        {book => [qw/author title/]},
2977
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2978
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2979

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

            
2982
    book.author as "book.author",
2983
    book.title as "book.title",
2984
    person.name as "person.name",
2985
    person.age as "person.age"
2986

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

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

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

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

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

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

            
3002
=item C<id>
3003

            
3004
    id => 4
3005
    id => [4, 5]
3006

            
3007
ID corresponding to C<primary_key>.
3008
You can select rows by C<id> and C<primary_key>.
3009

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

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

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

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

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

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

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

            
3037
    prefix => 'SQL_CALC_FOUND_ROWS'
3038

            
3039
Prefix of column cluase
3040

            
3041
    select SQL_CALC_FOUND_ROWS title, author from book;
3042

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3066
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3067
    from book
3068
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3069
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3070

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3071
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
3072
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3073

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3090
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3091

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3118
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3119
    
update pod
Yuki Kimoto authored on 2011-03-12
3120
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3121

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

            
3124
    $dbi->setup_model;
3125

            
3126
Setup all model objects.
3127
C<columns> of model object is automatically set, parsing database information.
3128

            
3129
=head2 C<type_rule>
3130

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

            
3154
Filtering rule when data is send into and get from database.
3155
This has a little complex problem.
3156

            
3157
In C<into1> and C<into2> you can specify
3158
type name as same as type name defined
3159
by create table, such as C<DATETIME> or C<DATE>.
3160

            
3161
Note that type name and data type don't contain upper case.
3162
If these contain upper case charactor, you convert it to lower case.
3163

            
3164
C<into2> is executed after C<into1>.
3165

            
3166
Type rule of C<into1> and C<into2> is enabled on the following
3167
column name.
3168

            
3169
=over 4
3170

            
3171
=item 1. column name
3172

            
3173
    issue_date
3174
    issue_datetime
3175

            
3176
This need C<table> option in each method.
3177

            
3178
=item 2. table name and column name, separator is dot
3179

            
3180
    book.issue_date
3181
    book.issue_datetime
3182

            
3183
=back
3184

            
3185
You get all type name used in database by C<available_typename>.
3186

            
3187
    print $dbi->available_typename;
3188

            
3189
In C<from1> and C<from2> you specify data type, not type name.
3190
C<from2> is executed after C<from1>.
3191
You get all data type by C<available_datatype>.
3192

            
3193
    print $dbi->available_datatype;
3194

            
3195
You can also specify multiple types at once.
3196

            
3197
    $dbi->type_rule(
3198
        into1 => [
3199
            [qw/DATE DATETIME/] => sub { ... },
3200
        ],
3201
    );
3202

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

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

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

            
3209
If you want to set constant value to row data, use scalar reference
3210
as parameter value.
3211

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3223
    id => 4
3224
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3225

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

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

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

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

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

            
3246
    prefix => 'or replace'
3247

            
3248
prefix before table name section
3249

            
3250
    update or replace book
3251

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

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

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

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

            
3260
    timestamp => 1
3261

            
3262
If this value is set to 1,
3263
automatically updated timestamp column is set based on
3264
C<timestamp> attribute's C<update> value.
3265

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

            
3268
Same as C<select> method's C<where> option.
3269

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

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

            
3274
placeholder wrapped string.
3275

            
3276
If the following statement
3277

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

            
3281
is executed, the following SQL is executed.
3282

            
3283
    update book set price =  ? + 5;
3284

            
updated pod
Yuki Kimoto authored on 2011-06-08
3285
=back
update pod
Yuki Kimoto authored on 2011-03-13
3286

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

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

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

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

            
3315
In both examples, the following SQL is executed.
3316

            
3317
    # In case insert
3318
    insert into book (id, title) values (?, ?)
3319
    
3320
    # In case update
3321
    update book set (id = ?, title = ?) where book.id = ?
3322

            
3323
The following opitons are available adding to C<update> option.
3324

            
3325
=over 4
3326

            
3327
=item C<select_option>
3328

            
3329
    select_option => {append => 'for update'}
3330

            
3331
select method option,
3332
select method is used to check the row is already exists.
3333

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

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

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

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

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

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

            
3354
    $dbi->show_datatype($table);
3355

            
3356
Show data type of the columns of specified table.
3357

            
3358
    book
3359
    title: 5
3360
    issue_date: 91
3361

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

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

            
3366
    $dbi->show_tables;
3367

            
3368
Show tables.
3369

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

            
3372
    $dbi->show_typename($table);
3373

            
3374
Show type name of the columns of specified table.
3375

            
3376
    book
3377
    title: varchar
3378
    issue_date: date
3379

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

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

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

            
3386
Create values clause.
3387

            
3388
    (title, author) values (title = :title, age = :age);
3389

            
3390
You can use this in insert statement.
3391

            
3392
    my $insert_sql = "insert into book $values_clause";
3393

            
3394
=head2 C<where>
3395

            
3396
    my $where = $dbi->where(
3397
        clause => ['and', 'title = :title', 'author = :author'],
3398
        param => {title => 'Perl', author => 'Ken'}
3399
    );
3400

            
3401
Create a new L<DBIx::Custom::Where> object.
3402

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

            
3405
=head2 C<DBIX_CUSTOM_DEBUG>
3406

            
3407
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3408
executed SQL and bind values are printed to STDERR.
3409

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

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

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

            
3416
L<DBIx::Custom>
3417

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

            
3461
L<DBIx::Custom::Model>
3462

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

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

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

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

            
3504
L<DBIx::Custom::Tag>
3505

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

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

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

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

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

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

            
3523
C<< <kimoto.yuki at gmail.com> >>
3524

            
3525
L<http://github.com/yuki-kimoto/DBIx-Custom>
3526

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3527
=head1 AUTHOR
3528

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

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

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

            
3535
This program is free software; you can redistribute it and/or modify it
3536
under the same terms as Perl itself.
3537

            
3538
=cut