DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3494 lines | 90.325kb
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

            
micro optimization
Yuki Kimoto authored on 2011-10-23
4
our $VERSION = '0.1735';
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 = '';
cleanup
Yuki Kimoto authored on 2011-10-21
74
    for my $i (-1000 .. 1000) {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
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} || {};
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
126

            
127
    my $qp = $self->_q('');
128
    my $q = substr($qp, 0, 1) || '';
129
    my $p = substr($qp, 1, 1) || '';
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
130
    
131
    # Create set tag
132
    my @params;
133
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-10-21
134
    for my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
135
        croak qq{"$column" is not safety column name } . _subname
136
          unless $column =~ /^[$safety\.]+$/;
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
137
        my $column_quote = "$q$column$p";
138
        $column_quote =~ s/\./$p.$q/;
updated pod
Yuki Kimoto authored on 2011-09-02
139
        my $func = $wrap->{$column} || sub { $_[0] };
140
        push @params,
141
          ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}}
142
        : "$column_quote = " . $func->(":$column");
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
143
    }
144
    my $tag = join(', ', @params);
145
    
146
    return $tag;
147
}
148

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
236
sub delete {
237
    my ($self, %opt) = @_;
238
    warn "delete method where_param option is DEPRECATED!"
239
      if $opt{where_param};
240
    
cleanup
Yuki Kimoto authored on 2011-10-21
241
    # Don't allow delete all rows
cleanup
Yuki Kimoto authored on 2011-10-21
242
    croak qq{delete method where or id option must be specified } . _subname
243
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
244
    
245
    # Where
246
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
247
           ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
248
           : $opt{where};
249
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
250

            
cleanup
Yuki Kimoto authored on 2011-04-02
251
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-10-21
252
    my $sql = "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
253
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
254
    $sql .= "from " . $self->_q($opt{table}) . " $w->{clause} ";
packaging one directory
yuki-kimoto authored on 2009-11-16
255
    
256
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
257
    return $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
258
}
259

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
264
sub create_model {
265
    my $self = shift;
266
    
cleanup
Yuki Kimoto authored on 2011-10-21
267
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
268
    my $opt = ref $_[0] eq 'HASH' ? $_[0] : {@_};
269
    $opt->{dbi} = $self;
270
    my $model_class = delete $opt->{model_class} || 'DBIx::Custom::Model';
271
    my $model_name  = delete $opt->{name};
272
    my $model_table = delete $opt->{table};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
273
    $model_name ||= $model_table;
274
    
cleanup
Yuki Kimoto authored on 2011-04-02
275
    # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
276
    my $model = $model_class->new($opt);
cleanup
Yuki Kimoto authored on 2011-08-13
277
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
278
    $model->name($model_name) unless $model->name;
279
    $model->table($model_table) unless $model->table;
280
    
micro optimization
Yuki Kimoto authored on 2011-07-30
281
    # Apply filter(DEPRECATED logic)
282
    if ($model->{filter}) {
283
        my $filter = ref $model->filter eq 'HASH'
284
                   ? [%{$model->filter}]
285
                   : $model->filter;
286
        $filter ||= [];
287
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
288
          if @$filter;
289
        $self->_apply_filter($model->table, @$filter);
290
    }
291
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
292
    # Set model
293
    $self->model($model->name, $model);
294
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
295
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
296
}
297

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
301
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
302
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
303
    if ($user_column_info) {
304
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
305
    }
306
    else {
307
    
308
        my $re = $self->exclude_table || $options{exclude_table};
309
        # Tables
310
        my %tables;
311
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
312

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
313
        # Iterate all tables
314
        my @tables = sort keys %tables;
315
        for (my $i = 0; $i < @tables; $i++) {
316
            my $table = $tables[$i];
317
            
318
            # Iterate all columns
319
            my $sth_columns;
320
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
321
            next if $@;
322
            while (my $column_info = $sth_columns->fetchrow_hashref) {
323
                my $column = $column_info->{COLUMN_NAME};
324
                $self->$cb($table, $column, $column_info);
325
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
326
        }
327
    }
328
}
329

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
330
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
331
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
332
    
cleanup test
Yuki Kimoto authored on 2011-08-16
333
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
334
    
added test
Yuki Kimoto authored on 2011-08-16
335
    # Iterate tables
336
    if ($user_table_infos) {
337
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
338
    }
339
    else {
340
        my $re = $self->exclude_table || $option{exclude};
341
        my $sth_tables = $self->dbh->table_info;
342
        while (my $table_info = $sth_tables->fetchrow_hashref) {
343
            
344
            # Table
345
            my $table = $table_info->{TABLE_NAME};
346
            next if defined $re && $table =~ /$re/;
347
            $self->$cb($table, $table_info);
348
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
349
    }
350
}
351

            
cleanup
Yuki Kimoto authored on 2011-04-02
352
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
353
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-10-20
354
    my $sql = shift;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
355

            
356
    # Options
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
357
    my $param;
358
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
359
    my %opt = @_;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
360
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
361
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
362
    my $tables = $opt{table} || [];
cleanup
Yuki Kimoto authored on 2011-04-02
363
    $tables = [$tables] unless ref $tables eq 'ARRAY';
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
364
    my $filter = _array_to_hash($opt{filter});
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
365
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
366
    # Append
367
    $sql .= $opt{append} if defined $opt{append} && !ref $sql;
368
    
369
    # Query
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
370
    my $query;
371
    if (ref $sql) { $query = $sql }
372
    else {
373
        $query = $opt{reuse}->{$sql} if $opt{reuse};
374
        $query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter})
375
          unless $query;
376
        $opt{reuse}->{$sql} = $query if $opt{reuse};
377
    }
378
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
379
    # Save query
380
    $self->last_sql($query->sql);
381

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
382
    # Return query
383
    return $query if $opt{query};
micro optimization
Yuki Kimoto authored on 2011-07-30
384
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
385
    # Merge query filter(DEPRECATED!)
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
386
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
387
    
cleanup
Yuki Kimoto authored on 2011-04-02
388
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
389
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
390
    my $main_table = @{$tables}[-1];
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
391
    
392
    # Convert id to parameter
393
    if (defined $opt{id}) {
394
        my $id_param = $self->_id_to_param($opt{id}, $opt{primary_key}, $main_table);
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
395
        $param = $self->merge_param($id_param, $param);
396
    }
micro optimization
Yuki Kimoto authored on 2011-07-30
397
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
398
    # Cleanup tables(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
399
    $tables = $self->_remove_duplicate_table($tables, $main_table)
