DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3525 lines | 91.538kb
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 {
cleanup
Yuki Kimoto authored on 2011-10-21
233
    my ($self, %opt) = @_;
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-10-21
236
    my $table = $opt{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            = $opt{where} || {};
240
    my $allow_delete_all = $opt{allow_delete_all};
241
    my $where_param      = $opt{where_param} || {};
242
    my $id = $opt{id};
243
    my $primary_key = $opt{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 = $opt{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
249
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
250
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
251
    $where = $self->_id_to_param($id, $primary_key, $table)
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
252
      if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
253
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
254
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
255
        $where_clause = "where " . $where->[0];
256
        $where_param = $where->[1];
257
    }
258
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
259
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
260
        $where_param = keys %$where_param
261
                     ? $self->merge_param($where_param, $where->param)
262
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
263
        
264
        # String where
265
        $where_clause = $where->to_string;
266
    }
267
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
268
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
269
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
270

            
cleanup
Yuki Kimoto authored on 2011-04-02
271
    # Delete statement
micro optimization
Yuki Kimoto authored on 2011-09-30
272
    my $sql;
273
    $sql .= "delete ";
274
    $sql .= "$prefix " if defined $prefix;
275
    $sql .= "from " . $self->_q($table) . " $where_clause ";
packaging one directory
yuki-kimoto authored on 2009-11-16
276
    
277
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
278
    return $self->execute($sql, $where_param, %opt);
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
cleanup
Yuki Kimoto authored on 2011-10-21
289
    my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
290
    $opt->{dbi} = $self;
291
    my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
292
    my $model_name  = delete $opt->{name};
293
    my $model_table = delete $opt->{table};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
294
    $model_name ||= $model_table;
295
    
cleanup
Yuki Kimoto authored on 2011-04-02
296
    # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
297
    my $model = $model_class->new($opt);
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;
cleanup
Yuki Kimoto authored on 2011-10-21
378
    my %opt = @_;
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 = $opt{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 = $opt{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 = $opt{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 = $opt{bind_type} || $opt{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 = $opt{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 => $opt{type_rule1_off},
392
        2 => $opt{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 = $opt{query};
395
    my $table_alias = $opt{table_alias} || {};
396
    my $after_build_sql = $opt{after_build_sql} || $opt{sqlfilter};
397
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
398
    my $id = $opt{id};
399
    my $primary_key = $opt{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 = $opt{append};
cleanup
Yuki Kimoto authored on 2011-10-20
405
    $sql .= $append if defined $append && !ref $sql;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
406
    
cleanup
Yuki Kimoto authored on 2011-10-20
407
    my $query
408
      = ref $sql ? $sql : $self->_create_query($sql, $after_build_sql);
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
409
    
410
    # Save query
411
    $self->last_sql($query->sql);
412

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

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

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

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

            
added test
Yuki Kimoto authored on 2011-08-16
555
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
556
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
557
    
cleanup
Yuki Kimoto authored on 2011-10-21
558
    my $exclude = delete $opt{exclude};
559
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
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 {
cleanup
Yuki Kimoto authored on 2011-10-21
571
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
572
    
cleanup
Yuki Kimoto authored on 2011-10-21
573
    my $exclude_table = delete $opt{exclude_table};
574
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
575
    
576
    my $column_info = [];
577
    $self->each_column(
578
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
579
        exclude_table => $exclude_table
580
    );
581
    
582
    return [
583
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
584
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
585
}
586

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

            
cleanup
yuki-kimoto authored on 2010-10-17
597
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
598
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
599
    
cleanup
yuki-kimoto authored on 2010-10-17
600
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
601
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
602
    my %opt = @_;
603
    warn "insert method param option is DEPRECATED" if $opt{param};
604
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
605
    
606
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
607
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
608
        my $columns = $insert_timestamp->[0];
609
        $columns = [$columns] unless ref $columns eq 'ARRAY';
610
        my $value = $insert_timestamp->[1];
611
        $value = $value->() if ref $value eq 'CODE';
612
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
613
    }
cleanup
Yuki Kimoto authored on 2011-10-21
614
    
615
    # Merge id to parameter
616
    $param = $self->merge_param(
cleanup
Yuki Kimoto authored on 2011-10-21
617
        $self->_id_to_param($opt{id}, $opt{primary_key}), $param)
618
      if defined $opt{id};
cleanup
Yuki Kimoto authored on 2011-10-21
619
    
cleanup
Yuki Kimoto authored on 2011-04-02
620
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
621
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
622
    $sql .= "$opt{prefix} " if defined $opt{prefix};
623
    $sql .= "into " . $self->_q($opt{table}) . " "
624
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
packaging one directory
yuki-kimoto authored on 2009-11-16
625
    
626
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
627
    return $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
628
}
629

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
848
sub select {
cleanup
Yuki Kimoto authored on 2011-10-21
849
    my ($self, %opt) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
850

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1090
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1091
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1092
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1093
    warn "update param option is DEPRECATED!" if $opt{param};
1094
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
1095
    my $where = $opt{where} || {};
1096
    my $where_param = $opt{where_param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1097
    
1098
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1099
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1100
        my $columns = $update_timestamp->[0];
1101
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1102
        my $value = $update_timestamp->[1];
1103
        $value = $value->() if ref $value eq 'CODE';
1104
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1105
    }
1106

            
cleanup
Yuki Kimoto authored on 2011-10-21
1107
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1108
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1109

            
1110
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1111
    $where = $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
1112
      if defined $opt{id};
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1113
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1114
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1115
        $where_clause = "where " . $where->[0];
1116
        $where_param = $where->[1];
1117
    }
1118
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1119
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1120
        $where_param = keys %$where_param
1121
                     ? $self->merge_param($where_param, $where->param)
1122
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1123
        
1124
        # String where
1125
        $where_clause = $where->to_string;
1126
    }
1127
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1128
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1129
      if "$where_clause" eq '' && !$opt{allow_update_all};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1130
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1131
    # Merge param
1132
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1133
    
cleanup
Yuki Kimoto authored on 2011-04-02
1134
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1135
    my $sql = "update ";
1136
    $sql .= "$opt{prefix} " if defined $opt{prefix};
1137
    $sql .= $self->_q($opt{table}) . " set $assign_clause $where_clause ";
cleanup
Yuki Kimoto authored on 2011-01-27
1138
    
cleanup
yuki-kimoto authored on 2010-10-17
1139
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1140
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1141
}
1142

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1145
sub update_timestamp {
1146
    my $self = shift;
1147
    
1148
    if (@_) {
1149
        $self->{update_timestamp} = [@_];
1150
        
1151
        return $self;
1152
    }
1153
    return $self->{update_timestamp};
1154
}
1155

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1156
sub values_clause {
1157
    my ($self, $param, $opts) = @_;
1158
    
1159
    my $wrap = $opts->{wrap} || {};
1160
    
1161
    # Create insert parameter tag
1162
    my $safety = $self->safety_character;
1163
    my @columns;
1164
    my @placeholders;
1165
    foreach my $column (sort keys %$param) {
1166
        croak qq{"$column" is not safety column name } . _subname
1167
          unless $column =~ /^[$safety\.]+$/;
1168
        my $column_quote = $self->_q($column);
1169
        $column_quote =~ s/\./$self->_q(".")/e;
1170
        push @columns, $column_quote;
1171
        
1172
        my $func = $wrap->{$column} || sub { $_[0] };
1173
        push @placeholders,
1174
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1175
        : $func->(":$column");
1176
    }
1177
    
1178
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1179
           '(' . join(', ', @placeholders) . ')'
1180
}
1181

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1184
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1185
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1186
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1187
    
updated pod
Yuki Kimoto authored on 2011-06-21
1188
    # Cache
1189
    my $cache = $self->cache;
1190
    
1191
    # Query
1192
    my $query;
1193
    
1194
    # Get cached query
1195
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1196
        
updated pod
Yuki Kimoto authored on 2011-06-21
1197
        # Get query
1198
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1199
        
updated pod
Yuki Kimoto authored on 2011-06-21
1200
        # Create query
1201
        if ($q) {
1202
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1203
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1204
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1205
    }
1206
    
1207
    # Create query
1208
    unless ($query) {
1209

            
1210
        # Create query
1211
        my $builder = $self->query_builder;
1212
        $query = $builder->build_query($source);
1213

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

            
1220
        # Save query to cache
1221
        $self->cache_method->(
1222
            $self, $source,
1223
            {
1224
                sql     => $query->sql, 
1225
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1226
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1227
            }
1228
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1229
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1230

            
1231
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1232
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1233
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1234
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1235
        $query->sql($sql);
1236
    }
1237
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1238
    # Save sql
1239
    $self->last_sql($query->sql);
1240
    
updated pod
Yuki Kimoto authored on 2011-06-21
1241
    # Prepare statement handle
1242
    my $sth;
1243
    eval { $sth = $self->dbh->prepare($query->{sql})};
1244
    
1245
    if ($@) {
1246
        $self->_croak($@, qq{. Following SQL is executed.\n}
1247
                        . qq{$query->{sql}\n} . _subname);
1248
    }
1249
    
1250
    # Set statement handle
1251
    $query->sth($sth);
1252
    
1253
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1254
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1255
    
1256
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1257
}
1258

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

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

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

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1404
sub _option {
1405
    my $self = shift;
1406
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1407
    warn "dbi_options is DEPRECATED! use option instead\n"
1408
      if keys %{$self->dbi_options};
1409
    warn "dbi_option is DEPRECATED! use option instead\n"
1410
      if keys %{$self->dbi_option};
1411
    return $option;
1412
}
1413

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1484
sub _quote {
1485
    my $self = shift;
1486
    
1487
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1488
         : defined $self->quote ? $self->quote
1489
         : '';
1490
}
1491

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

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

            
1524
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1525
}
1526

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1663
# DEPRECATED!
1664
has 'data_source';
1665
has dbi_options => sub { {} };
1666
has filter_check  => 1;
1667
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1668
has dbi_option => sub { {} };
1669
has default_dbi_option => sub {
1670
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1671
    return shift->default_option;
1672
};
1673

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1674
# DEPRECATED!
1675
sub method {
1676
    warn "method is DEPRECATED! use helper instead";
1677
    return shift->helper(@_);
1678
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1679

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

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

            
1697
    return $tag;
1698
}
1699

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1714
# DEPRECATED!
1715
sub select_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1716
    my ($self, %opt) = @_;
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1717

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1720
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1721
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1722
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1723
    my $where = delete $opt{where};
1724
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1725
    
1726
    # Table
1727
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1728
      unless $opt{table};
1729
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1730
    
1731
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1732
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1733
    
cleanup
Yuki Kimoto authored on 2011-10-21
1734
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1735
}
1736

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1737
# DEPRECATED!
1738
sub delete_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1739
    my ($self, %opt) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1740

            
1741
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1742
    
1743
    # Arguments
cleanup
Yuki Kimoto authored on 2011-10-21
1744
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1745
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1746
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1747
    
1748
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1749
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1750
    
cleanup
Yuki Kimoto authored on 2011-10-21
1751
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1752
}
1753

            
cleanup
Yuki Kimoto authored on 2011-06-08
1754
# DEPRECATED!
1755
sub update_at {
1756
    my $self = shift;
1757

            
1758
    warn "update_at is DEPRECATED! use update and id option instead";
1759
    
1760
    # Arguments
1761
    my $param;
1762
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1763
    my %opt = @_;
1764
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1765
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1766
    my $where = delete $opt{where};
1767
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1768
    $param  ||= $p;
1769
    
1770
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1771
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1772
    
cleanup
Yuki Kimoto authored on 2011-10-21
1773
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1774
}
1775

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1776
# DEPRECATED!
1777
sub insert_at {
1778
    my $self = shift;
1779
    
1780
    warn "insert_at is DEPRECATED! use insert and id option instead";
1781
    
1782
    # Arguments
1783
    my $param;
1784
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1785
    my %opt = @_;
1786
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1787
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1788
    my $where = delete $opt{where};
1789
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1790
    $param  ||= $p;
1791
    
1792
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1793
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1794
    $param = $self->merge_param($where_param, $param);
1795
    
cleanup
Yuki Kimoto authored on 2011-10-21
1796
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1797
}
1798

            
added warnings
Yuki Kimoto authored on 2011-06-07
1799
# DEPRECATED!
1800
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1801
    my $self = shift;
1802
    
added warnings
Yuki Kimoto authored on 2011-06-07
1803
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1804
    
1805
    # Merge tag
1806
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1807
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1808
    
1809
    return $self;
1810
}
1811

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1822
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1823
sub default_bind_filter {
1824
    my $self = shift;
1825
    
cleanup
Yuki Kimoto authored on 2011-06-13
1826
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1827
    
cleanup
Yuki Kimoto authored on 2011-01-12
1828
    if (@_) {
1829
        my $fname = $_[0];
1830
        
1831
        if (@_ && !$fname) {
1832
            $self->{default_out_filter} = undef;
1833
        }
1834
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1835
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1836
              unless exists $self->filters->{$fname};
1837
        
1838
            $self->{default_out_filter} = $self->filters->{$fname};
1839
        }
1840
        return $self;
1841
    }
1842
    
1843
    return $self->{default_out_filter};
1844
}
1845

            
cleanup
Yuki Kimoto authored on 2011-01-25
1846
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1847
sub default_fetch_filter {
1848
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1849

            
cleanup
Yuki Kimoto authored on 2011-06-13
1850
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1851
    
1852
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1853
        my $fname = $_[0];
1854

            
cleanup
Yuki Kimoto authored on 2011-01-12
1855
        if (@_ && !$fname) {
1856
            $self->{default_in_filter} = undef;
1857
        }
1858
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1859
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1860
              unless exists $self->filters->{$fname};
1861
        
1862
            $self->{default_in_filter} = $self->filters->{$fname};
1863
        }
1864
        
1865
        return $self;
1866
    }
