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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1720
    return $tag;
1721
}
1722

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2029
=item *
2030

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

            
2033
=item *
2034

            
2035
Connection manager support
2036

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

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

            
2043
=item *
2044

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

            
2047
=item *
2048

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2251
You can set the following data.
2252

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2334
Get rows count.
2335

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

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

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

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

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

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

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

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

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

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

            
2364
Execute delete statement.
2365

            
2366
The following opitons are available.
2367

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

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

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

            
2375
=item C<id>
2376

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

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

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

            
2389
The above is same as the followin one.
2390

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

            
2393
=item C<prefix>
2394

            
2395
    prefix => 'some'
2396

            
2397
prefix before table name section.
2398

            
2399
    delete some from book
2400

            
2401
=item C<table>
2402

            
2403
    table => 'book'
2404

            
2405
Table name.
2406

            
2407
=item C<where>
2408

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

            
2411
=back
2412

            
2413
=head2 C<delete_all>
2414

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2515
=over 4
2516

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

            
2519
    append => 'order by name'
2520

            
2521
Append some statement after SQL.
2522

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

            
2525
Specify database bind data type.
2526

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

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

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

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

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

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

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

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

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

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

            
2572
The above is same as the followin one.
2573

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

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

            
2581
    query => 1
2582

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2639
The following SQL is executed.
2640

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

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

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

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

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

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

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

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

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

            
2669
    type_rule_off => 1
2670

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

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

            
2675
    type_rule1_off => 1
2676

            
2677
Turn C<into1> type rule off.
2678

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

            
2681
    type_rule2_off => 1
2682

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2774
    prefix => 'or replace'
2775

            
2776
prefix before table name section
2777

            
2778
    insert or replace into book
2779

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

            
2782
    table => 'book'
2783

            
2784
Table name.
2785

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

            
2788
    timestamp => 1
2789

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

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

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

            
2798
placeholder wrapped string.
2799

            
2800
If the following statement
2801

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

            
2805
is executed, the following SQL is executed.
2806

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

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

            
2811
=over 4
2812

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2876
    my $like_value = $dbi->like_value
2877

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3012
=item C<id>
3013

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

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

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

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

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

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

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

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

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

            
3047
    prefix => 'SQL_CALC_FOUND_ROWS'
3048

            
3049
Prefix of column cluase
3050

            
3051
    select SQL_CALC_FOUND_ROWS title, author from book;
3052

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3134
    $dbi->setup_model;
3135

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

            
3139
=head2 C<type_rule>
3140

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

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

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

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

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

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

            
3179
=over 4
3180

            
3181
=item 1. column name
3182

            
3183
    issue_date
3184
    issue_datetime
3185

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

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

            
3190
    book.issue_date
3191
    book.issue_datetime
3192

            
3193
=back
3194

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

            
3197
    print $dbi->available_typename;
3198

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

            
3203
    print $dbi->available_datatype;
3204

            
3205
You can also specify multiple types at once.
3206

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3256
    prefix => 'or replace'
3257

            
3258
prefix before table name section
3259

            
3260
    update or replace book
3261

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

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

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

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

            
3270
    timestamp => 1
3271

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

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

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

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

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

            
3284
placeholder wrapped string.
3285

            
3286
If the following statement
3287

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

            
3291
is executed, the following SQL is executed.
3292

            
3293
    update book set price =  ? + 5;
3294

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

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

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

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

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

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

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

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

            
3335
=over 4
3336

            
3337
=item C<select_option>
3338

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

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

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

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

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

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

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

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

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

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

            
3368
    book
3369
    title: 5
3370
    issue_date: 91
3371

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

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

            
3376
    $dbi->show_tables;
3377

            
3378
Show tables.
3379

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

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

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

            
3386
    book
3387
    title: varchar
3388
    issue_date: date
3389

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

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

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

            
3396
Create values clause.
3397

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

            
3400
You can use this in insert statement.
3401

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

            
3404
=head2 C<where>
3405

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

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

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

            
3415
=head2 C<DBIX_CUSTOM_DEBUG>
3416

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

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

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

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

            
3426
L<DBIx::Custom>
3427

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

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

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

            
3478
L<DBIx::Custom::Query>
3479
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3480
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3481
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3482
    table # will be removed at 2017/1/1
3483
    filters # will be removed at 2017/1/1
3484
    
3485
    # Methods
3486
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3547
=cut