400
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
401
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
402
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
403
    my $type_filters = {};
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
404
    unless ($opt{type_rule_off}) {
405
        my $type_rule_off_parts = {
406
            1 => $opt{type_rule1_off},
407
            2 => $opt{type_rule2_off}
408
        };
cleanup
Yuki Kimoto authored on 2011-10-21
409
        for my $i (1, 2) {
micro optimization
Yuki Kimoto authored on 2011-07-30
410
            unless ($type_rule_off_parts->{$i}) {
411
                $type_filters->{$i} = {};
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
412
                my $table_alias = $opt{table_alias} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
413
                for my $alias (keys %$table_alias) {
micro optimization
Yuki Kimoto authored on 2011-07-30
414
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
415
                    
cleanup
Yuki Kimoto authored on 2011-10-21
416
                    for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
micro optimization
Yuki Kimoto authored on 2011-07-30
417
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
418
                    }
419
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
420
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
421
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
422
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
423
        }
424
    }
cleanup
Yuki Kimoto authored on 2011-04-02
425
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
426
    # Applied filter(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
427
    if ($self->{filter}{on}) {
428
        my $applied_filter = {};
cleanup
Yuki Kimoto authored on 2011-10-21
429
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-07-30
430
            $applied_filter = {
431
                %$applied_filter,
432
                %{$self->{filter}{out}->{$table} || {}}
433
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
434
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
435
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
436
    }
437
    
cleanup
Yuki Kimoto authored on 2011-04-02
438
    # Replace filter name to code
cleanup
Yuki Kimoto authored on 2011-10-21
439
    for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2011-04-02
440
        my $name = $filter->{$column};
441
        if (!defined $name) {
442
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
443
        }
cleanup
Yuki Kimoto authored on 2011-04-02
444
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
445
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
446
            unless exists $self->filters->{$name};
447
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
448
        }
449
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
450
    
cleanup
Yuki Kimoto authored on 2011-04-02
451
    # Create bind values
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
452
    my $bind = $self->_create_bind_values($param, $query->columns,
453
      $filter, $type_filters, _array_to_hash($opt{bind_type} || $opt{type}));
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
454

            
cleanup
yuki-kimoto authored on 2010-10-17
455
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
456
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
457
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
458
    eval {
micro optimization
Yuki Kimoto authored on 2011-10-22
459
        $sth->bind_param($_ + 1, $bind->[$_]->{value},
460
            $bind->[$_]->{bind_type} ? $bind->[$_]->{bind_type} : ())
461
          for (0 .. @$bind - 1);
cleanup
Yuki Kimoto authored on 2011-03-21
462
        $affected = $sth->execute;
463
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
464
    
micro optimization
Yuki Kimoto authored on 2011-07-30
465
    $self->_croak($@, qq{. Following SQL is executed.\n}
466
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
467
    
improved debug message
Yuki Kimoto authored on 2011-05-23
468
    # DEBUG message
469
    if (DEBUG) {
470
        print STDERR "SQL:\n" . $query->sql . "\n";
471
        my @output;
cleanup
Yuki Kimoto authored on 2011-10-21
472
        for my $b (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
473
            my $value = $b->{value};
474
            $value = 'undef' unless defined $value;
475
            $value = encode(DEBUG_ENCODING(), $value)
476
              if utf8::is_utf8($value);
477
            push @output, $value;
478
        }
479
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
480
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
481
    
cleanup
Yuki Kimoto authored on 2011-04-02
482
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
483
    if ($sth->{NUM_OF_FIELDS}) {
484
        
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
485
        # Filter(DEPRECATED!)
cleanup
Yuki Kimoto authored on 2011-04-02
486
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
487
        if ($self->{filter}{on}) {
488
            $filter->{in}  = {};
489
            $filter->{end} = {};
490
            push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-10-21
491
            for my $table (@$tables) {
492
                for my $way (qw/in end/) {
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
493
                    $filter->{$way} = {%{$filter->{$way}},
494
                      %{$self->{filter}{$way}{$table} || {}}};
micro optimization
Yuki Kimoto authored on 2011-07-30
495
                }
cleanup
Yuki Kimoto authored on 2011-04-02
496
            }
cleanup
Yuki Kimoto authored on 2011-01-12
497
        }
498
        
499
        # Result
500
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
501
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
502
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
503
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
504
            filter => $filter->{in} || {},
505
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
506
            type_rule => {
507
                from1 => $self->type_rule->{from1},
508
                from2 => $self->type_rule->{from2}
509
            },
cleanup
yuki-kimoto authored on 2010-10-17
510
        );
511
        return $result;
512
    }
cleanup
Yuki Kimoto authored on 2011-04-02
513
    # Not select statement
514
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
515
}
516

            
added test
Yuki Kimoto authored on 2011-08-16
517
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
518
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
519
    
cleanup
Yuki Kimoto authored on 2011-10-21
520
    my $exclude = delete $opt{exclude};
521
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
522
    
added test
Yuki Kimoto authored on 2011-08-16
523
    my $table_info = [];
524
    $self->each_table(
525
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
526
        exclude => $exclude
527
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
528
    
cleanup test
Yuki Kimoto authored on 2011-08-16
529
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
530
}
531

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
532
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
533
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
534
    
cleanup
Yuki Kimoto authored on 2011-10-21
535
    my $exclude_table = delete $opt{exclude_table};
536
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
537
    
538
    my $column_info = [];
539
    $self->each_column(
540
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
541
        exclude_table => $exclude_table
542
    );
543
    
544
    return [
545
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
546
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
547
}
548

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
549
sub helper {
550
    my $self = shift;
551
    
552
    # Register method
553
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
554
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
555
    
556
    return $self;
557
}
558

            
cleanup
yuki-kimoto authored on 2010-10-17
559
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
560
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
561
    
cleanup
Yuki Kimoto authored on 2011-10-21
562
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
563
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
564
    my %opt = @_;
565
    warn "insert method param option is DEPRECATED" if $opt{param};
566
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
567
    
568
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
569
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
570
        my $columns = $insert_timestamp->[0];
571
        $columns = [$columns] unless ref $columns eq 'ARRAY';
572
        my $value = $insert_timestamp->[1];
573
        $value = $value->() if ref $value eq 'CODE';
574
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
575
    }
cleanup
Yuki Kimoto authored on 2011-10-21
576
    
577
    # Merge id to parameter
578
    $param = $self->merge_param(
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
579
        $self->_id_to_param(delete $opt{id}, $opt{primary_key}), $param)
cleanup
Yuki Kimoto authored on 2011-10-21
580
      if defined $opt{id};
cleanup
Yuki Kimoto authored on 2011-10-21
581
    
cleanup
Yuki Kimoto authored on 2011-04-02
582
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
583
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
584
    $sql .= "$opt{prefix} " if defined $opt{prefix};
585
    $sql .= "into " . $self->_q($opt{table}) . " "
586
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
packaging one directory
yuki-kimoto authored on 2009-11-16
587
    
588
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
589
    return $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
590
}
591

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
592
sub insert_timestamp {
593
    my $self = shift;
594
    
595
    if (@_) {
596
        $self->{insert_timestamp} = [@_];
597
        
598
        return $self;
599
    }
600
    return $self->{insert_timestamp};
601
}
602

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
603
sub include_model {
604
    my ($self, $name_space, $model_infos) = @_;
605
    
cleanup
Yuki Kimoto authored on 2011-04-02
606
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
607
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
608
    
609
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
610
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
611

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
612
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
613
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
614
          if $name_space =~ /[^\w:]/;
615
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
616
        croak qq{Name space module "$name_space.pm" is needed. $@ }
617
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
618
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
619
        
620
        # Search model modules
621
        my $path = $INC{"$name_space.pm"};
622
        $path =~ s/\.pm$//;
623
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
624
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
625
        $model_infos = [];
626
        while (my $module = readdir $dh) {
627
            push @$model_infos, $module
628
              if $module =~ s/\.pm$//;
629
        }
630
        close $dh;
631
    }
632
    
cleanup
Yuki Kimoto authored on 2011-04-02
633
    # Include models
cleanup
Yuki Kimoto authored on 2011-10-21
634
    for my $model_info (@$model_infos) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
635
        
cleanup
Yuki Kimoto authored on 2011-04-02
636
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
637
        my $model_class;
638
        my $model_name;
639
        my $model_table;
640
        if (ref $model_info eq 'HASH') {
641
            $model_class = $model_info->{class};
642
            $model_name  = $model_info->{name};
643
            $model_table = $model_info->{table};
644
            
645
            $model_name  ||= $model_class;
646
            $model_table ||= $model_name;
647
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
648
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
649
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
650
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
651
          if $mclass =~ /[^\w:]/;
652
        unless ($mclass->can('isa')) {
653
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
654
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
655
        }
656
        
cleanup
Yuki Kimoto authored on 2011-04-02
657
        # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
658
        my $opt = {};
659
        $opt->{model_class} = $mclass if $mclass;
660
        $opt->{name}        = $model_name if $model_name;
661
        $opt->{table}       = $model_table if $model_table;
662
        $self->create_model($opt);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
663
    }
664
    
665
    return $self;
666
}
667

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
670
sub mapper {
671
    my $self = shift;
672
    return DBIx::Custom::Mapper->new(@_);
673
}
674

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
675
sub merge_param {
676
    my ($self, @params) = @_;
677
    
cleanup
Yuki Kimoto authored on 2011-04-02
678
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
679
    my $merge = {};
cleanup
Yuki Kimoto authored on 2011-10-21
680
    for my $param (@params) {
681
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
682
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
683
            
684
            if (exists $merge->{$column}) {
685
                $merge->{$column} = [$merge->{$column}]
686
                  unless ref $merge->{$column} eq 'ARRAY';
687
                push @{$merge->{$column}},
688
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
689
            }
690
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
691
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
692
            }
693
        }
694
    }
695
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
696
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
697
}
698

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
699
sub model {
700
    my ($self, $name, $model) = @_;
701
    
cleanup
Yuki Kimoto authored on 2011-04-02
702
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
703
    if ($model) {
704
        $self->models->{$name} = $model;
705
        return $self;
706
    }
707
    
708
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
709
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
710
      unless $self->models->{$name};
711
    
cleanup
Yuki Kimoto authored on 2011-04-02
712
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
713
    return $self->models->{$name};
714
}
715

            
cleanup
Yuki Kimoto authored on 2011-03-21
716
sub mycolumn {
717
    my ($self, $table, $columns) = @_;
718
    
cleanup
Yuki Kimoto authored on 2011-04-02
719
    # Create column clause
720
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
721
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
722
    push @column, $self->_q($table) . "." . $self->_q($_) .
723
      " as " . $self->_q($_)
724
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
725
    
726
    return join (', ', @column);
727
}
728

            
added dbi_options attribute
kimoto authored on 2010-12-20
729
sub new {
730
    my $self = shift->SUPER::new(@_);
731
    
cleanup
Yuki Kimoto authored on 2011-04-02
732
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
733
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
734
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
735
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
736
          unless $self->can($attr);
737
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
738

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
739
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
740
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
741
        '?'     => \&DBIx::Custom::Tag::placeholder,
742
        '='     => \&DBIx::Custom::Tag::equal,
743
        '<>'    => \&DBIx::Custom::Tag::not_equal,
744
        '>'     => \&DBIx::Custom::Tag::greater_than,
745
        '<'     => \&DBIx::Custom::Tag::lower_than,
746
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
747
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
748
        'like'  => \&DBIx::Custom::Tag::like,
749
        'in'    => \&DBIx::Custom::Tag::in,
750
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
751
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
752
    };
753
    
754
    return $self;
755
}
756

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

            
759
sub order {
760
    my $self = shift;
761
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
762
}
763

            
cleanup
yuki-kimoto authored on 2010-10-17
764
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
765
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
766
    
767
    # Register filter
768
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
769
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
770
    
cleanup
Yuki Kimoto authored on 2011-04-02
771
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
772
}
packaging one directory
yuki-kimoto authored on 2009-11-16
773

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
777
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
778
    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
779
               : defined $opt{table} ? [$opt{table}]
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
780
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
781
    $opt{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
782
    my $where_param = $opt{where_param} || delete $opt{param} || {};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
783
    
cleanup
Yuki Kimoto authored on 2011-03-09
784
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
785
    if ($opt{relation}) {
786
        warn "select() relation option is DEPRECATED!";
787
        $self->_add_relation_table($tables, $opt{relation});
788
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
789
    
cleanup
Yuki Kimoto authored on 2011-04-02
790
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
791
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
792
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
793
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
794
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
795
    
cleanup
Yuki Kimoto authored on 2011-10-21
796
    # Column
cleanup
Yuki Kimoto authored on 2011-10-21
797
    if (defined $opt{column}) {
798
        my $columns
799
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
cleanup
Yuki Kimoto authored on 2011-10-21
800
        for my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
801
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
802
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
803
            }
804
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
805
                if (@$column == 3 && $column->[1] eq 'as') {
806
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
807
                    splice @$column, 1, 1;
808
                }
809
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
810
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
811
            }
cleanup
Yuki Kimoto authored on 2011-04-02
812
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
813
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
814
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
815
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
816
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
817
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
818
    
819
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
820
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
821
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
822
        my $found = {};
cleanup
Yuki Kimoto authored on 2011-10-21
823
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
824
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
825
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
826
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
827
    }
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
828
    else { $sql .= $self->_q($tables->[-1] || '') . ' ' }