1867
    
many changed
Yuki Kimoto authored on 2011-01-23
1868
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1869
}
1870

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1871
# DEPRECATED!
1872
sub insert_param {
1873
    my $self = shift;
1874
    warn "insert_param is DEPRECATED! use values_clause instead";
1875
    return $self->values_clause(@_);
1876
}
1877

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1878
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1879
sub insert_param_tag {
1880
    warn "insert_param_tag is DEPRECATED! " .
1881
         "use insert_param instead!";
1882
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1883
}
1884

            
1885
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1886
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1887
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1888
         "use update_param instead";
1889
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1890
}
cleanup
Yuki Kimoto authored on 2011-03-08
1891
# DEPRECATED!
1892
sub _push_relation {
1893
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1894
    
1895
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1896
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1897
        foreach my $rcolumn (keys %$relation) {
1898
            my $table1 = (split (/\./, $rcolumn))[0];
1899
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1900
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1901
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1902
        }
1903
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1904
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1905
}
1906

            
1907
# DEPRECATED!
1908
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1909
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1910
    
1911
    if (keys %{$relation || {}}) {
1912
        foreach my $rcolumn (keys %$relation) {
1913
            my $table1 = (split (/\./, $rcolumn))[0];
1914
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1915
            my $table1_exists;
1916
            my $table2_exists;
1917
            foreach my $table (@$tables) {
1918
                $table1_exists = 1 if $table eq $table1;
1919
                $table2_exists = 1 if $table eq $table2;
1920
            }
1921
            unshift @$tables, $table1 unless $table1_exists;
1922
            unshift @$tables, $table2 unless $table2_exists;
1923
        }
1924
    }
