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

            
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
4
our $VERSION = '0.1733';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
628
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
629
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
630
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
631
        $param = $self->merge_param($id_param, $param);
632
    }
633

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
645
sub update_or_insert {
646
    my $self = shift;
647

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
681
sub insert_timestamp {
682
    my $self = shift;
683
    
684
    if (@_) {
685
        $self->{insert_timestamp} = [@_];
686
        
687
        return $self;
688
    }
689
    return $self->{insert_timestamp};
690
}
691

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
692
sub include_model {
693
    my ($self, $name_space, $model_infos) = @_;
694
    
cleanup
Yuki Kimoto authored on 2011-04-02
695
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
696
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
697
    
698
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
699
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
700

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
759
sub mapper {
760
    my $self = shift;
761
    return DBIx::Custom::Mapper->new(@_);
762
}
763

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

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

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

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

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

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-08-10
997
sub show_datatype {
998
    my ($self, $table) = @_;
999
    croak "Table name must be specified" unless defined $table;
1000
    print "$table\n";
1001
    
1002
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1003
    my $sth = $result->sth;
1004

            
1005
    my $columns = $sth->{NAME};
1006
    my $data_types = $sth->{TYPE};
1007
    
1008
    for (my $i = 0; $i < @$columns; $i++) {
1009
        my $column = $columns->[$i];
1010
        my $data_type = $data_types->[$i];
1011
        print "$column: $data_type\n";
1012
    }
1013
}
1014

            
1015
sub show_typename {
1016
    my ($self, $t) = @_;
1017
    croak "Table name must be specified" unless defined $t;
1018
    print "$t\n";
1019
    
1020
    $self->each_column(sub {
1021
        my ($self, $table, $column, $infos) = @_;
1022
        return unless $table eq $t;
1023
        my $typename = $infos->{TYPE_NAME};
1024
        print "$column: $typename\n";
1025
    });
1026
    
1027
    return $self;
1028
}
1029

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1030
sub show_tables {
1031
    my $self = shift;
1032
    
1033
    my %tables;
1034
    $self->each_table(sub { $tables{$_[1]}++ });
1035
    print join("\n", sort keys %tables) . "\n";
1036
    return $self;
1037
}
1038

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1074
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1075
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1076
                }
1077
            });
1078
        }
1079

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

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

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

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

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

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1175
sub update_timestamp {
1176
    my $self = shift;
1177
    
1178
    if (@_) {
1179
        $self->{update_timestamp} = [@_];
1180
        
1181
        return $self;
1182
    }
1183
    return $self->{update_timestamp};
1184
}
1185

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

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

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

            
1240
        # Create query
1241
        my $builder = $self->query_builder;
1242
        $query = $builder->build_query($source);
1243

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

            
1250
        # Save query to cache