micro optimization
Yuki Kimoto authored on 2011-09-30
829
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-10-21
830
    croak "select method table option must be specified " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
831
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
832

            
cleanup
Yuki Kimoto authored on 2011-04-02
833
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
834
    unshift @$tables,
835
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
836
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
837
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
838
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
839
              ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $tables->[-1])
cleanup
Yuki Kimoto authored on 2011-10-21
840
              : $opt{where};
841
    my $w = $self->_where_clause_and_param($where, $where_param);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
842
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
843
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
844
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
845
    
cleanup
Yuki Kimoto authored on 2011-10-21
846
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
847
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
848
    
cleanup
Yuki Kimoto authored on 2011-03-09
849
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
850
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
851
    
cleanup
Yuki Kimoto authored on 2011-03-08
852
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
853
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
854
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
855
    
packaging one directory
yuki-kimoto authored on 2009-11-16
856
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
857
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
858
    
859
    return $result;
860
}
861

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
862
sub setup_model {
863
    my $self = shift;
864
    
cleanup
Yuki Kimoto authored on 2011-04-02
865
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
866
    $self->each_column(
867
        sub {
868
            my ($self, $table, $column, $column_info) = @_;
869
            if (my $model = $self->models->{$table}) {
870
                push @{$model->columns}, $column;
871
            }
872
        }
873
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
874
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
875
}
876

            
update pod
Yuki Kimoto authored on 2011-08-10
877
sub show_datatype {
878
    my ($self, $table) = @_;
879
    croak "Table name must be specified" unless defined $table;
880
    print "$table\n";
881
    
882
    my $result = $self->select(table => $table, where => "'0' <> '0'");
883
    my $sth = $result->sth;
884

            
885
    my $columns = $sth->{NAME};
886
    my $data_types = $sth->{TYPE};
887
    
888
    for (my $i = 0; $i < @$columns; $i++) {
889
        my $column = $columns->[$i];
890
        my $data_type = $data_types->[$i];
891
        print "$column: $data_type\n";
892
    }
893
}
894

            
895
sub show_typename {
896
    my ($self, $t) = @_;
897
    croak "Table name must be specified" unless defined $t;
898
    print "$t\n";
899
    
900
    $self->each_column(sub {
901
        my ($self, $table, $column, $infos) = @_;
902
        return unless $table eq $t;
903
        my $typename = $infos->{TYPE_NAME};
904
        print "$column: $typename\n";
905
    });
906
    
907
    return $self;
908
}
909

            
test cleanup
Yuki Kimoto authored on 2011-08-15
910
sub show_tables {
911
    my $self = shift;
912
    
913
    my %tables;
914
    $self->each_table(sub { $tables{$_[1]}++ });
915
    print join("\n", sort keys %tables) . "\n";
916
    return $self;
917
}
918

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
919
sub type_rule {
920
    my $self = shift;
921
    
922
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
923
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
924
        
925
        # Into
cleanup
Yuki Kimoto authored on 2011-10-21
926
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
927
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
928
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
929
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
930
            $self->{type_rule} = $type_rule;
931
            $self->{"_$into"} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
932
            for my $type_name (keys %{$type_rule->{$into} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
933
                croak qq{type name of $into section must be lower case}
934
                  if $type_name =~ /[A-Z]/;
935
            }
cleanup
Yuki Kimoto authored on 2011-08-16
936
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
937
            $self->each_column(sub {
938
                my ($dbi, $table, $column, $column_info) = @_;
939
                
940
                my $type_name = lc $column_info->{TYPE_NAME};
941
                if ($type_rule->{$into} &&
942
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
943
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
944
                    return unless exists $type_rule->{$into}->{$type_name};
945
                    if  (defined $filter && ref $filter ne 'CODE') 
946
                    {
947
                        my $fname = $filter;
948
                        croak qq{Filter "$fname" is not registered" } . _subname
949
                          unless exists $self->filters->{$fname};
950
                        
951
                        $filter = $self->filters->{$fname};
952
                    }
953

            
micro optimization
Yuki Kimoto authored on 2011-07-30
954
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
955
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
956
                }
957
            });
958
        }
959

            
960
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
961
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
962
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
963
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
964
                croak qq{data type of from$i section must be lower case or number}
965
                  if $data_type =~ /[A-Z]/;
966
                my $fname = $type_rule->{"from$i"}{$data_type};
967
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
968
                    croak qq{Filter "$fname" is not registered" } . _subname
969
                      unless exists $self->filters->{$fname};
970
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
971
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
972
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
973
            }
974
        }
975
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
976
        return $self;
977
    }
978
    
979
    return $self->{type_rule} || {};
980
}
981

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
985
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
986
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
987
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
988
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
989
    warn "update method where_param option is DEPRECATED!"
990
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
991
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
992
    
cleanup
Yuki Kimoto authored on 2011-10-21
993
    # Don't allow update all rows
994
    croak qq{update method where option must be specified } . _subname
995
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
996
    
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
997
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
998
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
999
        my $columns = $update_timestamp->[0];
1000
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1001
        my $value = $update_timestamp->[1];
1002
        $value = $value->() if ref $value eq 'CODE';
1003
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1004
    }
1005

            
cleanup
Yuki Kimoto authored on 2011-10-21
1006
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1007
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1008
    
1009
    # Convert id to where parameter
1010
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1011
      ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
1012
      : $opt{where};
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1013

            
1014
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1015
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1016
    
cleanup
Yuki Kimoto authored on 2011-10-21
1017
    # Merge where parameter to parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1018
    $param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1019
    
cleanup
Yuki Kimoto authored on 2011-04-02
1020
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1021
    my $sql = "update ";
1022
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
1023
    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1024
    
cleanup
yuki-kimoto authored on 2010-10-17
1025
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1026
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1027
}
1028

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1031
sub update_or_insert {
1032
    my $self = shift;
1033

            
cleanup
Yuki Kimoto authored on 2011-10-21
1034
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1035
    my $param  = shift;
1036
    my %opt = @_;
1037
    my $id = $opt{id};
1038
    my $primary_key = $opt{primary_key};
1039
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1040
    croak "update_or_insert method need primary_key option " .
1041
          "when id is specified" . _subname
1042
      if defined $id && !defined $primary_key;
1043
    my $table  = $opt{table};
1044
    croak qq{"table" option must be specified } . _subname
1045
      unless defined $table;
1046
    my $select_option = $opt{select_option};
1047
    
1048
    my $rows = $self->select(table => $table, id => $id,
1049
        primary_key => $primary_key, %$select_option)->all;
1050
    
1051
    croak "selected row count must be one or zero" . _subname
1052
      if @$rows > 1;
1053
    
1054
    my $row = $rows->[0];
1055
    my @opt = (table => $table);
1056
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1057
    push @opt, %opt;
1058
    
1059
    if ($row) {
1060
        return $self->update($param, @opt);
1061
    }
1062
    else {
1063
        return $self->insert($param, @opt);
1064
    }
1065
}
1066

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1067
sub update_timestamp {
1068
    my $self = shift;
1069
    
1070
    if (@_) {
1071
        $self->{update_timestamp} = [@_];
1072
        
1073
        return $self;
1074
    }
1075
    return $self->{update_timestamp};
1076
}
1077

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1078
sub values_clause {
1079
    my ($self, $param, $opts) = @_;
1080
    
1081
    my $wrap = $opts->{wrap} || {};
1082
    
1083
    # Create insert parameter tag
1084
    my $safety = $self->safety_character;
1085
    my @columns;
1086
    my @placeholders;
improved performance
Yuki Kimoto authored on 2011-10-22
1087
    my $qp = $self->_q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1088
    my $q = substr($qp, 0, 1) || '';
1089
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1090
    
cleanup
Yuki Kimoto authored on 2011-10-21
1091
    for my $column (sort keys %$param) {
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1092
        croak qq{"$column" is not safety column name } . _subname
1093
          unless $column =~ /^[$safety\.]+$/;
improved performance
Yuki Kimoto authored on 2011-10-22
1094
        my $column_quote = "$q$column$p";
1095
        $column_quote =~ s/\./$p.$q/;
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1096
        push @columns, $column_quote;
1097
        
1098
        my $func = $wrap->{$column} || sub { $_[0] };
1099
        push @placeholders,
1100
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1101
        : $func->(":$column");
1102
    }
1103
    
1104
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1105
           '(' . join(', ', @placeholders) . ')'
1106
}
1107

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1110
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1111
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1112
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1113
    
updated pod
Yuki Kimoto authored on 2011-06-21
1114
    # Cache
1115
    my $cache = $self->cache;
1116
    
1117
    # Query
1118
    my $query;
1119
    
1120
    # Get cached query
1121
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1122
        
updated pod
Yuki Kimoto authored on 2011-06-21
1123
        # Get query
1124
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1125
        
updated pod
Yuki Kimoto authored on 2011-06-21
1126
        # Create query
1127
        if ($q) {
1128
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1129
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1130
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1131
    }
1132
    
1133
    # Create query