1925
}
1926

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1929
=head1 NAME
1930

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1935
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1936
    
1937
    # Connect
1938
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1939
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1940
        user => 'ken',
1941
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1942
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1943
    );
cleanup
yuki-kimoto authored on 2010-08-05
1944

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1945
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1946
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1947
    
1948
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1949
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1950
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1951
    
1952
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1953
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1954

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2004
Named place holder support
2005

            
2006
=item *
2007

            
cleanup
Yuki Kimoto authored on 2011-07-29
2008
Model support
2009

            
2010
=item *
2011

            
2012
Connection manager support
2013

            
2014
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2015

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

            
2020
=item *
2021

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

            
2024
=item *
2025

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

            
2028
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2029

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2037
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2038
L<DBIx::Custom::Result>,
2039
L<DBIx::Custom::Query>,
2040
L<DBIx::Custom::Where>,
2041
L<DBIx::Custom::Model>,
2042
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2043

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

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

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

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

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

            
2057
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2058
        "dbi:mysql:database=$database",
2059
        $user,
2060
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2061
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2062
    );
2063
    
updated pod
Yuki Kimoto authored on 2011-06-21
2064
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2065

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

            
2069
    my $dbi = DBIx::Custom->connect(
2070
      dsn => $dsn, user => $user, password => $password, connector => 1);