1251
        $self->cache_method->(
1252
            $self, $source,
1253
            {
1254
                sql     => $query->sql, 
1255
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1256
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1257
            }
1258
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1259
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1260

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

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1416
sub _need_tables {
1417
    my ($self, $tree, $need_tables, $tables) = @_;
1418
    
cleanup
Yuki Kimoto authored on 2011-04-02
1419
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1420
    foreach my $table (@$tables) {
1421
        if ($tree->{$table}) {
1422
            $need_tables->{$table} = 1;
1423
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1424
        }
1425
    }
1426
}
1427

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1428
sub _option {
1429
    my $self = shift;
1430
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1431
    warn "dbi_options is DEPRECATED! use option instead\n"
1432
      if keys %{$self->dbi_options};
1433
    warn "dbi_option is DEPRECATED! use option instead\n"
1434
      if keys %{$self->dbi_option};
1435
    return $option;
1436
}
1437

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1508
sub _quote {
1509
    my $self = shift;
1510
    
1511
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1512
         : defined $self->quote ? $self->quote
1513
         : '';
1514
}
1515

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

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

            
1548
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1549
}
1550

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1687
# DEPRECATED!
1688
has 'data_source';
1689
has dbi_options => sub { {} };
1690
has filter_check  => 1;
1691
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1692
has dbi_option => sub { {} };
1693
has default_dbi_option => sub {
1694
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1695
    return shift->default_option;
1696
};
1697

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1698
# DEPRECATED!
1699
sub method {
1700
    warn "method is DEPRECATED! use helper instead";
1701
    return shift->helper(@_);
1702
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1703

            
1704
# DEPRECATED!
1705
sub assign_param {
1706
    my $self = shift;
1707
    warn "assing_param is DEPRECATED! use assign_clause instead";
1708
    return $self->assign_clause(@_);
1709
}
1710

            
1711
# DEPRECATED
1712
sub update_param {
1713
    my ($self, $param, $opts) = @_;
1714
    
1715
    warn "update_param is DEPRECATED! use assing_clause instead.";
1716
    
1717
    # Create update parameter tag
1718
    my $tag = $self->assign_clause($param, $opts);
1719
    $tag = "set $tag" unless $opts->{no_set};
1720

            
1721
    return $tag;
1722
}
1723

            
updated pod
Yuki Kimoto authored on 2011-06-21
1724
# DEPRECATED!
1725
sub create_query {
1726
    warn "create_query is DEPRECATED! use query option of each method";
1727
    shift->_create_query(@_);
1728
}
1729

            
cleanup
Yuki Kimoto authored on 2011-06-13
1730
# DEPRECATED!
1731
sub apply_filter {
1732
    my $self = shift;
1733
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1734
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1735
    return $self->_apply_filter(@_);
1736
}
1737

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1738
# DEPRECATED!
1739
sub select_at {
1740
    my ($self, %args) = @_;
1741

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

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

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1761
# DEPRECATED!
1762
sub delete_at {
1763
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1764

            
1765
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1766
    
1767
    # Arguments
1768
    my $primary_keys = delete $args{primary_key};
1769
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1770
    my $where = delete $args{where};
1771
    
1772
    # Create where parameter
1773
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1774
    
1775
    return $self->delete(where => $where_param, %args);
1776
}
1777

            
cleanup
Yuki Kimoto authored on 2011-06-08
1778
# DEPRECATED!
1779
sub update_at {
1780
    my $self = shift;
1781

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1870
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1871
sub default_fetch_filter {
1872
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1873

            
cleanup
Yuki Kimoto authored on 2011-06-13
1874
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1875
    
1876
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1877
        my $fname = $_[0];
1878

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1895
# DEPRECATED!
1896
sub insert_param {
1897
    my $self = shift;
1898
    warn "insert_param is DEPRECATED! use values_clause instead";
1899
    return $self->values_clause(@_);
1900
}
1901

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1953
=head1 NAME
1954

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2028
Named place holder support
2029

            
2030
=item *
2031

            
cleanup
Yuki Kimoto authored on 2011-07-29
2032
Model support
2033

            
2034
=item *
2035

            
2036
Connection manager support
2037

            
2038
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2039

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

            
2044
=item *
2045

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

            
2048
=item *
2049

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

            
2052
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2053

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2061
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2062
L<DBIx::Custom::Result>,
2063
L<DBIx::Custom::Query>,
2064
L<DBIx::Custom::Where>,
2065
L<DBIx::Custom::Model>,
2066
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2067

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

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

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

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

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

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

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

            
2093
    my $dbi = DBIx::Custom->connect(
2094
      dsn => $dsn, user => $user, password => $password, connector => 1);
2095
    
2096
    my $connector = $dbi->connector; # DBIx::Connector
2097

            
2098
Note that L<DBIx::Connector> must be installed.
2099

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2115
    {
2116
        RaiseError => 1,
2117
        PrintError => 0,
2118
        AutoCommit => 1,
2119
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2120

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

            
2123
    my $exclude_table = $dbi->exclude_table;
2124
    $dbi = $dbi->exclude_table(qr/pg_/);
2125

            
2126
Excluded table regex.
2127
C<each_column>, C<each_table>, C<type_rule>,
2128
and C<setup_model> methods ignore matching tables.
2129

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

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

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

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

            
2139
    my $last_sql = $dbi->last_sql;
2140
    $dbi = $dbi->last_sql($last_sql);
2141

            
2142
Get last successed SQL executed by C<execute> method.
2143

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

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

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

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

            
2153
    my $option = $dbi->option;
2154
    $dbi = $dbi->option($option);
2155

            
2156
L<DBI> option, used when C<connect> method is executed.
2157
Each value in option override the value of C<default_option>.
2158

            
cleanup
yuki-kimoto authored on 2010-10-17
2159
=head2 C<password>
2160

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2181
You can set quote pair.
2182

            
2183
    $dbi->quote('[]');
2184

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

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

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

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

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

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

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

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

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

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

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

            
2213
    my $tag_parse = $dbi->tag_parse(0);
2214
    $dbi = $dbi->tag_parse;
2215

            
2216
Enable DEPRECATED tag parsing functionality, default to 1.
2217
If you want to disable tag parsing functionality, set to 0.
2218

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

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

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

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

            
2228
    my $user_column_info = $dbi->user_column_info;
2229
    $dbi = $dbi->user_column_info($user_column_info);
2230

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

            
2233
    [
2234
        {table => 'book', column => 'title', info => {...}},
2235
        {table => 'author', column => 'name', info => {...}}
2236
    ]
2237

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

            
2240
    my $user_column_info
2241
      = $dbi->get_column_info(exclude_table => qr/^system/);
2242
    $dbi->user_column_info($user_column_info);
2243

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

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

            
2249
    my $user_table_info = $dbi->user_table_info;
2250
    $dbi = $dbi->user_table_info($user_table_info);
2251

            
2252
You can set the following data.
2253

            
2254
    [
2255
        {table => 'book', info => {...}},
2256
        {table => 'author', info => {...}}
2257
    ]
2258

            
2259
Usually, you can set return value of C<get_table_info>.
2260

            
2261
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2262
    $dbi->user_table_info($user_table_info);
2263

            
2264
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2265
to find table info.
2266

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2303
Create column clause. The follwoing column clause is created.
2304

            
2305
    book.author as "book.author",
2306
    book.title as "book.title"
2307

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

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

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

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

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

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

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

            
2335
Get rows count.
2336

            
2337
Options is same as C<select> method's ones.
2338

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

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

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

            
2352
   $dbi->model('book')->select(...);
2353

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

            
2356
    my $dbh = $dbi->dbh;
2357

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

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

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

            
2365
Execute delete statement.
2366

            
2367
The following opitons are available.
2368

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

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

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

            
2376
=item C<id>
2377

            
2378
    id => 4
2379
    id => [4, 5]
2380

            
2381
ID corresponding to C<primary_key>.
2382
You can delete rows by C<id> and C<primary_key>.
2383

            
2384
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2385
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2386
        id => [4, 5],
2387
        table => 'book',
2388
    );
2389

            
2390
The above is same as the followin one.
2391

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

            
2394
=item C<prefix>
2395

            
2396
    prefix => 'some'
2397

            
2398
prefix before table name section.
2399

            
2400
    delete some from book
2401

            
2402
=item C<table>
2403

            
2404
    table => 'book'
2405

            
2406
Table name.
2407

            
2408
=item C<where>
2409

            
2410
Same as C<select> method's C<where> option.
2411

            
2412
=back
2413

            
2414
=head2 C<delete_all>
2415

            
2416
    $dbi->delete_all(table => $table);
2417

            
2418
Execute delete statement for all rows.
2419
Options is same as C<delete>.
2420

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

            
2423
    $dbi->each_column(
2424
        sub {
2425
            my ($dbi, $table, $column, $column_info) = @_;
2426
            
2427
            my $type = $column_info->{TYPE_NAME};
2428
            
2429
            if ($type eq 'DATE') {
2430
                # ...
2431
            }
2432
        }
2433
    );
2434

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

            
2440
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2441
infromation, you can improve the performance of C<each_column> in
2442
the following way.
2443

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

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

            
2450
    $dbi->each_table(
2451
        sub {
2452
            my ($dbi, $table, $table_info) = @_;
2453
            
2454
            my $table_name = $table_info->{TABLE_NAME};
2455
        }
2456
    );
2457

            
improved pod
Yuki Kimoto authored on 2011-10-14
2458
Iterate all table informationsfrom in database.
2459
Argument is callback which is executed when one table is found.
2460
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2461
C<table information>.
2462

            
2463
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2464
infromation, you can improve the performance of C<each_table> in
2465
the following way.
2466

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

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

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

            
2478
    my $result = $dbi->execute(
2479
      "select * from book where title = :book.title and author like :book.author",
2480
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2481
    );
2482

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2489
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2490
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2491
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2492
    select * from book where title = :title and author like :author
2493
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2494
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2495
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2496

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2500
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2501
    select * from book where :title{=} and :author{like}
2502
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2503
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2504
    select * from where title = ? and author like ?;
2505

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

            
2510
    select * from where title = "aa\\:bb";
2511

            
cleanup
Yuki Kimoto authored on 2011-10-20
2512
B<OPTIONS>
2513

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

            
2516
=over 4
2517

            
cleanup
Yuki Kimoto authored on 2011-10-20
2518
=item C<append>
2519

            
2520
    append => 'order by name'
2521

            
2522
Append some statement after SQL.
2523

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

            
2526
Specify database bind data type.
2527

            
2528
    bind_type => [image => DBI::SQL_BLOB]
2529
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2530

            
2531
This is used to bind parameter by C<bind_param> of statment handle.
2532

            
2533
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2534

            
update pod
Yuki Kimoto authored on 2011-03-13
2535
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2536
    
2537
    filter => {
2538
        title  => sub { uc $_[0] }
2539
        author => sub { uc $_[0] }
2540
    }
update pod
Yuki Kimoto authored on 2011-03-13
2541

            
updated pod
Yuki Kimoto authored on 2011-06-09
2542
    # Filter name
2543
    filter => {
2544
        title  => 'upper_case',
2545
        author => 'upper_case'
2546
    }
2547
        
2548
    # At once
2549
    filter => [
2550
        [qw/title author/]  => sub { uc $_[0] }
2551
    ]
2552

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

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

            
2560
    id => 4
2561
    id => [4, 5]
2562

            
2563
ID corresponding to C<primary_key>.
2564
You can delete rows by C<id> and C<primary_key>.
2565

            
2566
    $dbi->execute(
2567
        "select * from book where id1 = :id1 and id2 = :id2",
2568
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2569
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2570
        id => [4, 5],
2571
    );
2572

            
2573
The above is same as the followin one.
2574

            
2575
    $dbi->execute(
2576
        "select * from book where id1 = :id1 and id2 = :id2",
2577
        {id1 => 4, id2 => 5}
2578
    );
2579

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

            
2582
    query => 1
2583

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

            
2587
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2588
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2589
    my $columns = $query->columns;
2590
    
2591
If you want to execute SQL fast, you can do the following way.
2592

            
2593
    my $query;
2594
    foreach my $row (@$rows) {
2595
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2596
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2597
    }
2598

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

            
2602
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
2603
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2604
    
2605
    my $query;
2606
    my $sth;
2607
    foreach my $row (@$rows) {
2608
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2609
      $sth ||= $query->sth;
2610
      $sth->execute(map { $row->{$_} } sort keys %$row);
2611
    }
2612

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2619
    primary_key => 'id'
2620
    primary_key => ['id1', 'id2']
2621

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

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

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

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

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

            
2632
    $dbi->select(
2633
        table => 'book',
2634
        column => 'distinct(name)',
2635
        after_build_sql => sub {
2636
            "select count(*) from ($_[0]) as t1"
2637
        }
2638
    );
2639

            
2640
The following SQL is executed.
2641

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2644
=item C<table>
2645
    
2646
    table => 'author'
2647

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2655
    # Same
2656
    $dbi->execute(
2657
      "select * from book where title = :book.title and author = :book.author",
2658
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2659

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

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

            
2664
Table alias. Key is real table name, value is alias table name.
2665
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2666
on alias table name.
2667

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

            
2670
    type_rule_off => 1
2671

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

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

            
2676
    type_rule1_off => 1
2677

            
2678
Turn C<into1> type rule off.
2679

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

            
2682
    type_rule2_off => 1
2683

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

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

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

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

            
2692
get column infomation except for one which match C<exclude_table> pattern.
2693

            
2694
    [
2695
        {table => 'book', column => 'title', info => {...}},
2696
        {table => 'author', column => 'name' info => {...}}
2697
    ]
2698

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

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

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

            
2705
    [
2706
        {table => 'book', info => {...}},
2707
        {table => 'author', info => {...}}
2708
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2709

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

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

            
2714
    $dbi->helper(
2715
        update_or_insert => sub {
2716
            my $self = shift;
2717
            
2718
            # Process
2719
        },
2720
        find_or_create   => sub {
2721
            my $self = shift;
2722
            
2723
            # Process
2724
        }
2725
    );
2726

            
2727
Register helper. These helper is called directly from L<DBIx::Custom> object.
2728

            
2729
    $dbi->update_or_insert;
2730
    $dbi->find_or_create;
2731

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2744
B<options>
2745

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

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

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

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

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

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

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

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

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

            
2775
    prefix => 'or replace'
2776

            
2777
prefix before table name section
2778

            
2779
    insert or replace into book
2780

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

            
2783
    table => 'book'
2784

            
2785
Table name.
2786

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

            
2789
    timestamp => 1
2790

            
2791
If this value is set to 1,
2792
automatically created timestamp column is set based on
2793
C<timestamp> attribute's C<insert> value.
2794

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

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

            
2799
placeholder wrapped string.
2800

            
2801
If the following statement
2802

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

            
2806
is executed, the following SQL is executed.
2807

            
2808
    insert into book price values ( ? + 5 );
2809

            
update pod
Yuki Kimoto authored on 2011-03-13
2810
=back
2811

            
2812
=over 4
2813

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2821
    lib / MyModel.pm
2822
        / MyModel / book.pm
2823
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2824

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

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

            
2829
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2830
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2831
    
2832
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2833

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2838
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2839
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2840
    
2841
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2842

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2845
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2846
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2847
    
2848
    1;
2849
    
updated pod
Yuki Kimoto authored on 2011-06-21
2850
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2851

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

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

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

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

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

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

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

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

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

            
2877
    my $like_value = $dbi->like_value
2878

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

            
2881
    sub { "%$_[0]%" }
2882

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

            
2885
    my $mapper = $dbi->mapper(param => $param);
2886

            
2887
Create a new L<DBIx::Custom::Mapper> object.
2888

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

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

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

            
2895
    {key1 => [1, 1], key2 => 2}
2896

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

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

            
2901
    my $model = $dbi->model('book');
2902

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

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

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

            
2910
Create column clause for myself. The follwoing column clause is created.
2911

            
2912
    book.author as author,
2913
    book.title as title
2914

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

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

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

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

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

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

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

            
2935
    my $order = $dbi->order;
2936

            
2937
Create a new L<DBIx::Custom::Order> object.
2938

            
cleanup
yuki-kimoto authored on 2010-10-17
2939
=head2 C<register_filter>
2940

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2958
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2959
        table  => 'book',
2960
        column => ['author', 'title'],
2961
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2962
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2963
    
updated document
Yuki Kimoto authored on 2011-06-09
2964
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2965

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2973
=item C<column>
2974
    
updated document
Yuki Kimoto authored on 2011-06-09
2975
    column => 'author'
2976
    column => ['author', 'title']
2977

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2986
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2987
        {book => [qw/author title/]},
2988
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2989
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2990

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

            
2993
    book.author as "book.author",
2994
    book.title as "book.title",
2995
    person.name as "person.name",
2996
    person.age as "person.age"
2997

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

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

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

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

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

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

            
3013
=item C<id>
3014

            
3015
    id => 4
3016
    id => [4, 5]
3017

            
3018
ID corresponding to C<primary_key>.
3019
You can select rows by C<id> and C<primary_key>.
3020

            
3021
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3022
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3023
        id => [4, 5],
3024
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3025
    );
3026

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3029
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3030
        where => {id1 => 4, id2 => 5},
3031
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3032
    );
3033
    
cleanup
Yuki Kimoto authored on 2011-10-20
3034
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3035

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

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

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

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

            
3048
    prefix => 'SQL_CALC_FOUND_ROWS'
3049

            
3050
Prefix of column cluase
3051

            
3052
    select SQL_CALC_FOUND_ROWS title, author from book;
3053

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

            
3056
    join => [
3057
        'left outer join company on book.company_id = company_id',
3058
        'left outer join location on company.location_id = location.id'
3059
    ]
3060
        
3061
Join clause. If column cluase or where clause contain table name like "company.name",
3062
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3063

            
3064
    $dbi->select(
3065
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3066
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3067
        where => {'company.name' => 'Orange'},
3068
        join => [
3069
            'left outer join company on book.company_id = company.id',
3070
            'left outer join location on company.location_id = location.id'
3071
        ]
3072
    );
3073

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3077
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3078
    from book
3079
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3080
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3081

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3082
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
3083
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3084

            
3085
    $dbi->select(
3086
        table => 'book',
3087
        column => ['company.location_id as location_id'],
3088
        where => {'company.name' => 'Orange'},
3089
        join => [
3090
            {
3091
                clause => 'left outer join location on company.location_id = location.id',
3092
                table => ['company', 'location']
3093
            }
3094
        ]
3095
    );
3096

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3101
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3102

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3129
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3130
    
update pod
Yuki Kimoto authored on 2011-03-12
3131
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3132

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

            
3135
    $dbi->setup_model;
3136

            
3137
Setup all model objects.
3138
C<columns> of model object is automatically set, parsing database information.
3139

            
3140
=head2 C<type_rule>
3141

            
3142
    $dbi->type_rule(
3143
        into1 => {
3144
            date => sub { ... },
3145
            datetime => sub { ... }
3146
        },
3147
        into2 => {
3148
            date => sub { ... },
3149
            datetime => sub { ... }
3150
        },
3151
        from1 => {
3152
            # DATE
3153
            9 => sub { ... },
3154
            # DATETIME or TIMESTAMP
3155
            11 => sub { ... },
3156
        }
3157
        from2 => {
3158
            # DATE
3159
            9 => sub { ... },
3160
            # DATETIME or TIMESTAMP
3161
            11 => sub { ... },
3162
        }
3163
    );
3164

            
3165
Filtering rule when data is send into and get from database.
3166
This has a little complex problem.
3167

            
3168
In C<into1> and C<into2> you can specify
3169
type name as same as type name defined
3170
by create table, such as C<DATETIME> or C<DATE>.
3171

            
3172
Note that type name and data type don't contain upper case.
3173
If these contain upper case charactor, you convert it to lower case.
3174

            
3175
C<into2> is executed after C<into1>.
3176

            
3177
Type rule of C<into1> and C<into2> is enabled on the following
3178
column name.
3179

            
3180
=over 4
3181

            
3182
=item 1. column name
3183

            
3184
    issue_date
3185
    issue_datetime
3186

            
3187
This need C<table> option in each method.
3188

            
3189
=item 2. table name and column name, separator is dot
3190

            
3191
    book.issue_date
3192
    book.issue_datetime
3193

            
3194
=back
3195

            
3196
You get all type name used in database by C<available_typename>.
3197

            
3198
    print $dbi->available_typename;
3199

            
3200
In C<from1> and C<from2> you specify data type, not type name.
3201
C<from2> is executed after C<from1>.
3202
You get all data type by C<available_datatype>.
3203

            
3204
    print $dbi->available_datatype;
3205

            
3206
You can also specify multiple types at once.
3207

            
3208
    $dbi->type_rule(
3209
        into1 => [
3210
            [qw/DATE DATETIME/] => sub { ... },
3211
        ],
3212
    );
3213

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

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

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

            
3220
If you want to set constant value to row data, use scalar reference
3221
as parameter value.
3222

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3234
    id => 4
3235
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3236

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3240
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3241
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3242
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3243
        id => [4, 5],
3244
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3245
    );
update pod
Yuki Kimoto authored on 2011-03-13
3246

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3249
    $dbi->update(
3250
        {title => 'Perl', author => 'Ken'}
3251
        where => {id1 => 4, id2 => 5},
3252
        table => 'book'
3253
    );
update pod
Yuki Kimoto authored on 2011-03-13
3254

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

            
3257
    prefix => 'or replace'
3258

            
3259
prefix before table name section
3260

            
3261
    update or replace book
3262

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

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

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

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

            
3271
    timestamp => 1
3272

            
3273
If this value is set to 1,
3274
automatically updated timestamp column is set based on
3275
C<timestamp> attribute's C<update> value.
3276

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

            
3279
Same as C<select> method's C<where> option.
3280

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

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

            
3285
placeholder wrapped string.
3286

            
3287
If the following statement
3288

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

            
3292
is executed, the following SQL is executed.
3293

            
3294
    update book set price =  ? + 5;
3295

            
updated pod
Yuki Kimoto authored on 2011-06-08
3296
=back
update pod
Yuki Kimoto authored on 2011-03-13
3297

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

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

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

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

            
3326
In both examples, the following SQL is executed.
3327

            
3328
    # In case insert
3329
    insert into book (id, title) values (?, ?)
3330
    
3331
    # In case update
3332
    update book set (id = ?, title = ?) where book.id = ?
3333

            
3334
The following opitons are available adding to C<update> option.
3335

            
3336
=over 4
3337

            
3338
=item C<select_option>
3339

            
3340
    select_option => {append => 'for update'}
3341

            
3342
select method option,
3343
select method is used to check the row is already exists.
3344

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

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

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

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

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

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

            
3365
    $dbi->show_datatype($table);
3366

            
3367
Show data type of the columns of specified table.
3368

            
3369
    book
3370
    title: 5
3371
    issue_date: 91
3372

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

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

            
3377
    $dbi->show_tables;
3378

            
3379
Show tables.
3380

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

            
3383
    $dbi->show_typename($table);
3384

            
3385
Show type name of the columns of specified table.
3386

            
3387
    book
3388
    title: varchar
3389
    issue_date: date
3390

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

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

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

            
3397
Create values clause.
3398

            
3399
    (title, author) values (title = :title, age = :age);
3400

            
3401
You can use this in insert statement.
3402

            
3403
    my $insert_sql = "insert into book $values_clause";
3404

            
3405
=head2 C<where>
3406

            
3407
    my $where = $dbi->where(
3408
        clause => ['and', 'title = :title', 'author = :author'],
3409
        param => {title => 'Perl', author => 'Ken'}
3410
    );
3411

            
3412
Create a new L<DBIx::Custom::Where> object.
3413

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

            
3416
=head2 C<DBIX_CUSTOM_DEBUG>
3417

            
3418
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3419
executed SQL and bind values are printed to STDERR.
3420

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

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

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

            
3427
L<DBIx::Custom>
3428

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

            
3471
L<DBIx::Custom::Model>
3472

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3473
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3474
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3475
    filter # will be removed at 2017/1/1
3476
    name # will be removed at 2017/1/1
3477
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3478

            
3479
L<DBIx::Custom::Query>
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
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3483
    table # will be removed at 2017/1/1
3484
    filters # will be removed at 2017/1/1
3485
    
3486
    # Methods
3487
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3488

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

            
3503
L<DBIx::Custom::Result>
3504
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3505
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3506
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3507
    
3508
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3509
    end_filter # will be removed at 2017/1/1
3510
    remove_end_filter # will be removed at 2017/1/1
3511
    remove_filter # will be removed at 2017/1/1
3512
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3513

            
3514
L<DBIx::Custom::Tag>
3515

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

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

            
3520
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3521
except for attribute method.
3522
You can check all DEPRECATED functionalities by document.
3523
DEPRECATED functionality is removed after five years,
3524
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
3525
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3526

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

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

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

            
3533
C<< <kimoto.yuki at gmail.com> >>
3534

            
3535
L<http://github.com/yuki-kimoto/DBIx-Custom>
3536

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3537
=head1 AUTHOR
3538

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

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

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

            
3545
This program is free software; you can redistribute it and/or modify it
3546
under the same terms as Perl itself.
3547

            
3548
=cut