1134
    unless ($query) {
1135

            
1136
        # Create query
1137
        my $builder = $self->query_builder;
1138
        $query = $builder->build_query($source);
1139

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

            
1146
        # Save query to cache
1147
        $self->cache_method->(
1148
            $self, $source,
1149
            {
1150
                sql     => $query->sql, 
1151
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1152
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1153
            }
1154
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1155
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1156

            
1157
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1158
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1159
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1160
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1161
        $query->sql($sql);
1162
    }
1163
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1164
    # Save sql
1165
    $self->last_sql($query->sql);
1166
    
updated pod
Yuki Kimoto authored on 2011-06-21
1167
    # Prepare statement handle
1168
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1169
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1170
    
1171
    if ($@) {
1172
        $self->_croak($@, qq{. Following SQL is executed.\n}
1173
                        . qq{$query->{sql}\n} . _subname);
1174
    }
1175
    
1176
    # Set statement handle
1177
    $query->sth($sth);
1178
    
1179
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1180
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1181
    
1182
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1183
}
1184

            
cleanup
Yuki Kimoto authored on 2011-04-02
1185
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1186
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1187
    
cleanup
Yuki Kimoto authored on 2011-04-02
1188
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1189
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1190
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1191
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-10-21
1192
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1193
        
1194
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1195
        my $value;
1196
        if(ref $params->{$column} eq 'ARRAY') {
1197
            my $i = $count->{$column} || 0;
1198
            $i += $not_exists->{$column} || 0;
1199
            my $found;
1200
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1201
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1202
                    $not_exists->{$column}++;
1203
                }
1204
                else  {
1205
                    $value = $params->{$column}->[$k];
1206
                    $found = 1;
1207
                    last
1208
                }
1209
            }
1210
            next unless $found;
1211
        }
1212
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1213
        
cleanup
Yuki Kimoto authored on 2011-01-12
1214
        # Filter
1215
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1216
        $value = $f->($value) if $f;
1217
        
1218
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-22
1219
        my $tf1 = $self->{"_into1"}->{dot}->{$column}
1220
          || $type_filters->{1}->{$column};
1221
        $value = $tf1->($value) if $tf1;
1222
        my $tf2 = $self->{"_into2"}->{dot}->{$column}
1223
          || $type_filters->{2}->{$column};
1224
        $value = $tf2->($value) if $tf2;
1225
       
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1226
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1227
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1228
        
1229
        # Count up 
1230
        $count->{$column}++;
1231
    }
1232
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1233
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1234
}
1235

            
cleanup
Yuki Kimoto authored on 2011-10-21
1236
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1237
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1238
    
1239
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1240
    croak "primary_key option " .
1241
          "must be specified with id option " . _subname
1242
      unless defined $primary_keys;
1243
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1244
    
cleanup
Yuki Kimoto authored on 2011-06-08
1245
    # Create parameter
1246
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1247
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1248
        $id = [$id] unless ref $id;
1249
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1250
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1251
          unless !ref $id || ref $id eq 'ARRAY';
1252
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1253
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1254
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1255
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1256
           my $key = $primary_keys->[$i];
1257
           $key = "$table." . $key if $table;
1258
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1259
        }
1260
    }
1261
    
cleanup
Yuki Kimoto authored on 2011-06-08
1262
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1263
}
1264

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1265
sub _connect {
1266
    my $self = shift;
1267
    
1268
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1269
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1270
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1271
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1272
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1273
    croak qq{"dsn" must be specified } . _subname
1274
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1275
    my $user        = $self->user;
1276
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1277
    my $option = $self->_option;
1278
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1279
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1280
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1281
    my $dbh;
1282
    eval {
1283
        $dbh = DBI->connect(
1284
            $dsn,
1285
            $user,
1286
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1287
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1288
        );
1289
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1290
    
1291
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1292
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1293
    
1294
    return $dbh;
1295
}
1296

            
cleanup
yuki-kimoto authored on 2010-10-17
1297
sub _croak {
1298
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1299
    
1300
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1301
    $append ||= "";
1302
    
1303
    # Verbose
1304
    if ($Carp::Verbose) { croak $error }
1305
    
1306
    # Not verbose
1307
    else {
1308
        
1309
        # Remove line and module infromation
1310
        my $at_pos = rindex($error, ' at ');
1311
        $error = substr($error, 0, $at_pos);
1312
        $error =~ s/\s+$//;
1313
        croak "$error$append";
1314
    }
1315
}
1316

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1319
sub _need_tables {
1320
    my ($self, $tree, $need_tables, $tables) = @_;
1321
    
cleanup
Yuki Kimoto authored on 2011-04-02
1322
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1323
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1324
        if ($tree->{$table}) {
1325
            $need_tables->{$table} = 1;
1326
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1327
        }
1328
    }
1329
}
1330

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1331
sub _option {
1332
    my $self = shift;
1333
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1334
    warn "dbi_options is DEPRECATED! use option instead\n"
1335
      if keys %{$self->dbi_options};
1336
    warn "dbi_option is DEPRECATED! use option instead\n"
1337
      if keys %{$self->dbi_option};
1338
    return $option;
1339
}
1340

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1341
sub _push_join {
1342
    my ($self, $sql, $join, $join_tables) = @_;
1343
    
cleanup
Yuki Kimoto authored on 2011-10-21
1344
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1345
    
cleanup
Yuki Kimoto authored on 2011-04-02
1346
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1347
    return unless @$join;
1348
    
cleanup
Yuki Kimoto authored on 2011-04-02
1349
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1350
    my $tree = {};
1351
    for (my $i = 0; $i < @$join; $i++) {
1352
        
cleanup
Yuki Kimoto authored on 2011-07-28
1353
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1354
        my $join_clause;;
1355
        my $option;
1356
        if (ref $join->[$i] eq 'HASH') {
1357
            $join_clause = $join->[$i]->{clause};
1358
            $option = {table => $join->[$i]->{table}};
1359
        }
1360
        else {
1361
            $join_clause = $join->[$i];
1362
            $option = {};
1363
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1364

            
1365
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1366
        my $table1;
1367
        my $table2;
1368
        if (my $table = $option->{table}) {
1369
            $table1 = $table->[0];
1370
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1371
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1372
        else {
1373
            my $q = $self->_quote;
1374
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1375
            $j_clause =~ s/'.+?'//g;
1376
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1377
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1378
            
1379
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1380
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1381
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1382
            for my $clause (@j_clauses) {
1383
                if ($clause =~ $join_re) {
1384
                    $table1 = $1;
1385
                    $table2 = $2;
1386
                    last;
1387
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1388
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1389
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1390
        croak qq{join clause must have two table name after "on" keyword. } .
1391
              qq{"$join_clause" is passed }  . _subname
1392
          unless defined $table1 && defined $table2;
1393
        croak qq{right side table of "$join_clause" must be unique }
1394
            . _subname
1395
          if exists $tree->{$table2};
1396
        croak qq{Same table "$table1" is specified} . _subname
1397
          if $table1 eq $table2;
1398
        $tree->{$table2}
1399
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1400
    }
1401
    
cleanup
Yuki Kimoto authored on 2011-04-02
1402
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1403
    my $need_tables = {};
1404
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1405
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1406
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1407
    
1408
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1409
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1410
}
cleanup
Yuki Kimoto authored on 2011-03-08
1411

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1412
sub _quote {
1413
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1414
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1415
}
1416

            
cleanup
Yuki Kimoto authored on 2011-07-29
1417
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1418
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1419
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1420
    my $quote = $self->{reserved_word_quote}
1421
      || $self->{quote} || $self->quote || '';
1422
    return "$quote$value$quote"
1423
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
1424
    
cleanup
Yuki Kimoto authored on 2011-07-29
1425
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1426
    my $p;
1427
    if (defined $quote && length $quote > 1) {
1428
        $p = substr($quote, 1, 1);
1429
    }
1430
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1431
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1432
    if ($quotemeta) {
1433
        $q = quotemeta($q);
1434
        $p = quotemeta($p);
1435
    }
1436
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1437
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1438
}
1439

            
cleanup
Yuki Kimoto authored on 2011-04-02
1440
sub _remove_duplicate_table {
1441
    my ($self, $tables, $main_table) = @_;
1442
    
1443
    # Remove duplicate table
1444
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1445
    delete $tables{$main_table} if $main_table;
1446
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1447
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1448
    if (my $q = $self->_quote) {
1449
        $q = quotemeta($q);
1450
        $_ =~ s/[$q]//g for @$new_tables;
1451
    }
1452

            
1453
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1454
}
1455

            
cleanup
Yuki Kimoto authored on 2011-04-02
1456
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1457
    my ($self, $source) = @_;
1458
    
cleanup
Yuki Kimoto authored on 2011-04-02
1459
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1460
    my $tables = [];
1461
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1462
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1463
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1464
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1465
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1466
    while ($source =~ /$table_re/g) {
1467
        push @$tables, $1;
1468
    }
1469
    
1470
    return $tables;
1471
}
1472

            
cleanup
Yuki Kimoto authored on 2011-04-02
1473
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1474
    my ($self, $where) = @_;
1475
    
cleanup
Yuki Kimoto authored on 2011-04-02
1476
    my $obj;
1477
    
1478
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1479
    if (ref $where eq 'HASH') {
1480
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1481
        my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-10-21
1482
        for my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1483
            my $table;
1484
            my $c;
1485
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1486
                $table = $1;
1487
                $c = $2;
1488
            }
1489
            
1490
            my $table_quote;
1491
            $table_quote = $self->_q($table) if defined $table;
1492
            my $column_quote = $self->_q($c);
1493
            $column_quote = $table_quote . '.' . $column_quote
1494
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1495
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1496
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1497
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1498
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1499
    
1500
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1501
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1502
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1503
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1504
    
updated pod
Yuki Kimoto authored on 2011-06-21
1505
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1506
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1507
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1508
            clause => $where->[0],
1509
            param  => $where->[1]
1510
        );
1511
    }
1512
    
cleanup
Yuki Kimoto authored on 2011-04-02
1513
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1514
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1515
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1516
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1517
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1518
    
cleanup
Yuki Kimoto authored on 2011-04-02
1519
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1520
}
1521

            
cleanup
Yuki Kimoto authored on 2011-10-21
1522
sub _where_clause_and_param {
1523
    my ($self, $where, $param) = @_;
1524
 
1525
    $where ||= {};
1526
    $param ||= {};
1527
    my $w = {};
1528
    my $where_clause = '';
1529
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1530
        $w->{clause} = "where " . $where->[0];
1531
        $w->{param} = $where->[1];
1532
    }