2071
    
2072
    my $connector = $dbi->connector; # DBIx::Connector
2073

            
2074
Note that L<DBIx::Connector> must be installed.
2075

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2091
    {
2092
        RaiseError => 1,
2093
        PrintError => 0,
2094
        AutoCommit => 1,
2095
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2096

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

            
2099
    my $exclude_table = $dbi->exclude_table;
2100
    $dbi = $dbi->exclude_table(qr/pg_/);
2101

            
2102
Excluded table regex.
2103
C<each_column>, C<each_table>, C<type_rule>,
2104
and C<setup_model> methods ignore matching tables.
2105

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

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

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

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

            
2115
    my $last_sql = $dbi->last_sql;
2116
    $dbi = $dbi->last_sql($last_sql);
2117

            
2118
Get last successed SQL executed by C<execute> method.
2119

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

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

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

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

            
2129
    my $option = $dbi->option;
2130
    $dbi = $dbi->option($option);
2131

            
2132
L<DBI> option, used when C<connect> method is executed.
2133
Each value in option override the value of C<default_option>.
2134

            
cleanup
yuki-kimoto authored on 2010-10-17
2135
=head2 C<password>
2136

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2157
You can set quote pair.
2158

            
2159
    $dbi->quote('[]');
2160

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2170
    my $safety_character = $dbi->safety_character;
2171
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2172

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

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

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

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

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

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

            
2189
    my $tag_parse = $dbi->tag_parse(0);
2190
    $dbi = $dbi->tag_parse;
2191

            
2192
Enable DEPRECATED tag parsing functionality, default to 1.
2193
If you want to disable tag parsing functionality, set to 0.
2194

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

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

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

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

            
2204
    my $user_column_info = $dbi->user_column_info;
2205
    $dbi = $dbi->user_column_info($user_column_info);
2206

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

            
2209
    [
2210
        {table => 'book', column => 'title', info => {...}},
2211
        {table => 'author', column => 'name', info => {...}}
2212
    ]
2213

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

            
2216
    my $user_column_info
2217
      = $dbi->get_column_info(exclude_table => qr/^system/);
2218
    $dbi->user_column_info($user_column_info);
2219

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

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

            
2225
    my $user_table_info = $dbi->user_table_info;
2226
    $dbi = $dbi->user_table_info($user_table_info);
2227

            
2228
You can set the following data.
2229

            
2230
    [
2231
        {table => 'book', info => {...}},
2232
        {table => 'author', info => {...}}
2233
    ]
2234

            
2235
Usually, you can set return value of C<get_table_info>.
2236

            
2237
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2238
    $dbi->user_table_info($user_table_info);
2239

            
2240
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2241
to find table info.
2242

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2279
Create column clause. The follwoing column clause is created.
2280

            
2281
    book.author as "book.author",
2282
    book.title as "book.title"
2283

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2286
    # Separator is hyphen
2287
    $dbi->separator('-');
2288
    
2289
    book.author as "book-author",
2290
    book.title as "book-title"
2291
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2292
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2293

            
update pod
Yuki Kimoto authored on 2011-03-13
2294
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2295
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2296
        user => 'ken',
2297
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2298
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2299
    );
2300

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

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

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

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

            
2311
Get rows count.
2312

            
2313
Options is same as C<select> method's ones.
2314

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2317
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2318
        table => 'book',
2319
        primary_key => 'id',
2320
        join => [
2321
            'inner join company on book.comparny_id = company.id'
2322
        ],
2323
    );
2324

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

            
2328
   $dbi->model('book')->select(...);
2329

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

            
2332
    my $dbh = $dbi->dbh;
