DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3490 lines | 90.169kb
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-22
4
our $VERSION = '0.1734';
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
    
1420
    my $quote = $self->_quote;
1421
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1422
    my $p;
1423
    if (defined $quote && length $quote > 1) {
1424
        $p = substr($quote, 1, 1);
1425
    }
1426
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1427
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1428
    if ($quotemeta) {
1429
        $q = quotemeta($q);
1430
        $p = quotemeta($p);
1431
    }
1432
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1433
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1434
}
1435

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

            
1449
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1450
}
1451

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

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

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

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

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

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

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

            
1631
# DEPRECATED!
1632
sub assign_param {
1633
    my $self = shift;
1634
    warn "assing_param is DEPRECATED! use assign_clause instead";
1635
    return $self->assign_clause(@_);
1636
}
1637

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

            
1648
    return $tag;
1649
}
1650

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1705
# DEPRECATED!
1706
sub update_at {
1707
    my $self = shift;
1708

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1797
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1798
sub default_fetch_filter {
1799
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1800

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1880
=head1 NAME
1881

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1955
Named place holder support
1956

            
1957
=item *
1958

            
cleanup
Yuki Kimoto authored on 2011-07-29
1959
Model support
1960

            
1961
=item *
1962

            
1963
Connection manager support
1964

            
1965
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1966

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

            
1971
=item *
1972

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

            
1975
=item *
1976

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

            
1979
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1980

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

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

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

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

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

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

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

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

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

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

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

            
2020
    my $dbi = DBIx::Custom->connect(
2021
      dsn => $dsn, user => $user, password => $password, connector => 1);
2022
    
2023
    my $connector = $dbi->connector; # DBIx::Connector
2024

            
2025
Note that L<DBIx::Connector> must be installed.
2026

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

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

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

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

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

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

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

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

            
2050
    my $exclude_table = $dbi->exclude_table;
2051
    $dbi = $dbi->exclude_table(qr/pg_/);
2052

            
2053
Excluded table regex.
2054
C<each_column>, C<each_table>, C<type_rule>,
2055
and C<setup_model> methods ignore matching tables.
2056

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

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

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

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

            
2066
    my $last_sql = $dbi->last_sql;
2067
    $dbi = $dbi->last_sql($last_sql);
2068

            
2069
Get last successed SQL executed by C<execute> method.
2070

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

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

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

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

            
2080
    my $option = $dbi->option;
2081
    $dbi = $dbi->option($option);
2082

            
2083
L<DBI> option, used when C<connect> method is executed.
2084
Each value in option override the value of C<default_option>.
2085

            
cleanup
yuki-kimoto authored on 2010-10-17
2086
=head2 C<password>
2087

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2108
You can set quote pair.
2109

            
2110
    $dbi->quote('[]');
2111

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2121
    my $safety_character = $dbi->safety_character;
2122
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2123

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

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

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

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

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

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

            
2140
    my $tag_parse = $dbi->tag_parse(0);
2141
    $dbi = $dbi->tag_parse;
2142

            
2143
Enable DEPRECATED tag parsing functionality, default to 1.
2144
If you want to disable tag parsing functionality, set to 0.
2145

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

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

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

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

            
2155
    my $user_column_info = $dbi->user_column_info;
2156
    $dbi = $dbi->user_column_info($user_column_info);
2157

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

            
2160
    [
2161
        {table => 'book', column => 'title', info => {...}},
2162
        {table => 'author', column => 'name', info => {...}}
2163
    ]
2164

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

            
2167
    my $user_column_info
2168
      = $dbi->get_column_info(exclude_table => qr/^system/);
2169
    $dbi->user_column_info($user_column_info);
2170

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

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

            
2176
    my $user_table_info = $dbi->user_table_info;
2177
    $dbi = $dbi->user_table_info($user_table_info);
2178

            
2179
You can set the following data.
2180

            
2181
    [
2182
        {table => 'book', info => {...}},
2183
        {table => 'author', info => {...}}
2184
    ]
2185

            
2186
Usually, you can set return value of C<get_table_info>.
2187

            
2188
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2189
    $dbi->user_table_info($user_table_info);
2190

            
2191
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2192
to find table info.
2193

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2230
Create column clause. The follwoing column clause is created.
2231

            
2232
    book.author as "book.author",
2233
    book.title as "book.title"
2234

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

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

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

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

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

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

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

            
2262
Get rows count.
2263

            
2264
Options is same as C<select> method's ones.
2265

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

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

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

            
2279
   $dbi->model('book')->select(...);
2280

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

            
2283
    my $dbh = $dbi->dbh;
2284

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

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

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

            
2292
Execute delete statement.
2293

            
2294
The following opitons are available.
2295

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

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

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

            
2303
=item C<id>
2304

            
2305
    id => 4
2306
    id => [4, 5]
2307

            
2308
ID corresponding to C<primary_key>.
2309
You can delete rows by C<id> and C<primary_key>.
2310

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

            
2317
The above is same as the followin one.
2318

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

            
2321
=item C<prefix>
2322

            
2323
    prefix => 'some'
2324

            
2325
prefix before table name section.
2326

            
2327
    delete some from book
2328

            
2329
=item C<table>
2330

            
2331
    table => 'book'
2332

            
2333
Table name.
2334

            
2335
=item C<where>
2336

            
2337
Same as C<select> method's C<where> option.
2338

            
2339
=back
2340

            
2341
=head2 C<delete_all>
2342

            
2343
    $dbi->delete_all(table => $table);
2344

            
2345
Execute delete statement for all rows.
2346
Options is same as C<delete>.
2347

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

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

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

            
2367
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2368
infromation, you can improve the performance of C<each_column> in
2369
the following way.
2370

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

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

            
2377
    $dbi->each_table(
2378
        sub {
2379
            my ($dbi, $table, $table_info) = @_;
2380
            
2381
            my $table_name = $table_info->{TABLE_NAME};
2382
        }
2383
    );
2384

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

            
2390
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2391
infromation, you can improve the performance of C<each_table> in
2392
the following way.
2393

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

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

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

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

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

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

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

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

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

            
2437
    select * from where title = "aa\\:bb";
2438

            
cleanup
Yuki Kimoto authored on 2011-10-20
2439
B<OPTIONS>
2440

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

            
2443
=over 4
2444

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

            
2447
You can filter sql after the sql is build.
2448

            
2449
    after_build_sql => $code_ref
2450

            
2451
The following one is one example.
2452

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

            
2461
The following SQL is executed.
2462

            
2463
    select count(*) from (select distinct(name) from book) as t1;
2464

            
cleanup
Yuki Kimoto authored on 2011-10-20
2465
=item C<append>
2466

            
2467
    append => 'order by name'
2468

            
2469
Append some statement after SQL.
2470

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

            
2473
Specify database bind data type.
2474

            
2475
    bind_type => [image => DBI::SQL_BLOB]
2476
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2477

            
2478
This is used to bind parameter by C<bind_param> of statment handle.
2479

            
2480
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2481

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

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

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

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

            
2507
    id => 4
2508
    id => [4, 5]
2509

            
2510
ID corresponding to C<primary_key>.
2511
You can delete rows by C<id> and C<primary_key>.
2512

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

            
2520
The above is same as the followin one.
2521

            
2522
    $dbi->execute(
2523
        "select * from book where id1 = :id1 and id2 = :id2",
2524
        {id1 => 4, id2 => 5}
2525
    );
2526

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

            
2529
    query => 1
2530

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2566
    primary_key => 'id'
2567
    primary_key => ['id1', 'id2']
2568

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2571
=item C<table>
2572
    
2573
    table => 'author'
2574

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

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

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

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

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

            
2591
Table alias. Key is real table name, value is alias table name.
2592
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2593
on alias table name.
2594

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2595
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2596
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2597
    reuse_query => $has_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2598

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

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

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

            
2609
    type_rule_off => 1
2610

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

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

            
2615
    type_rule1_off => 1
2616

            
2617
Turn C<into1> type rule off.
2618

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

            
2621
    type_rule2_off => 1
2622

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

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

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

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

            
2631
get column infomation except for one which match C<exclude_table> pattern.
2632

            
2633
    [
2634
        {table => 'book', column => 'title', info => {...}},
2635
        {table => 'author', column => 'name' info => {...}}
2636
    ]
2637

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

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

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

            
2644
    [
2645
        {table => 'book', info => {...}},
2646
        {table => 'author', info => {...}}
2647
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2648

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

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

            
2653
    $dbi->helper(
2654
        update_or_insert => sub {
2655
            my $self = shift;
2656
            
2657
            # Process
2658
        },
2659
        find_or_create   => sub {
2660
            my $self = shift;
2661
            
2662
            # Process
2663
        }
2664
    );
2665

            
2666
Register helper. These helper is called directly from L<DBIx::Custom> object.
2667

            
2668
    $dbi->update_or_insert;
2669
    $dbi->find_or_create;
2670

            
cleanup
yuki-kimoto authored on 2010-10-17
2671
=head2 C<insert>
2672

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

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

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

            
2681
    {date => \"NOW()"}
2682

            
cleanup
Yuki Kimoto authored on 2011-10-20
2683
B<options>
2684

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2692
    id => 4
2693
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2694

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

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

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

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

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

            
2714
    prefix => 'or replace'
2715

            
2716
prefix before table name section
2717

            
2718
    insert or replace into book
2719

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

            
2722
    table => 'book'
2723

            
2724
Table name.
2725

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

            
2728
    timestamp => 1
2729

            
2730
If this value is set to 1,
2731
automatically created timestamp column is set based on
2732
C<timestamp> attribute's C<insert> value.
2733

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

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

            
2738
placeholder wrapped string.
2739

            
2740
If the following statement
2741

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

            
2745
is executed, the following SQL is executed.
2746

            
2747
    insert into book price values ( ? + 5 );
2748

            
update pod
Yuki Kimoto authored on 2011-03-13
2749
=back
2750

            
2751
=over 4
2752

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2760
    lib / MyModel.pm
2761
        / MyModel / book.pm
2762
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2763

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2777
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2778
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2779
    
2780
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2781

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

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

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

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

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

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

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

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

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

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

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

            
2816
    my $like_value = $dbi->like_value
2817

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

            
2820
    sub { "%$_[0]%" }
2821

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

            
2824
    my $mapper = $dbi->mapper(param => $param);
2825

            
2826
Create a new L<DBIx::Custom::Mapper> object.
2827

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

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

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

            
2834
    {key1 => [1, 1], key2 => 2}
2835

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

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

            
2840
    my $model = $dbi->model('book');
2841

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

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

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

            
2849
Create column clause for myself. The follwoing column clause is created.
2850

            
2851
    book.author as author,
2852
    book.title as title
2853

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

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

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

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

            
2867
    my $not_exists = $dbi->not_exists;
2868

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

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

            
2874
    my $order = $dbi->order;
2875

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2878
=head2 C<register_filter>
2879

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2925
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2926
        {book => [qw/author title/]},
2927
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2928
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2929

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

            
2932
    book.author as "book.author",
2933
    book.title as "book.title",
2934
    person.name as "person.name",
2935
    person.age as "person.age"
2936

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

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

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

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

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

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

            
2952
=item C<id>
2953

            
2954
    id => 4
2955
    id => [4, 5]
2956

            
2957
ID corresponding to C<primary_key>.
2958
You can select rows by C<id> and C<primary_key>.
2959

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

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

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

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

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

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

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

            
2987
    prefix => 'SQL_CALC_FOUND_ROWS'
2988

            
2989
Prefix of column cluase
2990

            
2991
    select SQL_CALC_FOUND_ROWS title, author from book;
2992

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3016
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3017
    from book
3018
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3019
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3020

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3021
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
3022
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3023

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3040
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3041

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3068
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3069
    
update pod
Yuki Kimoto authored on 2011-03-12
3070
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3071

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

            
3074
    $dbi->setup_model;
3075

            
3076
Setup all model objects.
3077
C<columns> of model object is automatically set, parsing database information.
3078

            
3079
=head2 C<type_rule>
3080

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

            
3104
Filtering rule when data is send into and get from database.
3105
This has a little complex problem.
3106

            
3107
In C<into1> and C<into2> you can specify
3108
type name as same as type name defined
3109
by create table, such as C<DATETIME> or C<DATE>.
3110

            
3111
Note that type name and data type don't contain upper case.
3112
If these contain upper case charactor, you convert it to lower case.
3113

            
3114
C<into2> is executed after C<into1>.
3115

            
3116
Type rule of C<into1> and C<into2> is enabled on the following
3117
column name.
3118

            
3119
=over 4
3120

            
3121
=item 1. column name
3122

            
3123
    issue_date
3124
    issue_datetime
3125

            
3126
This need C<table> option in each method.
3127

            
3128
=item 2. table name and column name, separator is dot
3129

            
3130
    book.issue_date
3131
    book.issue_datetime
3132

            
3133
=back
3134

            
3135
You get all type name used in database by C<available_typename>.
3136

            
3137
    print $dbi->available_typename;
3138

            
3139
In C<from1> and C<from2> you specify data type, not type name.
3140
C<from2> is executed after C<from1>.
3141
You get all data type by C<available_datatype>.
3142

            
3143
    print $dbi->available_datatype;
3144

            
3145
You can also specify multiple types at once.
3146

            
3147
    $dbi->type_rule(
3148
        into1 => [
3149
            [qw/DATE DATETIME/] => sub { ... },
3150
        ],
3151
    );
3152

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

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

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

            
3159
If you want to set constant value to row data, use scalar reference
3160
as parameter value.
3161

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3173
    id => 4
3174
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3175

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

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

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

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

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

            
3196
    prefix => 'or replace'
3197

            
3198
prefix before table name section
3199

            
3200
    update or replace book
3201

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

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

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

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

            
3210
    timestamp => 1
3211

            
3212
If this value is set to 1,
3213
automatically updated timestamp column is set based on
3214
C<timestamp> attribute's C<update> value.
3215

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

            
3218
Same as C<select> method's C<where> option.
3219

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

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

            
3224
placeholder wrapped string.
3225

            
3226
If the following statement
3227

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

            
3231
is executed, the following SQL is executed.
3232

            
3233
    update book set price =  ? + 5;
3234

            
updated pod
Yuki Kimoto authored on 2011-06-08
3235
=back
update pod
Yuki Kimoto authored on 2011-03-13
3236

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

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

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

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

            
3265
In both examples, the following SQL is executed.
3266

            
3267
    # In case insert
3268
    insert into book (id, title) values (?, ?)
3269
    
3270
    # In case update
3271
    update book set (id = ?, title = ?) where book.id = ?
3272

            
3273
The following opitons are available adding to C<update> option.
3274

            
3275
=over 4
3276

            
3277
=item C<select_option>
3278

            
3279
    select_option => {append => 'for update'}
3280

            
3281
select method option,
3282
select method is used to check the row is already exists.
3283

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

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

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

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

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

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

            
3304
    $dbi->show_datatype($table);
3305

            
3306
Show data type of the columns of specified table.
3307

            
3308
    book
3309
    title: 5
3310
    issue_date: 91
3311

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

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

            
3316
    $dbi->show_tables;
3317

            
3318
Show tables.
3319

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

            
3322
    $dbi->show_typename($table);
3323

            
3324
Show type name of the columns of specified table.
3325

            
3326
    book
3327
    title: varchar
3328
    issue_date: date
3329

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

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

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

            
3336
Create values clause.
3337

            
3338
    (title, author) values (title = :title, age = :age);
3339

            
3340
You can use this in insert statement.
3341

            
3342
    my $insert_sql = "insert into book $values_clause";
3343

            
3344
=head2 C<where>
3345

            
3346
    my $where = $dbi->where(
3347
        clause => ['and', 'title = :title', 'author = :author'],
3348
        param => {title => 'Perl', author => 'Ken'}
3349
    );
3350

            
3351
Create a new L<DBIx::Custom::Where> object.
3352

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

            
3355
=head2 C<DBIX_CUSTOM_DEBUG>
3356

            
3357
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3358
executed SQL and bind values are printed to STDERR.
3359

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

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

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

            
3366
L<DBIx::Custom>
3367

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

            
3413
L<DBIx::Custom::Model>
3414

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

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

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

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

            
3456
L<DBIx::Custom::Tag>
3457

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

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

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

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

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

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

            
3475
C<< <kimoto.yuki at gmail.com> >>
3476

            
3477
L<http://github.com/yuki-kimoto/DBIx-Custom>
3478

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3479
=head1 AUTHOR
3480

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

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

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

            
3487
This program is free software; you can redistribute it and/or modify it
3488
under the same terms as Perl itself.
3489

            
3490
=cut