1533
    elsif (ref $where) {
1534
        $where = $self->_where_to_obj($where);
1535
        $w->{param} = keys %$param
1536
                    ? $self->merge_param($param, $where->param)
1537
                    : $where->param;
1538
        $w->{clause} = $where->to_string;
1539
    }
1540
    elsif ($where) {
1541
        $w->{clause} = "where $where";
1542
        $w->{param} = $param;
1543
    }
1544
    
1545
    return $w;
1546
}
1547

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

            
1551
    # Initialize filters
1552
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1553
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1554
    $self->{filter}{out} ||= {};
1555
    $self->{filter}{in} ||= {};
1556
    $self->{filter}{end} ||= {};
1557
    
1558
    # Usage
1559
    my $usage = "Usage: \$dbi->apply_filter(" .
1560
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1561
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1562
    
1563
    # Apply filter
1564
    for (my $i = 0; $i < @cinfos; $i += 2) {
1565
        
1566
        # Column
1567
        my $column = $cinfos[$i];
1568
        if (ref $column eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-10-21
1569
            for my $c (@$column) {
updated pod
Yuki Kimoto authored on 2011-06-21
1570
                push @cinfos, $c, $cinfos[$i + 1];
1571
            }
1572
            next;
1573
        }
1574
        
1575
        # Filter infomation
1576
        my $finfo = $cinfos[$i + 1] || {};
1577
        croak "$usage (table: $table) " . _subname
1578
          unless  ref $finfo eq 'HASH';
cleanup
Yuki Kimoto authored on 2011-10-21
1579
        for my $ftype (keys %$finfo) {
updated pod
Yuki Kimoto authored on 2011-06-21
1580
            croak "$usage (table: $table) " . _subname
1581
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1582
        }
1583
        
1584
        # Set filters
cleanup
Yuki Kimoto authored on 2011-10-21
1585
        for my $way (qw/in out end/) {
updated pod
Yuki Kimoto authored on 2011-06-21
1586
        
1587
            # Filter
1588
            my $filter = $finfo->{$way};
1589
            
1590
            # Filter state
1591
            my $state = !exists $finfo->{$way} ? 'not_exists'
1592
                      : !defined $filter        ? 'not_defined'
1593
                      : ref $filter eq 'CODE'   ? 'code'
1594
                      : 'name';
1595
            
1596
            # Filter is not exists
1597
            next if $state eq 'not_exists';
1598
            
1599
            # Check filter name
1600
            croak qq{Filter "$filter" is not registered } . _subname
1601
              if  $state eq 'name'
1602
               && ! exists $self->filters->{$filter};
1603
            
1604
            # Set filter
1605
            my $f = $state eq 'not_defined' ? undef
1606
                  : $state eq 'code'        ? $filter
1607
                  : $self->filters->{$filter};
1608
            $self->{filter}{$way}{$table}{$column} = $f;
1609
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1610
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1611
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1612
        }
1613
    }
1614
    
1615
    return $self;
1616
}
1617

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1618
# DEPRECATED!
1619
has 'data_source';
1620
has dbi_options => sub { {} };
1621
has filter_check  => 1;
1622
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1623
has dbi_option => sub { {} };
1624
has default_dbi_option => sub {
1625
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1626
    return shift->default_option;
1627
};
1628

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1629
# DEPRECATED!
1630
sub method {
1631
    warn "method is DEPRECATED! use helper instead";
1632
    return shift->helper(@_);
1633
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1634

            
1635
# DEPRECATED!
1636
sub assign_param {
1637
    my $self = shift;
1638
    warn "assing_param is DEPRECATED! use assign_clause instead";
1639
    return $self->assign_clause(@_);
1640
}
1641

            
1642
# DEPRECATED
1643
sub update_param {
1644
    my ($self, $param, $opts) = @_;
1645
    
1646
    warn "update_param is DEPRECATED! use assing_clause instead.";
1647
    
1648
    # Create update parameter tag
1649
    my $tag = $self->assign_clause($param, $opts);
1650
    $tag = "set $tag" unless $opts->{no_set};
1651

            
1652
    return $tag;
1653
}
1654

            
updated pod
Yuki Kimoto authored on 2011-06-21
1655
# DEPRECATED!
1656
sub create_query {
1657
    warn "create_query is DEPRECATED! use query option of each method";
1658
    shift->_create_query(@_);
1659
}
1660

            
cleanup
Yuki Kimoto authored on 2011-06-13
1661
# DEPRECATED!
1662
sub apply_filter {
1663
    my $self = shift;
1664
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1665
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1666
    return $self->_apply_filter(@_);
1667
}
1668

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1673
    warn "select_at is DEPRECATED! use select method id option instead";
updated pod
Yuki Kimoto authored on 2011-06-08
1674

            
cleanup
Yuki Kimoto authored on 2011-10-21
1675
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1676
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1677
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1678
    my $where = delete $opt{where};
1679
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1680
    
1681
    # Table
1682
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1683
      unless $opt{table};
1684
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1685
    
1686
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1687
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1688
    
cleanup
Yuki Kimoto authored on 2011-10-21
1689
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1690
}
1691

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1696
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1697
    
cleanup
Yuki Kimoto authored on 2011-10-21
1698
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1699
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1700
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1701
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1702
    
1703
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1704
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1705
    
cleanup
Yuki Kimoto authored on 2011-10-21
1706
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1707
}
1708

            
cleanup
Yuki Kimoto authored on 2011-06-08
1709
# DEPRECATED!
1710
sub update_at {
1711
    my $self = shift;
1712

            
cleanup
Yuki Kimoto authored on 2011-10-21
1713
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1714
    
cleanup
Yuki Kimoto authored on 2011-10-21
1715
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1716
    my $param;
1717
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1718
    my %opt = @_;
1719
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1720
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1721
    my $where = delete $opt{where};
1722
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1723
    $param  ||= $p;
1724
    
1725
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1726
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1727
    
cleanup
Yuki Kimoto authored on 2011-10-21
1728
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1729
}
1730

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1731
# DEPRECATED!
1732
sub insert_at {
1733
    my $self = shift;
1734
    
cleanup
Yuki Kimoto authored on 2011-10-21
1735
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1736
    
cleanup
Yuki Kimoto authored on 2011-10-21
1737
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1738
    my $param;
1739
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1740
    my %opt = @_;
1741
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1742
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1743
    my $where = delete $opt{where};
1744
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1745
    $param  ||= $p;
1746
    
1747
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1748
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1749
    $param = $self->merge_param($where_param, $param);
1750
    
cleanup
Yuki Kimoto authored on 2011-10-21
1751
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1752
}
1753

            
added warnings
Yuki Kimoto authored on 2011-06-07
1754
# DEPRECATED!
1755
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1756
    my $self = shift;
1757
    
added warnings
Yuki Kimoto authored on 2011-06-07
1758
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1759
    
1760
    # Merge tag
1761
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1762
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1763
    
1764
    return $self;
1765
}
1766

            
1767
# DEPRECATED!
1768
sub register_tag_processor {
1769
    my $self = shift;
1770
    warn "register_tag_processor is DEPRECATED!";
1771
    # Merge tag
1772
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1773
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1774
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1775
}
1776

            
cleanup
Yuki Kimoto authored on 2011-01-25
1777
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1778
sub default_bind_filter {
1779
    my $self = shift;
1780
    
cleanup
Yuki Kimoto authored on 2011-06-13
1781
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1782
    
cleanup
Yuki Kimoto authored on 2011-01-12
1783
    if (@_) {
1784
        my $fname = $_[0];
1785
        
1786
        if (@_ && !$fname) {
1787
            $self->{default_out_filter} = undef;
1788
        }
1789
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1790
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1791
              unless exists $self->filters->{$fname};
1792
        
1793
            $self->{default_out_filter} = $self->filters->{$fname};
1794
        }
1795
        return $self;
1796
    }
1797
    
1798
    return $self->{default_out_filter};
1799
}
1800

            
cleanup
Yuki Kimoto authored on 2011-01-25
1801
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1802
sub default_fetch_filter {
1803
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1804

            
cleanup
Yuki Kimoto authored on 2011-06-13
1805
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1806
    
1807
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1808
        my $fname = $_[0];
1809

            
cleanup
Yuki Kimoto authored on 2011-01-12
1810
        if (@_ && !$fname) {
1811
            $self->{default_in_filter} = undef;
1812
        }
1813
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1814
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1815
              unless exists $self->filters->{$fname};
1816
        
1817
            $self->{default_in_filter} = $self->filters->{$fname};
1818
        }
1819
        
1820
        return $self;
1821
    }
1822
    
many changed
Yuki Kimoto authored on 2011-01-23
1823
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1824
}
1825

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1826
# DEPRECATED!
1827
sub insert_param {
1828
    my $self = shift;
1829
    warn "insert_param is DEPRECATED! use values_clause instead";
1830
    return $self->values_clause(@_);
1831
}
1832

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1833
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1834
sub insert_param_tag {
1835
    warn "insert_param_tag is DEPRECATED! " .
1836
         "use insert_param instead!";
1837
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1838
}
1839

            
1840
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1841
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1842
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1843
         "use update_param instead";