2333

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

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

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

            
2341
Execute delete statement.
2342

            
2343
The following opitons are available.
2344

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

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

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

            
2352
=item C<id>
2353

            
2354
    id => 4
2355
    id => [4, 5]
2356

            
2357
ID corresponding to C<primary_key>.
2358
You can delete rows by C<id> and C<primary_key>.
2359

            
2360
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2361
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2362
        id => [4, 5],
2363
        table => 'book',
2364
    );
2365

            
2366
The above is same as the followin one.
2367

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

            
2370
=item C<prefix>
2371

            
2372
    prefix => 'some'
2373

            
2374
prefix before table name section.
2375

            
2376
    delete some from book
2377

            
2378
=item C<table>
2379

            
2380
    table => 'book'
2381

            
2382
Table name.
2383

            
2384
=item C<where>
2385

            
2386
Same as C<select> method's C<where> option.
2387

            
2388
=back
2389

            
2390
=head2 C<delete_all>
2391

            
2392
    $dbi->delete_all(table => $table);
2393

            
2394
Execute delete statement for all rows.
2395
Options is same as C<delete>.
2396

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

            
2399
    $dbi->each_column(
2400
        sub {
2401
            my ($dbi, $table, $column, $column_info) = @_;
2402
            
2403
            my $type = $column_info->{TYPE_NAME};
2404
            
2405
            if ($type eq 'DATE') {
2406
                # ...
2407
            }
2408
        }
2409
    );
2410

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

            
2416
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2417
infromation, you can improve the performance of C<each_column> in
2418
the following way.
2419

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

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

            
2426
    $dbi->each_table(
2427
        sub {
2428
            my ($dbi, $table, $table_info) = @_;
2429
            
2430
            my $table_name = $table_info->{TABLE_NAME};
2431
        }
2432
    );
2433

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

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

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

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

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

            
2454
    my $result = $dbi->execute(
2455
      "select * from book where title = :book.title and author like :book.author",
2456
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2457
    );
2458

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2465
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2466
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2467
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2468
    select * from book where title = :title and author like :author
2469
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2470
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2471
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2472

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2476
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2477
    select * from book where :title{=} and :author{like}
2478
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2479
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2480
    select * from where title = ? and author like ?;
2481

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

            
2486
    select * from where title = "aa\\:bb";
2487

            
cleanup
Yuki Kimoto authored on 2011-10-20
2488
B<OPTIONS>
2489

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

            
2492
=over 4
2493

            
cleanup
Yuki Kimoto authored on 2011-10-20
2494
=item C<append>
2495

            
2496
    append => 'order by name'
2497

            
2498
Append some statement after SQL.
2499

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

            
2502
Specify database bind data type.
2503

            
2504
    bind_type => [image => DBI::SQL_BLOB]
2505
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2506

            
2507
This is used to bind parameter by C<bind_param> of statment handle.
2508

            
2509
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2510

            
update pod
Yuki Kimoto authored on 2011-03-13
2511
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2512
    
2513
    filter => {
2514
        title  => sub { uc $_[0] }
2515
        author => sub { uc $_[0] }
2516
    }
update pod
Yuki Kimoto authored on 2011-03-13
2517

            
updated pod
Yuki Kimoto authored on 2011-06-09
2518
    # Filter name
2519
    filter => {
2520
        title  => 'upper_case',
2521
        author => 'upper_case'
2522
    }
2523
        
2524
    # At once
2525
    filter => [
2526
        [qw/title author/]  => sub { uc $_[0] }
2527
    ]
2528

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

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

            
2536
    id => 4
2537
    id => [4, 5]
2538

            
2539
ID corresponding to C<primary_key>.
2540
You can delete rows by C<id> and C<primary_key>.
2541

            
2542
    $dbi->execute(
2543
        "select * from book where id1 = :id1 and id2 = :id2",
2544
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2545
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2546
        id => [4, 5],
2547
    );
2548

            
2549
The above is same as the followin one.
2550

            
2551
    $dbi->execute(
2552
        "select * from book where id1 = :id1 and id2 = :id2",
2553
        {id1 => 4, id2 => 5}
2554
    );
2555

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

            
2558
    query => 1
2559

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

            
2563
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2564
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2565
    my $columns = $query->columns;
2566
    
2567
If you want to execute SQL fast, you can do the following way.
2568

            
2569
    my $query;
2570
    foreach my $row (@$rows) {
2571
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2572
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2573
    }
2574

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

            
2578
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
2579
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2580
    
2581
    my $query;
2582
    my $sth;
2583
    foreach my $row (@$rows) {
2584
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2585
      $sth ||= $query->sth;
2586
      $sth->execute(map { $row->{$_} } sort keys %$row);
2587
    }
2588

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2595
    primary_key => 'id'
2596
    primary_key => ['id1', 'id2']
2597

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

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

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

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

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

            
2608
    $dbi->select(
2609
        table => 'book',
2610
        column => 'distinct(name)',
2611
        after_build_sql => sub {
2612
            "select count(*) from ($_[0]) as t1"
2613
        }
2614
    );
2615

            
2616
The following SQL is executed.
2617

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2620
=item C<table>
2621
    
2622
    table => 'author'
2623

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2631
    # Same
2632
    $dbi->execute(
2633
      "select * from book where title = :book.title and author = :book.author",
2634
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2635

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

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

            
2640
Table alias. Key is real table name, value is alias table name.
2641
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2642
on alias table name.
2643

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

            
2646
    type_rule_off => 1
2647

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

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

            
2652
    type_rule1_off => 1
2653

            
2654
Turn C<into1> type rule off.
2655

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

            
2658
    type_rule2_off => 1
2659

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

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

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

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

            
2668
get column infomation except for one which match C<exclude_table> pattern.
2669

            
2670
    [
2671
        {table => 'book', column => 'title', info => {...}},
2672
        {table => 'author', column => 'name' info => {...}}
2673
    ]
2674

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

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

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

            
2681
    [
2682
        {table => 'book', info => {...}},
2683
        {table => 'author', info => {...}}
2684
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2685

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

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

            
2690
    $dbi->helper(
2691
        update_or_insert => sub {
2692
            my $self = shift;
2693
            
2694
            # Process
2695
        },
2696
        find_or_create   => sub {
2697
            my $self = shift;
2698
            
2699
            # Process
2700
        }
2701
    );
2702

            
2703
Register helper. These helper is called directly from L<DBIx::Custom> object.
2704

            
2705
    $dbi->update_or_insert;
2706
    $dbi->find_or_create;
2707

            
cleanup
yuki-kimoto authored on 2010-10-17
2708
=head2 C<insert>
2709

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

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

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

            
2718
    {date => \"NOW()"}
2719

            
cleanup
Yuki Kimoto authored on 2011-10-20
2720
B<options>
2721

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2729
    id => 4
2730
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2731

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2735
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2736
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2737
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2738
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2739
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2740
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2741

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

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

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

            
2751
    prefix => 'or replace'
2752

            
2753
prefix before table name section
2754

            
2755
    insert or replace into book
2756

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

            
2759
    table => 'book'
2760

            
2761
Table name.
2762

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

            
2765
    timestamp => 1
2766

            
2767
If this value is set to 1,
2768
automatically created timestamp column is set based on
2769
C<timestamp> attribute's C<insert> value.
2770

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

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

            
2775
placeholder wrapped string.
2776

            
2777
If the following statement
2778

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

            
2782
is executed, the following SQL is executed.
2783

            
2784
    insert into book price values ( ? + 5 );
2785

            
update pod
Yuki Kimoto authored on 2011-03-13
2786
=back
2787

            
2788
=over 4
2789

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2797
    lib / MyModel.pm
2798
        / MyModel / book.pm
2799
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2800

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

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

            
2805
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2806
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2807
    
2808
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2809

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2814
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2815
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2816
    
2817
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2818

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2821
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2822
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2823
    
2824
    1;
2825
    
updated pod
Yuki Kimoto authored on 2011-06-21
2826
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2827

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

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

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

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

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

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

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

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

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

            
2853
    my $like_value = $dbi->like_value
2854

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

            
2857
    sub { "%$_[0]%" }
2858

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

            
2861
    my $mapper = $dbi->mapper(param => $param);
2862

            
2863
Create a new L<DBIx::Custom::Mapper> object.
2864

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

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

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

            
2871
    {key1 => [1, 1], key2 => 2}
2872

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

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

            
2877
    my $model = $dbi->model('book');
2878

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

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

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

            
2886
Create column clause for myself. The follwoing column clause is created.
2887

            
2888
    book.author as author,
2889
    book.title as title
2890

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

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

            
2900
Create a new L<DBIx::Custom> object.
2901

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

            
2904
    my $not_exists = $dbi->not_exists;
2905

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

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

            
2911
    my $order = $dbi->order;
2912

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2915
=head2 C<register_filter>
2916

            
update pod
Yuki Kimoto authored on 2011-03-13
2917
    $dbi->register_filter(
2918
        # Time::Piece object to database DATE format
2919
        tp_to_date => sub {
2920
            my $tp = shift;
2921
            return $tp->strftime('%Y-%m-%d');
2922
        },
2923
        # database DATE format to Time::Piece object
2924
        date_to_tp => sub {
2925
           my $date = shift;
2926
           return Time::Piece->strptime($date, '%Y-%m-%d');
2927
        }
2928
    );
cleanup
yuki-kimoto authored on 2010-10-17
2929
    
update pod
Yuki Kimoto authored on 2011-03-13
2930
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2931

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2934
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2935
        table  => 'book',
2936
        column => ['author', 'title'],
2937
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2938
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2939
    
updated document
Yuki Kimoto authored on 2011-06-09
2940
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2941

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2949
=item C<column>
2950
    
updated document
Yuki Kimoto authored on 2011-06-09
2951
    column => 'author'
2952
    column => ['author', 'title']
2953

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2962
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2963
        {book => [qw/author title/]},
2964
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2965
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2966

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

            
2969
    book.author as "book.author",
2970
    book.title as "book.title",
2971
    person.name as "person.name",
2972
    person.age as "person.age"
2973

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

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

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

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

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

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

            
2989
=item C<id>
2990

            
2991
    id => 4
2992
    id => [4, 5]
2993

            
2994
ID corresponding to C<primary_key>.
2995
You can select rows by C<id> and C<primary_key>.
2996

            
2997
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2998
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2999
        id => [4, 5],
3000
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3001
    );
3002

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3005
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3006
        where => {id1 => 4, id2 => 5},
3007
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3008
    );