1844
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1845
}
cleanup
Yuki Kimoto authored on 2011-03-08
1846
# DEPRECATED!
1847
sub _push_relation {
1848
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1849
    
1850
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1851
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1852
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1853
            my $table1 = (split (/\./, $rcolumn))[0];
1854
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1855
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1856
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1857
        }
1858
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1859
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1860
}
1861

            
1862
# DEPRECATED!
1863
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1864
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1865
    
1866
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1867
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1868
            my $table1 = (split (/\./, $rcolumn))[0];
1869
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1870
            my $table1_exists;
1871
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1872
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1873
                $table1_exists = 1 if $table eq $table1;
1874
                $table2_exists = 1 if $table eq $table2;
1875
            }
1876
            unshift @$tables, $table1 unless $table1_exists;
1877
            unshift @$tables, $table2 unless $table2_exists;
1878
        }
1879
    }
1880
}
1881

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1884
=head1 NAME
1885

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1886
DBIx::Custom - DBI extension to execute insert, update, delete, and select easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1887

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1890
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1891
    
1892
    # Connect
1893
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1894
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1895
        user => 'ken',
1896
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1897
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1898
    );
cleanup
yuki-kimoto authored on 2010-08-05
1899

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1900
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1901
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1902
    
1903
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1904
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1905
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1906
    
1907
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1908
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1909

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1914
    # Select, more complex
1915
    my $result = $dbi->select(
1916
        table  => 'book',
1917
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1918
            {book => [qw/title author/]},
1919
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1920
        ],
1921
        where  => {'book.author' => 'Ken'},
1922
        join => ['left outer join company on book.company_id = company.id'],
1923
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1924
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1925
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1926
    # Fetch
1927
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1928
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1929
    }
1930
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1931
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1932
    while (my $row = $result->fetch_hash) {
1933
        
1934
    }
1935
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1936
    # Execute SQL with parameter.
1937
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1938
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1939
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1940
    );
1941
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1942
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1943

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1959
Named place holder support
1960

            
1961
=item *
1962

            
cleanup
Yuki Kimoto authored on 2011-07-29
1963
Model support
1964

            
1965
=item *
1966

            
1967
Connection manager support
1968

            
1969
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1970

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

            
1975
=item *
1976

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

            
1979
=item *
1980

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

            
1983
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1984

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1992
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1993
L<DBIx::Custom::Result>,
1994
L<DBIx::Custom::Query>,
1995
L<DBIx::Custom::Where>,
1996
L<DBIx::Custom::Model>,
1997
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1998

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

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

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

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

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

            
2012
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2013
        "dbi:mysql:database=$database",
2014
        $user,
2015
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2016
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2017
    );
2018
    
updated pod
Yuki Kimoto authored on 2011-06-21
2019
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2020

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

            
2024
    my $dbi = DBIx::Custom->connect(
2025
      dsn => $dsn, user => $user, password => $password, connector => 1);
2026
    
2027
    my $connector = $dbi->connector; # DBIx::Connector
2028

            
2029
Note that L<DBIx::Connector> must be installed.
2030

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2046
    {
2047
        RaiseError => 1,
2048
        PrintError => 0,
2049
        AutoCommit => 1,
2050
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2051

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

            
2054
    my $exclude_table = $dbi->exclude_table;
2055
    $dbi = $dbi->exclude_table(qr/pg_/);
2056

            
2057
Excluded table regex.
2058
C<each_column>, C<each_table>, C<type_rule>,
2059
and C<setup_model> methods ignore matching tables.
2060

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

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

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

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

            
2070
    my $last_sql = $dbi->last_sql;
2071
    $dbi = $dbi->last_sql($last_sql);
2072

            
2073
Get last successed SQL executed by C<execute> method.
2074

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

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

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

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

            
2084
    my $option = $dbi->option;
2085
    $dbi = $dbi->option($option);
2086

            
2087
L<DBI> option, used when C<connect> method is executed.
2088
Each value in option override the value of C<default_option>.
2089

            
cleanup
yuki-kimoto authored on 2010-10-17
2090
=head2 C<password>
2091

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2112
You can set quote pair.
2113

            
2114
    $dbi->quote('[]');
2115

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2125
    my $safety_character = $dbi->safety_character;
2126
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2127

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

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

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

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

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

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

            
2144
    my $tag_parse = $dbi->tag_parse(0);
2145
    $dbi = $dbi->tag_parse;
2146

            
2147
Enable DEPRECATED tag parsing functionality, default to 1.
2148
If you want to disable tag parsing functionality, set to 0.
2149

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

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

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

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

            
2159
    my $user_column_info = $dbi->user_column_info;
2160
    $dbi = $dbi->user_column_info($user_column_info);
2161

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

            
2164
    [
2165
        {table => 'book', column => 'title', info => {...}},
2166
        {table => 'author', column => 'name', info => {...}}
2167
    ]
2168

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

            
2171
    my $user_column_info
2172
      = $dbi->get_column_info(exclude_table => qr/^system/);
2173
    $dbi->user_column_info($user_column_info);
2174

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

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

            
2180
    my $user_table_info = $dbi->user_table_info;
2181
    $dbi = $dbi->user_table_info($user_table_info);
2182

            
2183
You can set the following data.
2184

            
2185
    [
2186
        {table => 'book', info => {...}},
2187
        {table => 'author', info => {...}}
2188
    ]
2189

            
2190
Usually, you can set return value of C<get_table_info>.
2191

            
2192
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2193
    $dbi->user_table_info($user_table_info);
2194

            
2195
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2196
to find table info.
2197

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2234
Create column clause. The follwoing column clause is created.
2235

            
2236
    book.author as "book.author",
2237
    book.title as "book.title"
2238

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2241
    # Separator is hyphen
2242
    $dbi->separator('-');
2243
    
2244
    book.author as "book-author",
2245
    book.title as "book-title"
2246
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2247
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2248

            
update pod
Yuki Kimoto authored on 2011-03-13
2249
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2250
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2251
        user => 'ken',
2252
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2253
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2254
    );
2255

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

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

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

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

            
2266
Get rows count.
2267

            
2268
Options is same as C<select> method's ones.
2269

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2272
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2273
        table => 'book',
2274
        primary_key => 'id',
2275
        join => [
2276
            'inner join company on book.comparny_id = company.id'
2277
        ],
2278
    );
2279

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

            
2283
   $dbi->model('book')->select(...);
2284

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

            
2287
    my $dbh = $dbi->dbh;
2288

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

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

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

            
2296
Execute delete statement.
2297

            
2298
The following opitons are available.
2299

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

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

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

            
2307
=item C<id>
2308

            
2309
    id => 4
2310
    id => [4, 5]
2311

            
2312
ID corresponding to C<primary_key>.
2313
You can delete rows by C<id> and C<primary_key>.
2314

            
2315
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2316
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2317
        id => [4, 5],
2318
        table => 'book',
2319
    );
2320

            
2321
The above is same as the followin one.
2322

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

            
2325
=item C<prefix>
2326

            
2327
    prefix => 'some'
2328

            
2329
prefix before table name section.
2330

            
2331
    delete some from book
2332

            
2333
=item C<table>
2334

            
2335
    table => 'book'
2336

            
2337
Table name.
2338

            
2339
=item C<where>
2340

            
2341
Same as C<select> method's C<where> option.
2342

            
2343
=back
2344

            
2345
=head2 C<delete_all>
2346

            
2347
    $dbi->delete_all(table => $table);
2348

            
2349
Execute delete statement for all rows.
2350
Options is same as C<delete>.
2351

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

            
2354
    $dbi->each_column(
2355
        sub {
2356
            my ($dbi, $table, $column, $column_info) = @_;
2357
            
2358
            my $type = $column_info->{TYPE_NAME};
2359
            
2360
            if ($type eq 'DATE') {
2361
                # ...
2362
            }
2363
        }
2364
    );
2365

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

            
2371
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2372
infromation, you can improve the performance of C<each_column> in
2373
the following way.
2374

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

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

            
2381
    $dbi->each_table(
2382
        sub {
2383
            my ($dbi, $table, $table_info) = @_;
2384
            
2385
            my $table_name = $table_info->{TABLE_NAME};
2386
        }
2387
    );
2388

            
improved pod
Yuki Kimoto authored on 2011-10-14
2389
Iterate all table informationsfrom in database.
2390
Argument is callback which is executed when one table is found.
2391
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2392
C<table information>.
2393

            
2394
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2395
infromation, you can improve the performance of C<each_table> in
2396
the following way.
2397

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

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

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

            
2409
    my $result = $dbi->execute(
2410
      "select * from book where title = :book.title and author like :book.author",
2411
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2412
    );
2413

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2420
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2421
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2422
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2423
    select * from book where title = :title and author like :author
2424
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2425
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2426
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2427

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2431
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2432
    select * from book where :title{=} and :author{like}
2433
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2434
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2435
    select * from where title = ? and author like ?;
2436

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

            
2441
    select * from where title = "aa\\:bb";
2442

            
cleanup
Yuki Kimoto authored on 2011-10-20
2443
B<OPTIONS>
2444

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

            
2447
=over 4
2448

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2449
=item C<after_build_sql> 
2450

            
2451
You can filter sql after the sql is build.
2452

            
2453
    after_build_sql => $code_ref
2454

            
2455
The following one is one example.
2456

            
2457
    $dbi->select(
2458
        table => 'book',
2459
        column => 'distinct(name)',
2460
        after_build_sql => sub {
2461
            "select count(*) from ($_[0]) as t1"
2462
        }
2463
    );
2464

            
2465
The following SQL is executed.
2466

            
2467
    select count(*) from (select distinct(name) from book) as t1;
2468

            
cleanup
Yuki Kimoto authored on 2011-10-20
2469
=item C<append>
2470

            
2471
    append => 'order by name'
2472

            
2473
Append some statement after SQL.
2474

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

            
2477
Specify database bind data type.
2478

            
2479
    bind_type => [image => DBI::SQL_BLOB]
2480
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2481

            
2482
This is used to bind parameter by C<bind_param> of statment handle.
2483

            
2484
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2485

            
update pod
Yuki Kimoto authored on 2011-03-13
2486
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2487
    
2488
    filter => {
2489
        title  => sub { uc $_[0] }
2490
        author => sub { uc $_[0] }
2491
    }
update pod
Yuki Kimoto authored on 2011-03-13
2492

            
updated pod
Yuki Kimoto authored on 2011-06-09
2493
    # Filter name
2494
    filter => {
2495
        title  => 'upper_case',
2496
        author => 'upper_case'
2497
    }
2498
        
2499
    # At once
2500
    filter => [
2501
        [qw/title author/]  => sub { uc $_[0] }
2502
    ]
2503

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

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

            
2511
    id => 4
2512
    id => [4, 5]
2513

            
2514
ID corresponding to C<primary_key>.
2515
You can delete rows by C<id> and C<primary_key>.
2516

            
2517
    $dbi->execute(
2518
        "select * from book where id1 = :id1 and id2 = :id2",
2519
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2520
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2521
        id => [4, 5],
2522
    );
2523

            
2524
The above is same as the followin one.
2525

            
2526
    $dbi->execute(
2527
        "select * from book where id1 = :id1 and id2 = :id2",
2528
        {id1 => 4, id2 => 5}
2529
    );
2530

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

            
2533
    query => 1
2534

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

            
2538
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2539
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2540
    my $columns = $query->columns;
2541
    
2542
If you want to execute SQL fast, you can do the following way.
2543

            
2544
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2545
    for my $row (@$rows) {
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2546
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2547
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2548
    }
2549

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

            
2553
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
2554
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2555
    
2556
    my $query;
2557
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2558
    for my $row (@$rows) {
cleanup
Yuki Kimoto authored on 2011-07-30
2559
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2560
      $sth ||= $query->sth;
2561
      $sth->execute(map { $row->{$_} } sort keys %$row);
2562
    }
2563

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2570
    primary_key => 'id'
2571
    primary_key => ['id1', 'id2']
2572

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2575
=item C<table>
2576
    
2577
    table => 'author'
2578

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2586
    # Same