3009
    
cleanup
Yuki Kimoto authored on 2011-10-20
3010
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3011

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

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

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

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

            
3024
    prefix => 'SQL_CALC_FOUND_ROWS'
3025

            
3026
Prefix of column cluase
3027

            
3028
    select SQL_CALC_FOUND_ROWS title, author from book;
3029

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

            
3032
    join => [
3033
        'left outer join company on book.company_id = company_id',
3034
        'left outer join location on company.location_id = location.id'
3035
    ]
3036
        
3037
Join clause. If column cluase or where clause contain table name like "company.name",
3038
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3039

            
3040
    $dbi->select(
3041
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3042
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3043
        where => {'company.name' => 'Orange'},
3044
        join => [
3045
            'left outer join company on book.company_id = company.id',
3046
            'left outer join location on company.location_id = location.id'
3047
        ]
3048
    );
3049

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3053
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3054
    from book
3055
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3056
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3057

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3058
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
3059
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3060

            
3061
    $dbi->select(
3062
        table => 'book',
3063
        column => ['company.location_id as location_id'],
3064
        where => {'company.name' => 'Orange'},
3065
        join => [
3066
            {
3067
                clause => 'left outer join location on company.location_id = location.id',
3068
                table => ['company', 'location']
3069
            }
3070
        ]
3071
    );
3072

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3077
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3078

            
updated document
Yuki Kimoto authored on 2011-06-09
3079
=item C<where>
3080
    
3081
    # Hash refrence
3082
    where => {author => 'Ken', 'title' => 'Perl'}
3083
    
3084
    # DBIx::Custom::Where object
3085
    where => $dbi->where(
3086
        clause => ['and', 'author = :author', 'title like :title'],
3087
        param  => {author => 'Ken', title => '%Perl%'}
3088
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3089
    
3090
    # Array reference 1 (array reference, hash referenc). same as above
3091
    where => [
3092
        ['and', 'author = :author', 'title like :title'],
3093
        {author => 'Ken', title => '%Perl%'}
3094
    ];    
3095
    
3096
    # Array reference 2 (String, hash reference)
3097
    where => [
3098
        'title like :title',
3099
        {title => '%Perl%'}
3100
    ]
3101
    
3102
    # String
3103
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3104

            
cleanup
Yuki Kimoto authored on 2011-10-20
3105
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3106
    
update pod
Yuki Kimoto authored on 2011-03-12
3107
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3108

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

            
3111
    $dbi->setup_model;
3112

            
3113
Setup all model objects.
3114
C<columns> of model object is automatically set, parsing database information.
3115

            
3116
=head2 C<type_rule>
3117

            
3118
    $dbi->type_rule(
3119
        into1 => {
3120
            date => sub { ... },
3121
            datetime => sub { ... }
3122
        },
3123
        into2 => {
3124
            date => sub { ... },
3125
            datetime => sub { ... }
3126
        },
3127
        from1 => {
3128
            # DATE
3129
            9 => sub { ... },
3130
            # DATETIME or TIMESTAMP
3131
            11 => sub { ... },
3132
        }
3133
        from2 => {
3134
            # DATE
3135
            9 => sub { ... },
3136
            # DATETIME or TIMESTAMP
3137
            11 => sub { ... },
3138
        }
3139
    );
3140

            
3141
Filtering rule when data is send into and get from database.
3142
This has a little complex problem.
3143

            
3144
In C<into1> and C<into2> you can specify
3145
type name as same as type name defined
3146
by create table, such as C<DATETIME> or C<DATE>.
3147

            
3148
Note that type name and data type don't contain upper case.
3149
If these contain upper case charactor, you convert it to lower case.
3150

            
3151
C<into2> is executed after C<into1>.
3152

            
3153
Type rule of C<into1> and C<into2> is enabled on the following
3154
column name.
3155

            
3156
=over 4
3157

            
3158
=item 1. column name
3159

            
3160
    issue_date
3161
    issue_datetime
3162

            
3163
This need C<table> option in each method.
3164

            
3165
=item 2. table name and column name, separator is dot
3166

            
3167
    book.issue_date
3168
    book.issue_datetime
3169

            
3170
=back
3171

            
3172
You get all type name used in database by C<available_typename>.
3173

            
3174
    print $dbi->available_typename;
3175

            
3176
In C<from1> and C<from2> you specify data type, not type name.
3177
C<from2> is executed after C<from1>.
3178
You get all data type by C<available_datatype>.
3179

            
3180
    print $dbi->available_datatype;
3181

            
3182
You can also specify multiple types at once.
3183

            
3184
    $dbi->type_rule(
3185
        into1 => [
3186
            [qw/DATE DATETIME/] => sub { ... },
3187
        ],
3188
    );
3189

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

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

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

            
3196
If you want to set constant value to row data, use scalar reference
3197
as parameter value.
3198

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3210
    id => 4
3211
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3212

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3216
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3217
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3218
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3219
        id => [4, 5],
3220
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3221
    );