2587
    $dbi->execute(
2588
      "select * from book where title = :book.title and author = :book.author",
2589
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2590

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

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

            
2595
Table alias. Key is real table name, value is alias table name.
2596
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2597
on alias table name.
2598

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2599
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2600
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2601
    reuse_query => $has_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2602

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2603
Reuse query object if the hash reference variable is set.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2604
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2605
    my $queries = {};
2606
    $dbi->execute($sql, $param, reuse => $queries);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2607

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2608
This will improved performance when you want to execute same query repeatedly
2609
because generally creating query object is slow.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2610

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

            
2613
    type_rule_off => 1
2614

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

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

            
2619
    type_rule1_off => 1
2620

            
2621
Turn C<into1> type rule off.
2622

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

            
2625
    type_rule2_off => 1
2626

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

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

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

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

            
2635
get column infomation except for one which match C<exclude_table> pattern.
2636

            
2637
    [
2638
        {table => 'book', column => 'title', info => {...}},
2639
        {table => 'author', column => 'name' info => {...}}
2640
    ]
2641

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

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

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

            
2648
    [
2649
        {table => 'book', info => {...}},
2650
        {table => 'author', info => {...}}
2651
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2652

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

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

            
2657
    $dbi->helper(
2658
        update_or_insert => sub {
2659
            my $self = shift;
2660
            
2661
            # Process
2662
        },
2663
        find_or_create   => sub {
2664
            my $self = shift;
2665
            
2666
            # Process
2667
        }
2668
    );
2669

            
2670
Register helper. These helper is called directly from L<DBIx::Custom> object.
2671

            
2672
    $dbi->update_or_insert;
2673
    $dbi->find_or_create;
2674

            
cleanup
yuki-kimoto authored on 2010-10-17
2675
=head2 C<insert>
2676

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

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

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

            
2685
    {date => \"NOW()"}
2686

            
cleanup
Yuki Kimoto authored on 2011-10-20
2687
B<options>
2688

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2696
    id => 4
2697
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2698

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2702
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2703
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2704
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2705
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2706
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2707
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2708

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

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

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

            
2718
    prefix => 'or replace'
2719

            
2720
prefix before table name section
2721

            
2722
    insert or replace into book
2723

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

            
2726
    table => 'book'
2727

            
2728
Table name.
2729

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

            
2732
    timestamp => 1
2733

            
2734
If this value is set to 1,
2735
automatically created timestamp column is set based on
2736
C<timestamp> attribute's C<insert> value.
2737

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

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

            
2742
placeholder wrapped string.
2743

            
2744
If the following statement
2745

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

            
2749
is executed, the following SQL is executed.
2750

            
2751
    insert into book price values ( ? + 5 );
2752

            
update pod
Yuki Kimoto authored on 2011-03-13
2753
=back
2754

            
2755
=over 4
2756

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2764
    lib / MyModel.pm
2765
        / MyModel / book.pm
2766
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2767

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

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

            
2772
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2773
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2774
    
2775
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2776

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2781
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2782
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2783
    
2784
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2785

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2788
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2789
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2790
    
2791
    1;
2792
    
updated pod
Yuki Kimoto authored on 2011-06-21
2793
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2794

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

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

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

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

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
2804
    $dbi->insert_timestamp(
2805
      [qw/created_at updated_at/]
2806
        => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
2807
    );
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2808

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

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

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
2816
    $dbi->insert($param, table => 'book', timestamp => 1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2817

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

            
2820
    my $like_value = $dbi->like_value
2821

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

            
2824
    sub { "%$_[0]%" }
2825

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

            
2828
    my $mapper = $dbi->mapper(param => $param);
2829

            
2830
Create a new L<DBIx::Custom::Mapper> object.
2831

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

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

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

            
2838
    {key1 => [1, 1], key2 => 2}
2839

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

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

            
2844
    my $model = $dbi->model('book');
2845

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

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

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

            
2853
Create column clause for myself. The follwoing column clause is created.
2854

            
2855
    book.author as author,
2856
    book.title as title
2857

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

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

            
2867
Create a new L<DBIx::Custom> object.
2868

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

            
2871
    my $not_exists = $dbi->not_exists;
2872

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

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

            
2878
    my $order = $dbi->order;
2879

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2882
=head2 C<register_filter>
2883

            
update pod
Yuki Kimoto authored on 2011-03-13
2884
    $dbi->register_filter(
2885
        # Time::Piece object to database DATE format
2886
        tp_to_date => sub {
2887
            my $tp = shift;
2888
            return $tp->strftime('%Y-%m-%d');
2889
        },
2890
        # database DATE format to Time::Piece object
2891
        date_to_tp => sub {
2892
           my $date = shift;
2893
           return Time::Piece->strptime($date, '%Y-%m-%d');
2894
        }
2895
    );
cleanup
yuki-kimoto authored on 2010-10-17
2896
    
update pod
Yuki Kimoto authored on 2011-03-13
2897
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2898

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2901
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2902
        table  => 'book',
2903
        column => ['author', 'title'],
2904
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2905
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2906
    
updated document
Yuki Kimoto authored on 2011-06-09
2907
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2908

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2916
=item C<column>
2917
    
updated document
Yuki Kimoto authored on 2011-06-09
2918
    column => 'author'
2919
    column => ['author', 'title']
2920

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2929
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2930
        {book => [qw/author title/]},
2931
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2932
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2933

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

            
2936
    book.author as "book.author",
2937
    book.title as "book.title",
2938
    person.name as "person.name",
2939
    person.age as "person.age"
2940

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

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

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

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

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

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

            
2956
=item C<id>
2957

            
2958
    id => 4
2959
    id => [4, 5]
2960

            
2961
ID corresponding to C<primary_key>.
2962
You can select rows by C<id> and C<primary_key>.
2963

            
2964
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2965
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2966
        id => [4, 5],
2967
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2968
    );
2969

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2972
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2973
        where => {id1 => 4, id2 => 5},
2974
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2975
    );
2976
    
cleanup
Yuki Kimoto authored on 2011-10-20
2977
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2978

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

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

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

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

            
2991
    prefix => 'SQL_CALC_FOUND_ROWS'
2992

            
2993
Prefix of column cluase
2994

            
2995
    select SQL_CALC_FOUND_ROWS title, author from book;
2996

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

            
2999
    join => [
3000
        'left outer join company on book.company_id = company_id',
3001
        'left outer join location on company.location_id = location.id'
3002
    ]
3003
        
3004
Join clause. If column cluase or where clause contain table name like "company.name",
3005
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3006

            
3007
    $dbi->select(
3008
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3009
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3010
        where => {'company.name' => 'Orange'},
3011
        join => [
3012
            'left outer join company on book.company_id = company.id',
3013
            'left outer join location on company.location_id = location.id'
3014
        ]
3015
    );
3016

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3020
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3021
    from book
3022
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3023
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3024

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3025
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
3026
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3027

            
3028
    $dbi->select(
3029
        table => 'book',
3030
        column => ['company.location_id as location_id'],
3031
        where => {'company.name' => 'Orange'},
3032
        join => [
3033
            {
3034
                clause => 'left outer join location on company.location_id = location.id',
3035
                table => ['company', 'location']
3036
            }
3037
        ]
3038
    );
3039

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3044
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3045

            
updated document
Yuki Kimoto authored on 2011-06-09
3046
=item C<where>
3047
    
3048
    # Hash refrence
3049
    where => {author => 'Ken', 'title' => 'Perl'}
3050
    
3051
    # DBIx::Custom::Where object
3052
    where => $dbi->where(
3053
        clause => ['and', 'author = :author', 'title like :title'],
3054
        param  => {author => 'Ken', title => '%Perl%'}
3055
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3056
    
3057
    # Array reference 1 (array reference, hash referenc). same as above
3058
    where => [
3059
        ['and', 'author = :author', 'title like :title'],
3060
        {author => 'Ken', title => '%Perl%'}
3061
    ];    
3062
    
3063
    # Array reference 2 (String, hash reference)
3064
    where => [
3065
        'title like :title',
3066
        {title => '%Perl%'}
3067
    ]
3068
    
3069
    # String
3070
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3071

            
cleanup
Yuki Kimoto authored on 2011-10-20
3072
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3073
    
update pod
Yuki Kimoto authored on 2011-03-12
3074
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3075

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

            
3078
    $dbi->setup_model;
3079

            
3080
Setup all model objects.
3081
C<columns> of model object is automatically set, parsing database information.
3082

            
3083
=head2 C<type_rule>
3084

            
3085
    $dbi->type_rule(
3086
        into1 => {
3087
            date => sub { ... },
3088
            datetime => sub { ... }
3089
        },
3090
        into2 => {
3091
            date => sub { ... },
3092
            datetime => sub { ... }
3093
        },
3094
        from1 => {
3095
            # DATE
3096
            9 => sub { ... },
3097
            # DATETIME or TIMESTAMP
3098
            11 => sub { ... },
3099
        }
3100
        from2 => {
3101
            # DATE
3102
            9 => sub { ... },
3103
            # DATETIME or TIMESTAMP
3104
            11 => sub { ... },
3105
        }
3106
    );
3107

            
3108
Filtering rule when data is send into and get from database.
3109
This has a little complex problem.
3110

            
3111
In C<into1> and C<into2> you can specify
3112
type name as same as type name defined
3113
by create table, such as C<DATETIME> or C<DATE>.
3114

            
3115
Note that type name and data type don't contain upper case.
3116
If these contain upper case charactor, you convert it to lower case.
3117

            
3118
C<into2> is executed after C<into1>.
3119

            
3120
Type rule of C<into1> and C<into2> is enabled on the following
3121
column name.
3122

            
3123
=over 4
3124

            
3125
=item 1. column name
3126

            
3127
    issue_date
3128
    issue_datetime
3129

            
3130
This need C<table> option in each method.
3131

            
3132
=item 2. table name and column name, separator is dot
3133

            
3134
    book.issue_date
3135
    book.issue_datetime
3136

            
3137
=back
3138

            
3139
You get all type name used in database by C<available_typename>.
3140

            
3141
    print $dbi->available_typename;
3142

            
3143
In C<from1> and C<from2> you specify data type, not type name.
3144
C<from2> is executed after C<from1>.
3145
You get all data type by C<available_datatype>.
3146

            
3147
    print $dbi->available_datatype;
3148

            
3149
You can also specify multiple types at once.
3150

            
3151
    $dbi->type_rule(
3152
        into1 => [
3153
            [qw/DATE DATETIME/] => sub { ... },
3154
        ],
3155
    );
3156

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

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

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

            
3163
If you want to set constant value to row data, use scalar reference
3164
as parameter value.
3165

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3177
    id => 4
3178
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3179

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3183
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3184
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3185
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3186
        id => [4, 5],
3187
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3188
    );
update pod
Yuki Kimoto authored on 2011-03-13
3189

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3192
    $dbi->update(
3193
        {title => 'Perl', author => 'Ken'}
3194
        where => {id1 => 4, id2 => 5},
3195
        table => 'book'
3196
    );
update pod
Yuki Kimoto authored on 2011-03-13
3197

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

            
3200
    prefix => 'or replace'
3201

            
3202
prefix before table name section
3203

            
3204
    update or replace book
3205

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

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

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

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

            
3214
    timestamp => 1
3215

            
3216
If this value is set to 1,
3217
automatically updated timestamp column is set based on
3218
C<timestamp> attribute's C<update> value.
3219

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

            
3222
Same as C<select> method's C<where> option.
3223

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

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

            
3228
placeholder wrapped string.
3229

            
3230
If the following statement
3231

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

            
3235
is executed, the following SQL is executed.
3236

            
3237
    update book set price =  ? + 5;
3238

            
updated pod
Yuki Kimoto authored on 2011-06-08
3239
=back
update pod
Yuki Kimoto authored on 2011-03-13
3240

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3248
=head2 C<update_or_insert EXPERIMENTAL>
3249
    
3250
    # Where
3251
    $dbi->update_or_insert(
3252
        {id => 1, title => 'Perl'},
3253
        table => 'book',
3254
        where => {id => 1},
3255
        select_option => {append => 'for update'}
3256
    );
3257
    
3258
    # ID
3259
    $dbi->update_or_insert(
3260
        {title => 'Perl'},
3261
        table => 'book',
3262
        id => 1,
3263
        primary_key => 'id',
3264
        select_option => {append => 'for update'}
3265
    );
3266
    
3267
Update or insert.
3268

            
3269
In both examples, the following SQL is executed.
3270

            
3271
    # In case insert
3272
    insert into book (id, title) values (?, ?)
3273
    
3274
    # In case update
3275
    update book set (id = ?, title = ?) where book.id = ?
3276

            
3277
The following opitons are available adding to C<update> option.
3278

            
3279
=over 4
3280

            
3281
=item C<select_option>
3282

            
3283
    select_option => {append => 'for update'}
3284

            
3285
select method option,
3286
select method is used to check the row is already exists.
3287

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

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

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

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

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

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

            
3308
    $dbi->show_datatype($table);
3309

            
3310
Show data type of the columns of specified table.
3311

            
3312
    book
3313
    title: 5
3314
    issue_date: 91
3315

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

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

            
3320
    $dbi->show_tables;
3321

            
3322
Show tables.
3323

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

            
3326
    $dbi->show_typename($table);
3327

            
3328
Show type name of the columns of specified table.
3329

            
3330
    book
3331
    title: varchar
3332
    issue_date: date
3333

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

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

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

            
3340
Create values clause.
3341

            
3342
    (title, author) values (title = :title, age = :age);
3343

            
3344
You can use this in insert statement.
3345

            
3346
    my $insert_sql = "insert into book $values_clause";
3347

            
3348
=head2 C<where>
3349

            
3350
    my $where = $dbi->where(
3351
        clause => ['and', 'title = :title', 'author = :author'],
3352
        param => {title => 'Perl', author => 'Ken'}
3353
    );
3354

            
3355
Create a new L<DBIx::Custom::Where> object.
3356

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

            
3359
=head2 C<DBIX_CUSTOM_DEBUG>
3360

            
3361
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3362
executed SQL and bind values are printed to STDERR.
3363

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

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

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

            
3370
L<DBIx::Custom>
3371

            
3372
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3373
    default_dbi_option # will be removed 2017/1/1
3374
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3375
    data_source # will be removed at 2017/1/1
3376
    dbi_options # will be removed at 2017/1/1
3377
    filter_check # will be removed at 2017/1/1
3378
    reserved_word_quote # will be removed at 2017/1/1
3379
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3380
    
3381
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3382
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3383
    assign_param # will be removed at 2017/1/1
3384
    update_param # will be removed at 2017/1/1
3385
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3386
    create_query # will be removed at 2017/1/1
3387
    apply_filter # will be removed at 2017/1/1
3388
    select_at # will be removed at 2017/1/1
3389
    delete_at # will be removed at 2017/1/1
3390
    update_at # will be removed at 2017/1/1
3391
    insert_at # will be removed at 2017/1/1
3392
    register_tag # will be removed at 2017/1/1
3393
    default_bind_filter # will be removed at 2017/1/1
3394
    default_fetch_filter # will be removed at 2017/1/1
3395
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3396
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3397
    register_tag_processor # will be removed at 2017/1/1
3398
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3399
    
3400
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3401
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3402
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3403
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3404
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3405
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3406
    select method relation option # will be removed at 2017/1/1
3407
    select method column option [COLUMN, as => ALIAS] format
3408
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3409
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3410
    
3411
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3412
    execute("select * from {= title}"); # execute method's
3413
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3414
                                        # will be removed at 2017/1/1
3415
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3416

            
3417
L<DBIx::Custom::Model>
3418

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3419
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3420
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3421
    filter # will be removed at 2017/1/1
3422
    name # will be removed at 2017/1/1
3423
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3424

            
3425
L<DBIx::Custom::Query>
3426
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3427
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3428
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3429
    table # will be removed at 2017/1/1
3430
    filters # will be removed at 2017/1/1
3431
    
3432
    # Methods
3433
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3434

            
3435
L<DBIx::Custom::QueryBuilder>
3436
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3437
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3438
    tags # will be removed at 2017/1/1
3439
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3440
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3441
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3442
    register_tag # will be removed at 2017/1/1
3443
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3444
    
3445
    # Others
3446
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3447
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3448

            
3449
L<DBIx::Custom::Result>
3450
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3451
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3452
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3453
    
3454
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3455
    end_filter # will be removed at 2017/1/1
3456
    remove_end_filter # will be removed at 2017/1/1
3457
    remove_filter # will be removed at 2017/1/1
3458
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3459

            
3460
L<DBIx::Custom::Tag>
3461

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

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

            
3466
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3467
except for attribute method.
3468
You can check all DEPRECATED functionalities by document.
3469
DEPRECATED functionality is removed after five years,
3470
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
3471
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3472

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

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

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

            
3479
C<< <kimoto.yuki at gmail.com> >>
3480

            
3481
L<http://github.com/yuki-kimoto/DBIx-Custom>
3482

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3483
=head1 AUTHOR
3484

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

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

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

            
3491
This program is free software; you can redistribute it and/or modify it
3492
under the same terms as Perl itself.
3493

            
3494
=cut