update pod
Yuki Kimoto authored on 2011-03-13
3222

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3225
    $dbi->update(
3226
        {title => 'Perl', author => 'Ken'}
3227
        where => {id1 => 4, id2 => 5},
3228
        table => 'book'
3229
    );
update pod
Yuki Kimoto authored on 2011-03-13
3230

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

            
3233
    prefix => 'or replace'
3234

            
3235
prefix before table name section
3236

            
3237
    update or replace book
3238

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

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

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

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

            
3247
    timestamp => 1
3248

            
3249
If this value is set to 1,
3250
automatically updated timestamp column is set based on
3251
C<timestamp> attribute's C<update> value.
3252

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

            
3255
Same as C<select> method's C<where> option.
3256

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

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

            
3261
placeholder wrapped string.
3262

            
3263
If the following statement
3264

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

            
3268
is executed, the following SQL is executed.
3269

            
3270
    update book set price =  ? + 5;
3271

            
updated pod
Yuki Kimoto authored on 2011-06-08
3272
=back
update pod
Yuki Kimoto authored on 2011-03-13
3273

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3281
=head2 C<update_or_insert EXPERIMENTAL>
3282
    
3283
    # Where
3284
    $dbi->update_or_insert(
3285
        {id => 1, title => 'Perl'},
3286
        table => 'book',
3287
        where => {id => 1},
3288
        select_option => {append => 'for update'}
3289
    );
3290
    
3291
    # ID
3292
    $dbi->update_or_insert(
3293
        {title => 'Perl'},
3294
        table => 'book',
3295
        id => 1,
3296
        primary_key => 'id',
3297
        select_option => {append => 'for update'}
3298
    );
3299
    
3300
Update or insert.
3301

            
3302
In both examples, the following SQL is executed.
3303

            
3304
    # In case insert
3305
    insert into book (id, title) values (?, ?)
3306
    
3307
    # In case update
3308
    update book set (id = ?, title = ?) where book.id = ?
3309

            
3310
The following opitons are available adding to C<update> option.
3311

            
3312
=over 4
3313

            
3314
=item C<select_option>
3315

            
3316
    select_option => {append => 'for update'}
3317

            
3318
select method option,
3319
select method is used to check the row is already exists.
3320

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

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

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

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

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

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

            
3341
    $dbi->show_datatype($table);
3342

            
3343
Show data type of the columns of specified table.
3344

            
3345
    book
3346
    title: 5
3347
    issue_date: 91
3348

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

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

            
3353
    $dbi->show_tables;
3354

            
3355
Show tables.
3356

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

            
3359
    $dbi->show_typename($table);
3360

            
3361
Show type name of the columns of specified table.
3362

            
3363
    book
3364
    title: varchar
3365
    issue_date: date
3366

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

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

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

            
3373
Create values clause.
3374

            
3375
    (title, author) values (title = :title, age = :age);
3376

            
3377
You can use this in insert statement.
3378

            
3379
    my $insert_sql = "insert into book $values_clause";
3380

            
3381
=head2 C<where>
3382

            
3383
    my $where = $dbi->where(
3384
        clause => ['and', 'title = :title', 'author = :author'],
3385
        param => {title => 'Perl', author => 'Ken'}
3386
    );
3387

            
3388
Create a new L<DBIx::Custom::Where> object.
3389

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

            
3392
=head2 C<DBIX_CUSTOM_DEBUG>
3393

            
3394
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3395
executed SQL and bind values are printed to STDERR.
3396

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

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

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

            
3403
L<DBIx::Custom>
3404

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

            
3448
L<DBIx::Custom::Model>
3449

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3450
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3451
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3452
    filter # will be removed at 2017/1/1
3453
    name # will be removed at 2017/1/1
3454
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3455

            
3456
L<DBIx::Custom::Query>
3457
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3458
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3459
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3460
    table # will be removed at 2017/1/1
3461
    filters # will be removed at 2017/1/1
3462
    
3463
    # Methods
3464
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3465

            
3466
L<DBIx::Custom::QueryBuilder>
3467
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3468
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3469
    tags # will be removed at 2017/1/1
3470
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3471
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3472
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3473
    register_tag # will be removed at 2017/1/1
3474
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3475
    
3476
    # Others
3477
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3478
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3479

            
3480
L<DBIx::Custom::Result>
3481
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3482
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3483
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3484
    
3485
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3486
    end_filter # will be removed at 2017/1/1
3487
    remove_end_filter # will be removed at 2017/1/1
3488
    remove_filter # will be removed at 2017/1/1
3489
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3490

            
3491
L<DBIx::Custom::Tag>
3492

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

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

            
3497
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3498
except for attribute method.
3499
You can check all DEPRECATED functionalities by document.
3500
DEPRECATED functionality is removed after five years,
3501
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
3502
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3503

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

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

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

            
3510
C<< <kimoto.yuki at gmail.com> >>
3511

            
3512
L<http://github.com/yuki-kimoto/DBIx-Custom>
3513

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3514
=head1 AUTHOR
3515

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

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

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

            
3522
This program is free software; you can redistribute it and/or modify it
3523
under the same terms as Perl itself.
3524

            
3525
=cut