DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3465 lines | 89.503kb
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} || {};
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
    
127
    # Create set tag
128
    my @params;
129
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-10-21
130
    for my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
131
        croak qq{"$column" is not safety column name } . _subname
132
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
133
        my $column_quote = $self->_q($column);
134
        $column_quote =~ s/\./$self->_q(".")/e;
updated pod
Yuki Kimoto authored on 2011-09-02
135
        my $func = $wrap->{$column} || sub { $_[0] };
136
        push @params,
137
          ref $param->{$column} eq 'SCALAR' ? "$column_quote = " . ${$param->{$column}}
138
        : "$column_quote = " . $func->(":$column");
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
139
    }
140
    my $tag = join(', ', @params);
141
    
142
    return $tag;
143
}
144

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added test
Yuki Kimoto authored on 2011-08-16
508
sub get_table_info {
cleanup
Yuki Kimoto authored on 2011-10-21
509
    my ($self, %opt) = @_;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
510
    
cleanup
Yuki Kimoto authored on 2011-10-21
511
    my $exclude = delete $opt{exclude};
512
    croak qq/"$_" is wrong option/ for keys %opt;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
513
    
added test
Yuki Kimoto authored on 2011-08-16
514
    my $table_info = [];
515
    $self->each_table(
516
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
517
        exclude => $exclude
518
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
519
    
cleanup test
Yuki Kimoto authored on 2011-08-16
520
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
521
}
522

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
523
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
524
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
525
    
cleanup
Yuki Kimoto authored on 2011-10-21
526
    my $exclude_table = delete $opt{exclude_table};
527
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
528
    
529
    my $column_info = [];
530
    $self->each_column(
531
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
532
        exclude_table => $exclude_table
533
    );
534
    
535
    return [
536
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
537
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
538
}
539

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
540
sub helper {
541
    my $self = shift;
542
    
543
    # Register method
544
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
545
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
546
    
547
    return $self;
548
}
549

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
583
sub insert_timestamp {
584
    my $self = shift;
585
    
586
    if (@_) {
587
        $self->{insert_timestamp} = [@_];
588
        
589
        return $self;
590
    }
591
    return $self->{insert_timestamp};
592
}
593

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
594
sub include_model {
595
    my ($self, $name_space, $model_infos) = @_;
596
    
cleanup
Yuki Kimoto authored on 2011-04-02
597
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
598
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
599
    
600
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
601
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
602

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
661
sub mapper {
662
    my $self = shift;
663
    return DBIx::Custom::Mapper->new(@_);
664
}
665

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
690
sub model {
691
    my ($self, $name, $model) = @_;
692
    
cleanup
Yuki Kimoto authored on 2011-04-02
693
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
694
    if ($model) {
695
        $self->models->{$name} = $model;
696
        return $self;
697
    }
698
    
699
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
700
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
701
      unless $self->models->{$name};
702
    
cleanup
Yuki Kimoto authored on 2011-04-02
703
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
704
    return $self->models->{$name};
705
}
706

            
cleanup
Yuki Kimoto authored on 2011-03-21
707
sub mycolumn {
708
    my ($self, $table, $columns) = @_;
709
    
cleanup
Yuki Kimoto authored on 2011-04-02
710
    # Create column clause
711
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
712
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
713
    push @column, $self->_q($table) . "." . $self->_q($_) .
714
      " as " . $self->_q($_)
715
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
716
    
717
    return join (', ', @column);
718
}
719

            
added dbi_options attribute
kimoto authored on 2010-12-20
720
sub new {
721
    my $self = shift->SUPER::new(@_);
722
    
cleanup
Yuki Kimoto authored on 2011-04-02
723
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
724
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
725
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
726
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
727
          unless $self->can($attr);
728
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
729

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
730
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
731
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
732
        '?'     => \&DBIx::Custom::Tag::placeholder,
733
        '='     => \&DBIx::Custom::Tag::equal,
734
        '<>'    => \&DBIx::Custom::Tag::not_equal,
735
        '>'     => \&DBIx::Custom::Tag::greater_than,
736
        '<'     => \&DBIx::Custom::Tag::lower_than,
737
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
738
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
739
        'like'  => \&DBIx::Custom::Tag::like,
740
        'in'    => \&DBIx::Custom::Tag::in,
741
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
742
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
743
    };
744
    
745
    return $self;
746
}
747

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

            
750
sub order {
751
    my $self = shift;
752
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
753
}
754

            
cleanup
yuki-kimoto authored on 2010-10-17
755
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
756
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
757
    
758
    # Register filter
759
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
760
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
761
    
cleanup
Yuki Kimoto authored on 2011-04-02
762
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
763
}
packaging one directory
yuki-kimoto authored on 2009-11-16
764

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
853
sub setup_model {
854
    my $self = shift;
855
    
cleanup
Yuki Kimoto authored on 2011-04-02
856
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
857
    $self->each_column(
858
        sub {
859
            my ($self, $table, $column, $column_info) = @_;
860
            if (my $model = $self->models->{$table}) {
861
                push @{$model->columns}, $column;
862
            }
863
        }
864
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
865
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
866
}
867

            
update pod
Yuki Kimoto authored on 2011-08-10
868
sub show_datatype {
869
    my ($self, $table) = @_;
870
    croak "Table name must be specified" unless defined $table;
871
    print "$table\n";
872
    
873
    my $result = $self->select(table => $table, where => "'0' <> '0'");
874
    my $sth = $result->sth;
875

            
876
    my $columns = $sth->{NAME};
877
    my $data_types = $sth->{TYPE};
878
    
879
    for (my $i = 0; $i < @$columns; $i++) {
880
        my $column = $columns->[$i];
881
        my $data_type = $data_types->[$i];
882
        print "$column: $data_type\n";
883
    }
884
}
885

            
886
sub show_typename {
887
    my ($self, $t) = @_;
888
    croak "Table name must be specified" unless defined $t;
889
    print "$t\n";
890
    
891
    $self->each_column(sub {
892
        my ($self, $table, $column, $infos) = @_;
893
        return unless $table eq $t;
894
        my $typename = $infos->{TYPE_NAME};
895
        print "$column: $typename\n";
896
    });
897
    
898
    return $self;
899
}
900

            
test cleanup
Yuki Kimoto authored on 2011-08-15
901
sub show_tables {
902
    my $self = shift;
903
    
904
    my %tables;
905
    $self->each_table(sub { $tables{$_[1]}++ });
906
    print join("\n", sort keys %tables) . "\n";
907
    return $self;
908
}
909

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
945
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
946
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
947
                }
948
            });
949
        }
950

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
997
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
998
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
999
    
1000
    # Convert id to where parameter
1001
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1002
      ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
1003
      : $opt{where};
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1004

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1022
sub update_or_insert {
1023
    my $self = shift;
1024

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1058
sub update_timestamp {
1059
    my $self = shift;
1060
    
1061
    if (@_) {
1062
        $self->{update_timestamp} = [@_];
1063
        
1064
        return $self;
1065
    }
1066
    return $self->{update_timestamp};
1067
}
1068

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1069
sub values_clause {
1070
    my ($self, $param, $opts) = @_;
1071
    
1072
    my $wrap = $opts->{wrap} || {};
1073
    
1074
    # Create insert parameter tag
1075
    my $safety = $self->safety_character;
1076
    my @columns;
1077
    my @placeholders;
cleanup
Yuki Kimoto authored on 2011-10-21
1078
    for my $column (sort keys %$param) {
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1079
        croak qq{"$column" is not safety column name } . _subname
1080
          unless $column =~ /^[$safety\.]+$/;
1081
        my $column_quote = $self->_q($column);
1082
        $column_quote =~ s/\./$self->_q(".")/e;
1083
        push @columns, $column_quote;
1084
        
1085
        my $func = $wrap->{$column} || sub { $_[0] };
1086
        push @placeholders,
1087
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1088
        : $func->(":$column");
1089
    }
1090
    
1091
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1092
           '(' . join(', ', @placeholders) . ')'
1093
}
1094

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1097
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1098
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1099
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1100
    
updated pod
Yuki Kimoto authored on 2011-06-21
1101
    # Cache
1102
    my $cache = $self->cache;
1103
    
1104
    # Query
1105
    my $query;
1106
    
1107
    # Get cached query
1108
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1109
        
updated pod
Yuki Kimoto authored on 2011-06-21
1110
        # Get query
1111
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1112
        
updated pod
Yuki Kimoto authored on 2011-06-21
1113
        # Create query
1114
        if ($q) {
1115
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1116
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1117
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1118
    }
1119
    
1120
    # Create query
1121
    unless ($query) {
1122

            
1123
        # Create query
1124
        my $builder = $self->query_builder;
1125
        $query = $builder->build_query($source);
1126

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

            
1133
        # Save query to cache
1134
        $self->cache_method->(
1135
            $self, $source,
1136
            {
1137
                sql     => $query->sql, 
1138
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1139
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1140
            }
1141
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1142
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1143

            
1144
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1145
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1146
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1147
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1148
        $query->sql($sql);
1149
    }
1150
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1151
    # Save sql
1152
    $self->last_sql($query->sql);
1153
    
updated pod
Yuki Kimoto authored on 2011-06-21
1154
    # Prepare statement handle
1155
    my $sth;
1156
    eval { $sth = $self->dbh->prepare($query->{sql})};
1157
    
1158
    if ($@) {
1159
        $self->_croak($@, qq{. Following SQL is executed.\n}
1160
                        . qq{$query->{sql}\n} . _subname);
1161
    }
1162
    
1163
    # Set statement handle
1164
    $query->sth($sth);
1165
    
1166
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1167
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1168
    
1169
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1170
}
1171

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1284
sub _croak {
1285
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1286
    
1287
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1288
    $append ||= "";
1289
    
1290
    # Verbose
1291
    if ($Carp::Verbose) { croak $error }
1292
    
1293
    # Not verbose
1294
    else {
1295
        
1296
        # Remove line and module infromation
1297
        my $at_pos = rindex($error, ' at ');
1298
        $error = substr($error, 0, $at_pos);
1299
        $error =~ s/\s+$//;
1300
        croak "$error$append";
1301
    }
1302
}
1303

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1306
sub _need_tables {
1307
    my ($self, $tree, $need_tables, $tables) = @_;
1308
    
cleanup
Yuki Kimoto authored on 2011-04-02
1309
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1310
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1311
        if ($tree->{$table}) {
1312
            $need_tables->{$table} = 1;
1313
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1314
        }
1315
    }
1316
}
1317

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1318
sub _option {
1319
    my $self = shift;
1320
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1321
    warn "dbi_options is DEPRECATED! use option instead\n"
1322
      if keys %{$self->dbi_options};
1323
    warn "dbi_option is DEPRECATED! use option instead\n"
1324
      if keys %{$self->dbi_option};
1325
    return $option;
1326
}
1327

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1328
sub _push_join {
1329
    my ($self, $sql, $join, $join_tables) = @_;
1330
    
cleanup
Yuki Kimoto authored on 2011-10-21
1331
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1332
    
cleanup
Yuki Kimoto authored on 2011-04-02
1333
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1334
    return unless @$join;
1335
    
cleanup
Yuki Kimoto authored on 2011-04-02
1336
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1337
    my $tree = {};
1338
    for (my $i = 0; $i < @$join; $i++) {
1339
        
cleanup
Yuki Kimoto authored on 2011-07-28
1340
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1341
        my $join_clause;;
1342
        my $option;
1343
        if (ref $join->[$i] eq 'HASH') {
1344
            $join_clause = $join->[$i]->{clause};
1345
            $option = {table => $join->[$i]->{table}};
1346
        }
1347
        else {
1348
            $join_clause = $join->[$i];
1349
            $option = {};
1350
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1351

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1399
sub _quote {
1400
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1401
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1402
}
1403

            
cleanup
Yuki Kimoto authored on 2011-07-29
1404
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1405
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1406
    
1407
    my $quote = $self->_quote;
1408
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1409
    my $p;
1410
    if (defined $quote && length $quote > 1) {
1411
        $p = substr($quote, 1, 1);
1412
    }
1413
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1414
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1415
    if ($quotemeta) {
1416
        $q = quotemeta($q);
1417
        $p = quotemeta($p);
1418
    }
1419
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1420
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1421
}
1422

            
cleanup
Yuki Kimoto authored on 2011-04-02
1423
sub _remove_duplicate_table {
1424
    my ($self, $tables, $main_table) = @_;
1425
    
1426
    # Remove duplicate table
1427
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1428
    delete $tables{$main_table} if $main_table;
1429
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1430
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1431
    if (my $q = $self->_quote) {
1432
        $q = quotemeta($q);
1433
        $_ =~ s/[$q]//g for @$new_tables;
1434
    }
1435

            
1436
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1437
}
1438

            
cleanup
Yuki Kimoto authored on 2011-04-02
1439
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1440
    my ($self, $source) = @_;
1441
    
cleanup
Yuki Kimoto authored on 2011-04-02
1442
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1443
    my $tables = [];
1444
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1445
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1446
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1447
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1448
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1449
    while ($source =~ /$table_re/g) {
1450
        push @$tables, $1;
1451
    }
1452
    
1453
    return $tables;
1454
}
1455

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1505
sub _where_clause_and_param {
1506
    my ($self, $where, $param) = @_;
1507
 
1508
    $where ||= {};
1509
    $param ||= {};
1510
    my $w = {};
1511
    my $where_clause = '';
1512
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1513
        $w->{clause} = "where " . $where->[0];
1514
        $w->{param} = $where->[1];
1515
    }
1516
    elsif (ref $where) {
1517
        $where = $self->_where_to_obj($where);
1518
        $w->{param} = keys %$param
1519
                    ? $self->merge_param($param, $where->param)
1520
                    : $where->param;
1521
        $w->{clause} = $where->to_string;
1522
    }
1523
    elsif ($where) {
1524
        $w->{clause} = "where $where";
1525
        $w->{param} = $param;
1526
    }
1527
    
1528
    return $w;
1529
}
1530

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1601
# DEPRECATED!
1602
has 'data_source';
1603
has dbi_options => sub { {} };
1604
has filter_check  => 1;
1605
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1606
has dbi_option => sub { {} };
1607
has default_dbi_option => sub {
1608
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1609
    return shift->default_option;
1610
};
1611

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1612
# DEPRECATED!
1613
sub method {
1614
    warn "method is DEPRECATED! use helper instead";
1615
    return shift->helper(@_);
1616
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1617

            
1618
# DEPRECATED!
1619
sub assign_param {
1620
    my $self = shift;
1621
    warn "assing_param is DEPRECATED! use assign_clause instead";
1622
    return $self->assign_clause(@_);
1623
}
1624

            
1625
# DEPRECATED
1626
sub update_param {
1627
    my ($self, $param, $opts) = @_;
1628
    
1629
    warn "update_param is DEPRECATED! use assing_clause instead.";
1630
    
1631
    # Create update parameter tag
1632
    my $tag = $self->assign_clause($param, $opts);
1633
    $tag = "set $tag" unless $opts->{no_set};
1634

            
1635
    return $tag;
1636
}
1637

            
updated pod
Yuki Kimoto authored on 2011-06-21
1638
# DEPRECATED!
1639
sub create_query {
1640
    warn "create_query is DEPRECATED! use query option of each method";
1641
    shift->_create_query(@_);
1642
}
1643

            
cleanup
Yuki Kimoto authored on 2011-06-13
1644
# DEPRECATED!
1645
sub apply_filter {
1646
    my $self = shift;
1647
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1648
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1649
    return $self->_apply_filter(@_);
1650
}
1651

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1658
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1659
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1660
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1661
    my $where = delete $opt{where};
1662
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1663
    
1664
    # Table
1665
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1666
      unless $opt{table};
1667
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1668
    
1669
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1670
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1671
    
cleanup
Yuki Kimoto authored on 2011-10-21
1672
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1673
}
1674

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1679
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1680
    
cleanup
Yuki Kimoto authored on 2011-10-21
1681
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1682
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1683
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1684
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1685
    
1686
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1687
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1688
    
cleanup
Yuki Kimoto authored on 2011-10-21
1689
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1690
}
1691

            
cleanup
Yuki Kimoto authored on 2011-06-08
1692
# DEPRECATED!
1693
sub update_at {
1694
    my $self = shift;
1695

            
cleanup
Yuki Kimoto authored on 2011-10-21
1696
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1697
    
cleanup
Yuki Kimoto authored on 2011-10-21
1698
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1699
    my $param;
1700
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1701
    my %opt = @_;
1702
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1703
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1704
    my $where = delete $opt{where};
1705
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1706
    $param  ||= $p;
1707
    
1708
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1709
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1710
    
cleanup
Yuki Kimoto authored on 2011-10-21
1711
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1712
}
1713

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1737
# DEPRECATED!
1738
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1739
    my $self = shift;
1740
    
added warnings
Yuki Kimoto authored on 2011-06-07
1741
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1742
    
1743
    # Merge tag
1744
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1745
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1746
    
1747
    return $self;
1748
}
1749

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1760
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1761
sub default_bind_filter {
1762
    my $self = shift;
1763
    
cleanup
Yuki Kimoto authored on 2011-06-13
1764
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1765
    
cleanup
Yuki Kimoto authored on 2011-01-12
1766
    if (@_) {
1767
        my $fname = $_[0];
1768
        
1769
        if (@_ && !$fname) {
1770
            $self->{default_out_filter} = undef;
1771
        }
1772
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1773
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1774
              unless exists $self->filters->{$fname};
1775
        
1776
            $self->{default_out_filter} = $self->filters->{$fname};
1777
        }
1778
        return $self;
1779
    }
1780
    
1781
    return $self->{default_out_filter};
1782
}
1783

            
cleanup
Yuki Kimoto authored on 2011-01-25
1784
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1785
sub default_fetch_filter {
1786
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1787

            
cleanup
Yuki Kimoto authored on 2011-06-13
1788
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1789
    
1790
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1791
        my $fname = $_[0];
1792

            
cleanup
Yuki Kimoto authored on 2011-01-12
1793
        if (@_ && !$fname) {
1794
            $self->{default_in_filter} = undef;
1795
        }
1796
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1797
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1798
              unless exists $self->filters->{$fname};
1799
        
1800
            $self->{default_in_filter} = $self->filters->{$fname};
1801
        }
1802
        
1803
        return $self;
1804
    }
1805
    
many changed
Yuki Kimoto authored on 2011-01-23
1806
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1807
}
1808

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1809
# DEPRECATED!
1810
sub insert_param {
1811
    my $self = shift;
1812
    warn "insert_param is DEPRECATED! use values_clause instead";
1813
    return $self->values_clause(@_);
1814
}
1815

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1816
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1817
sub insert_param_tag {
1818
    warn "insert_param_tag is DEPRECATED! " .
1819
         "use insert_param instead!";
1820
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1821
}
1822

            
1823
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1824
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1825
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1826
         "use update_param instead";
1827
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1828
}
cleanup
Yuki Kimoto authored on 2011-03-08
1829
# DEPRECATED!
1830
sub _push_relation {
1831
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1832
    
1833
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1834
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1835
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1836
            my $table1 = (split (/\./, $rcolumn))[0];
1837
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1838
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1839
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1840
        }
1841
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1842
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1843
}
1844

            
1845
# DEPRECATED!
1846
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1847
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1848
    
1849
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1850
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1851
            my $table1 = (split (/\./, $rcolumn))[0];
1852
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1853
            my $table1_exists;
1854
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1855
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1856
                $table1_exists = 1 if $table eq $table1;
1857
                $table2_exists = 1 if $table eq $table2;
1858
            }
1859
            unshift @$tables, $table1 unless $table1_exists;
1860
            unshift @$tables, $table2 unless $table2_exists;
1861
        }
1862
    }
1863
}
1864

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1867
=head1 NAME
1868

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1873
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1874
    
1875
    # Connect
1876
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1877
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1878
        user => 'ken',
1879
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1880
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1881
    );
cleanup
yuki-kimoto authored on 2010-08-05
1882

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1883
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1884
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1885
    
1886
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1887
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1888
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1889
    
1890
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1891
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1892

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1942
Named place holder support
1943

            
1944
=item *
1945

            
cleanup
Yuki Kimoto authored on 2011-07-29
1946
Model support
1947

            
1948
=item *
1949

            
1950
Connection manager support
1951

            
1952
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1953

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

            
1958
=item *
1959

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

            
1962
=item *
1963

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

            
1966
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1967

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1975
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1976
L<DBIx::Custom::Result>,
1977
L<DBIx::Custom::Query>,
1978
L<DBIx::Custom::Where>,
1979
L<DBIx::Custom::Model>,
1980
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1981

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

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

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

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

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

            
1995
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
1996
        "dbi:mysql:database=$database",
1997
        $user,
1998
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1999
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2000
    );
2001
    
updated pod
Yuki Kimoto authored on 2011-06-21
2002
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2003

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

            
2007
    my $dbi = DBIx::Custom->connect(
2008
      dsn => $dsn, user => $user, password => $password, connector => 1);
2009
    
2010
    my $connector = $dbi->connector; # DBIx::Connector
2011

            
2012
Note that L<DBIx::Connector> must be installed.
2013

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2029
    {
2030
        RaiseError => 1,
2031
        PrintError => 0,
2032
        AutoCommit => 1,
2033
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2034

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

            
2037
    my $exclude_table = $dbi->exclude_table;
2038
    $dbi = $dbi->exclude_table(qr/pg_/);
2039

            
2040
Excluded table regex.
2041
C<each_column>, C<each_table>, C<type_rule>,
2042
and C<setup_model> methods ignore matching tables.
2043

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

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

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

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

            
2053
    my $last_sql = $dbi->last_sql;
2054
    $dbi = $dbi->last_sql($last_sql);
2055

            
2056
Get last successed SQL executed by C<execute> method.
2057

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

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

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

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

            
2067
    my $option = $dbi->option;
2068
    $dbi = $dbi->option($option);
2069

            
2070
L<DBI> option, used when C<connect> method is executed.
2071
Each value in option override the value of C<default_option>.
2072

            
cleanup
yuki-kimoto authored on 2010-10-17
2073
=head2 C<password>
2074

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2095
You can set quote pair.
2096

            
2097
    $dbi->quote('[]');
2098

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2108
    my $safety_character = $dbi->safety_character;
2109
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2110

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

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

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

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

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

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

            
2127
    my $tag_parse = $dbi->tag_parse(0);
2128
    $dbi = $dbi->tag_parse;
2129

            
2130
Enable DEPRECATED tag parsing functionality, default to 1.
2131
If you want to disable tag parsing functionality, set to 0.
2132

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

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

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

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

            
2142
    my $user_column_info = $dbi->user_column_info;
2143
    $dbi = $dbi->user_column_info($user_column_info);
2144

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

            
2147
    [
2148
        {table => 'book', column => 'title', info => {...}},
2149
        {table => 'author', column => 'name', info => {...}}
2150
    ]
2151

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

            
2154
    my $user_column_info
2155
      = $dbi->get_column_info(exclude_table => qr/^system/);
2156
    $dbi->user_column_info($user_column_info);
2157

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

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

            
2163
    my $user_table_info = $dbi->user_table_info;
2164
    $dbi = $dbi->user_table_info($user_table_info);
2165

            
2166
You can set the following data.
2167

            
2168
    [
2169
        {table => 'book', info => {...}},
2170
        {table => 'author', info => {...}}
2171
    ]
2172

            
2173
Usually, you can set return value of C<get_table_info>.
2174

            
2175
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2176
    $dbi->user_table_info($user_table_info);
2177

            
2178
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2179
to find table info.
2180

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2217
Create column clause. The follwoing column clause is created.
2218

            
2219
    book.author as "book.author",
2220
    book.title as "book.title"
2221

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2224
    # Separator is hyphen
2225
    $dbi->separator('-');
2226
    
2227
    book.author as "book-author",
2228
    book.title as "book-title"
2229
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2230
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2231

            
update pod
Yuki Kimoto authored on 2011-03-13
2232
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2233
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2234
        user => 'ken',
2235
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2236
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2237
    );
2238

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

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

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

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

            
2249
Get rows count.
2250

            
2251
Options is same as C<select> method's ones.
2252

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2255
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2256
        table => 'book',
2257
        primary_key => 'id',
2258
        join => [
2259
            'inner join company on book.comparny_id = company.id'
2260
        ],
2261
    );
2262

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

            
2266
   $dbi->model('book')->select(...);
2267

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

            
2270
    my $dbh = $dbi->dbh;
2271

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

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

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

            
2279
Execute delete statement.
2280

            
2281
The following opitons are available.
2282

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

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

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

            
2290
=item C<id>
2291

            
2292
    id => 4
2293
    id => [4, 5]
2294

            
2295
ID corresponding to C<primary_key>.
2296
You can delete rows by C<id> and C<primary_key>.
2297

            
2298
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2299
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2300
        id => [4, 5],
2301
        table => 'book',
2302
    );
2303

            
2304
The above is same as the followin one.
2305

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

            
2308
=item C<prefix>
2309

            
2310
    prefix => 'some'
2311

            
2312
prefix before table name section.
2313

            
2314
    delete some from book
2315

            
2316
=item C<table>
2317

            
2318
    table => 'book'
2319

            
2320
Table name.
2321

            
2322
=item C<where>
2323

            
2324
Same as C<select> method's C<where> option.
2325

            
2326
=back
2327

            
2328
=head2 C<delete_all>
2329

            
2330
    $dbi->delete_all(table => $table);
2331

            
2332
Execute delete statement for all rows.
2333
Options is same as C<delete>.
2334

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

            
2337
    $dbi->each_column(
2338
        sub {
2339
            my ($dbi, $table, $column, $column_info) = @_;
2340
            
2341
            my $type = $column_info->{TYPE_NAME};
2342
            
2343
            if ($type eq 'DATE') {
2344
                # ...
2345
            }
2346
        }
2347
    );
2348

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

            
2354
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2355
infromation, you can improve the performance of C<each_column> in
2356
the following way.
2357

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

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

            
2364
    $dbi->each_table(
2365
        sub {
2366
            my ($dbi, $table, $table_info) = @_;
2367
            
2368
            my $table_name = $table_info->{TABLE_NAME};
2369
        }
2370
    );
2371

            
improved pod
Yuki Kimoto authored on 2011-10-14
2372
Iterate all table informationsfrom in database.
2373
Argument is callback which is executed when one table is found.
2374
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2375
C<table information>.
2376

            
2377
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2378
infromation, you can improve the performance of C<each_table> in
2379
the following way.
2380

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

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

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

            
2392
    my $result = $dbi->execute(
2393
      "select * from book where title = :book.title and author like :book.author",
2394
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2395
    );
2396

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2403
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2404
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2405
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2406
    select * from book where title = :title and author like :author
2407
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2408
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2409
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2410

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2414
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2415
    select * from book where :title{=} and :author{like}
2416
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2417
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2418
    select * from where title = ? and author like ?;
2419

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

            
2424
    select * from where title = "aa\\:bb";
2425

            
cleanup
Yuki Kimoto authored on 2011-10-20
2426
B<OPTIONS>
2427

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

            
2430
=over 4
2431

            
cleanup
Yuki Kimoto authored on 2011-10-20
2432
=item C<append>
2433

            
2434
    append => 'order by name'
2435

            
2436
Append some statement after SQL.
2437

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

            
2440
Specify database bind data type.
2441

            
2442
    bind_type => [image => DBI::SQL_BLOB]
2443
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2444

            
2445
This is used to bind parameter by C<bind_param> of statment handle.
2446

            
2447
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2448

            
update pod
Yuki Kimoto authored on 2011-03-13
2449
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2450
    
2451
    filter => {
2452
        title  => sub { uc $_[0] }
2453
        author => sub { uc $_[0] }
2454
    }
update pod
Yuki Kimoto authored on 2011-03-13
2455

            
updated pod
Yuki Kimoto authored on 2011-06-09
2456
    # Filter name
2457
    filter => {
2458
        title  => 'upper_case',
2459
        author => 'upper_case'
2460
    }
2461
        
2462
    # At once
2463
    filter => [
2464
        [qw/title author/]  => sub { uc $_[0] }
2465
    ]
2466

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

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

            
2474
    id => 4
2475
    id => [4, 5]
2476

            
2477
ID corresponding to C<primary_key>.
2478
You can delete rows by C<id> and C<primary_key>.
2479

            
2480
    $dbi->execute(
2481
        "select * from book where id1 = :id1 and id2 = :id2",
2482
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2483
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2484
        id => [4, 5],
2485
    );
2486

            
2487
The above is same as the followin one.
2488

            
2489
    $dbi->execute(
2490
        "select * from book where id1 = :id1 and id2 = :id2",
2491
        {id1 => 4, id2 => 5}
2492
    );
2493

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

            
2496
    query => 1
2497

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

            
2501
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2502
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2503
    my $columns = $query->columns;
2504
    
2505
If you want to execute SQL fast, you can do the following way.
2506

            
2507
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2508
    for my $row (@$rows) {
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2509
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2510
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2511
    }
2512

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

            
2516
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
2517
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2518
    
2519
    my $query;
2520
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2521
    for my $row (@$rows) {
cleanup
Yuki Kimoto authored on 2011-07-30
2522
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2523
      $sth ||= $query->sth;
2524
      $sth->execute(map { $row->{$_} } sort keys %$row);
2525
    }
2526

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2533
    primary_key => 'id'
2534
    primary_key => ['id1', 'id2']
2535

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

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

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

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

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

            
2546
    $dbi->select(
2547
        table => 'book',
2548
        column => 'distinct(name)',
2549
        after_build_sql => sub {
2550
            "select count(*) from ($_[0]) as t1"
2551
        }
2552
    );
2553

            
2554
The following SQL is executed.
2555

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2558
=item C<table>
2559
    
2560
    table => 'author'
2561

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2569
    # Same
2570
    $dbi->execute(
2571
      "select * from book where title = :book.title and author = :book.author",
2572
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2573

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

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

            
2578
Table alias. Key is real table name, value is alias table name.
2579
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2580
on alias table name.
2581

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

            
2584
    type_rule_off => 1
2585

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

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

            
2590
    type_rule1_off => 1
2591

            
2592
Turn C<into1> type rule off.
2593

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

            
2596
    type_rule2_off => 1
2597

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

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

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

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

            
2606
get column infomation except for one which match C<exclude_table> pattern.
2607

            
2608
    [
2609
        {table => 'book', column => 'title', info => {...}},
2610
        {table => 'author', column => 'name' info => {...}}
2611
    ]
2612

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

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

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

            
2619
    [
2620
        {table => 'book', info => {...}},
2621
        {table => 'author', info => {...}}
2622
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2623

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

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

            
2628
    $dbi->helper(
2629
        update_or_insert => sub {
2630
            my $self = shift;
2631
            
2632
            # Process
2633
        },
2634
        find_or_create   => sub {
2635
            my $self = shift;
2636
            
2637
            # Process
2638
        }
2639
    );
2640

            
2641
Register helper. These helper is called directly from L<DBIx::Custom> object.
2642

            
2643
    $dbi->update_or_insert;
2644
    $dbi->find_or_create;
2645

            
cleanup
yuki-kimoto authored on 2010-10-17
2646
=head2 C<insert>
2647

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

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

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

            
2656
    {date => \"NOW()"}
2657

            
cleanup
Yuki Kimoto authored on 2011-10-20
2658
B<options>
2659

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2667
    id => 4
2668
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2669

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2673
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2674
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2675
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2676
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2677
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2678
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2679

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

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

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

            
2689
    prefix => 'or replace'
2690

            
2691
prefix before table name section
2692

            
2693
    insert or replace into book
2694

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

            
2697
    table => 'book'
2698

            
2699
Table name.
2700

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

            
2703
    timestamp => 1
2704

            
2705
If this value is set to 1,
2706
automatically created timestamp column is set based on
2707
C<timestamp> attribute's C<insert> value.
2708

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

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

            
2713
placeholder wrapped string.
2714

            
2715
If the following statement
2716

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

            
2720
is executed, the following SQL is executed.
2721

            
2722
    insert into book price values ( ? + 5 );
2723

            
update pod
Yuki Kimoto authored on 2011-03-13
2724
=back
2725

            
2726
=over 4
2727

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2735
    lib / MyModel.pm
2736
        / MyModel / book.pm
2737
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2738

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

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

            
2743
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2744
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2745
    
2746
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2747

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2752
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2753
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2754
    
2755
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2756

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2759
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2760
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2761
    
2762
    1;
2763
    
updated pod
Yuki Kimoto authored on 2011-06-21
2764
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2765

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

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

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

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

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

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

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

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

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

            
2791
    my $like_value = $dbi->like_value
2792

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

            
2795
    sub { "%$_[0]%" }
2796

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

            
2799
    my $mapper = $dbi->mapper(param => $param);
2800

            
2801
Create a new L<DBIx::Custom::Mapper> object.
2802

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

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

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

            
2809
    {key1 => [1, 1], key2 => 2}
2810

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

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

            
2815
    my $model = $dbi->model('book');
2816

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

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

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

            
2824
Create column clause for myself. The follwoing column clause is created.
2825

            
2826
    book.author as author,
2827
    book.title as title
2828

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

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

            
2838
Create a new L<DBIx::Custom> object.
2839

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

            
2842
    my $not_exists = $dbi->not_exists;
2843

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

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

            
2849
    my $order = $dbi->order;
2850

            
2851
Create a new L<DBIx::Custom::Order> object.
2852

            
cleanup
yuki-kimoto authored on 2010-10-17
2853
=head2 C<register_filter>
2854

            
update pod
Yuki Kimoto authored on 2011-03-13
2855
    $dbi->register_filter(
2856
        # Time::Piece object to database DATE format
2857
        tp_to_date => sub {
2858
            my $tp = shift;
2859
            return $tp->strftime('%Y-%m-%d');
2860
        },
2861
        # database DATE format to Time::Piece object
2862
        date_to_tp => sub {
2863
           my $date = shift;
2864
           return Time::Piece->strptime($date, '%Y-%m-%d');
2865
        }
2866
    );
cleanup
yuki-kimoto authored on 2010-10-17
2867
    
update pod
Yuki Kimoto authored on 2011-03-13
2868
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2869

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2872
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2873
        table  => 'book',
2874
        column => ['author', 'title'],
2875
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2876
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2877
    
updated document
Yuki Kimoto authored on 2011-06-09
2878
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2879

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2887
=item C<column>
2888
    
updated document
Yuki Kimoto authored on 2011-06-09
2889
    column => 'author'
2890
    column => ['author', 'title']
2891

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2900
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2901
        {book => [qw/author title/]},
2902
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2903
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2904

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

            
2907
    book.author as "book.author",
2908
    book.title as "book.title",
2909
    person.name as "person.name",
2910
    person.age as "person.age"
2911

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

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

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

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

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

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

            
2927
=item C<id>
2928

            
2929
    id => 4
2930
    id => [4, 5]
2931

            
2932
ID corresponding to C<primary_key>.
2933
You can select rows by C<id> and C<primary_key>.
2934

            
2935
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2936
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2937
        id => [4, 5],
2938
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2939
    );
2940

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2943
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2944
        where => {id1 => 4, id2 => 5},
2945
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2946
    );
2947
    
cleanup
Yuki Kimoto authored on 2011-10-20
2948
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2949

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

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

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

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

            
2962
    prefix => 'SQL_CALC_FOUND_ROWS'
2963

            
2964
Prefix of column cluase
2965

            
2966
    select SQL_CALC_FOUND_ROWS title, author from book;
2967

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

            
2970
    join => [
2971
        'left outer join company on book.company_id = company_id',
2972
        'left outer join location on company.location_id = location.id'
2973
    ]
2974
        
2975
Join clause. If column cluase or where clause contain table name like "company.name",
2976
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2977

            
2978
    $dbi->select(
2979
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2980
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2981
        where => {'company.name' => 'Orange'},
2982
        join => [
2983
            'left outer join company on book.company_id = company.id',
2984
            'left outer join location on company.location_id = location.id'
2985
        ]
2986
    );
2987

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2991
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2992
    from book
2993
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2994
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2995

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
2996
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
2997
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
2998

            
2999
    $dbi->select(
3000
        table => 'book',
3001
        column => ['company.location_id as location_id'],
3002
        where => {'company.name' => 'Orange'},
3003
        join => [
3004
            {
3005
                clause => 'left outer join location on company.location_id = location.id',
3006
                table => ['company', 'location']
3007
            }
3008
        ]
3009
    );
3010

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3015
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3016

            
updated document
Yuki Kimoto authored on 2011-06-09
3017
=item C<where>
3018
    
3019
    # Hash refrence
3020
    where => {author => 'Ken', 'title' => 'Perl'}
3021
    
3022
    # DBIx::Custom::Where object
3023
    where => $dbi->where(
3024
        clause => ['and', 'author = :author', 'title like :title'],
3025
        param  => {author => 'Ken', title => '%Perl%'}
3026
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3027
    
3028
    # Array reference 1 (array reference, hash referenc). same as above
3029
    where => [
3030
        ['and', 'author = :author', 'title like :title'],
3031
        {author => 'Ken', title => '%Perl%'}
3032
    ];    
3033
    
3034
    # Array reference 2 (String, hash reference)
3035
    where => [
3036
        'title like :title',
3037
        {title => '%Perl%'}
3038
    ]
3039
    
3040
    # String
3041
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3042

            
cleanup
Yuki Kimoto authored on 2011-10-20
3043
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3044
    
update pod
Yuki Kimoto authored on 2011-03-12
3045
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3046

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

            
3049
    $dbi->setup_model;
3050

            
3051
Setup all model objects.
3052
C<columns> of model object is automatically set, parsing database information.
3053

            
3054
=head2 C<type_rule>
3055

            
3056
    $dbi->type_rule(
3057
        into1 => {
3058
            date => sub { ... },
3059
            datetime => sub { ... }
3060
        },
3061
        into2 => {
3062
            date => sub { ... },
3063
            datetime => sub { ... }
3064
        },
3065
        from1 => {
3066
            # DATE
3067
            9 => sub { ... },
3068
            # DATETIME or TIMESTAMP
3069
            11 => sub { ... },
3070
        }
3071
        from2 => {
3072
            # DATE
3073
            9 => sub { ... },
3074
            # DATETIME or TIMESTAMP
3075
            11 => sub { ... },
3076
        }
3077
    );
3078

            
3079
Filtering rule when data is send into and get from database.
3080
This has a little complex problem.
3081

            
3082
In C<into1> and C<into2> you can specify
3083
type name as same as type name defined
3084
by create table, such as C<DATETIME> or C<DATE>.
3085

            
3086
Note that type name and data type don't contain upper case.
3087
If these contain upper case charactor, you convert it to lower case.
3088

            
3089
C<into2> is executed after C<into1>.
3090

            
3091
Type rule of C<into1> and C<into2> is enabled on the following
3092
column name.
3093

            
3094
=over 4
3095

            
3096
=item 1. column name
3097

            
3098
    issue_date
3099
    issue_datetime
3100

            
3101
This need C<table> option in each method.
3102

            
3103
=item 2. table name and column name, separator is dot
3104

            
3105
    book.issue_date
3106
    book.issue_datetime
3107

            
3108
=back
3109

            
3110
You get all type name used in database by C<available_typename>.
3111

            
3112
    print $dbi->available_typename;
3113

            
3114
In C<from1> and C<from2> you specify data type, not type name.
3115
C<from2> is executed after C<from1>.
3116
You get all data type by C<available_datatype>.
3117

            
3118
    print $dbi->available_datatype;
3119

            
3120
You can also specify multiple types at once.
3121

            
3122
    $dbi->type_rule(
3123
        into1 => [
3124
            [qw/DATE DATETIME/] => sub { ... },
3125
        ],
3126
    );
3127

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

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

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

            
3134
If you want to set constant value to row data, use scalar reference
3135
as parameter value.
3136

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3148
    id => 4
3149
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3150

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3154
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3155
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3156
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3157
        id => [4, 5],
3158
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3159
    );
update pod
Yuki Kimoto authored on 2011-03-13
3160

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3163
    $dbi->update(
3164
        {title => 'Perl', author => 'Ken'}
3165
        where => {id1 => 4, id2 => 5},
3166
        table => 'book'
3167
    );
update pod
Yuki Kimoto authored on 2011-03-13
3168

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

            
3171
    prefix => 'or replace'
3172

            
3173
prefix before table name section
3174

            
3175
    update or replace book
3176

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

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

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

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

            
3185
    timestamp => 1
3186

            
3187
If this value is set to 1,
3188
automatically updated timestamp column is set based on
3189
C<timestamp> attribute's C<update> value.
3190

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

            
3193
Same as C<select> method's C<where> option.
3194

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

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

            
3199
placeholder wrapped string.
3200

            
3201
If the following statement
3202

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

            
3206
is executed, the following SQL is executed.
3207

            
3208
    update book set price =  ? + 5;
3209

            
updated pod
Yuki Kimoto authored on 2011-06-08
3210
=back
update pod
Yuki Kimoto authored on 2011-03-13
3211

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3219
=head2 C<update_or_insert EXPERIMENTAL>
3220
    
3221
    # Where
3222
    $dbi->update_or_insert(
3223
        {id => 1, title => 'Perl'},
3224
        table => 'book',
3225
        where => {id => 1},
3226
        select_option => {append => 'for update'}
3227
    );
3228
    
3229
    # ID
3230
    $dbi->update_or_insert(
3231
        {title => 'Perl'},
3232
        table => 'book',
3233
        id => 1,
3234
        primary_key => 'id',
3235
        select_option => {append => 'for update'}
3236
    );
3237
    
3238
Update or insert.
3239

            
3240
In both examples, the following SQL is executed.
3241

            
3242
    # In case insert
3243
    insert into book (id, title) values (?, ?)
3244
    
3245
    # In case update
3246
    update book set (id = ?, title = ?) where book.id = ?
3247

            
3248
The following opitons are available adding to C<update> option.
3249

            
3250
=over 4
3251

            
3252
=item C<select_option>
3253

            
3254
    select_option => {append => 'for update'}
3255

            
3256
select method option,
3257
select method is used to check the row is already exists.
3258

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

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

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

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

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

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

            
3279
    $dbi->show_datatype($table);
3280

            
3281
Show data type of the columns of specified table.
3282

            
3283
    book
3284
    title: 5
3285
    issue_date: 91
3286

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

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

            
3291
    $dbi->show_tables;
3292

            
3293
Show tables.
3294

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

            
3297
    $dbi->show_typename($table);
3298

            
3299
Show type name of the columns of specified table.
3300

            
3301
    book
3302
    title: varchar
3303
    issue_date: date
3304

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

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

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

            
3311
Create values clause.
3312

            
3313
    (title, author) values (title = :title, age = :age);
3314

            
3315
You can use this in insert statement.
3316

            
3317
    my $insert_sql = "insert into book $values_clause";
3318

            
3319
=head2 C<where>
3320

            
3321
    my $where = $dbi->where(
3322
        clause => ['and', 'title = :title', 'author = :author'],
3323
        param => {title => 'Perl', author => 'Ken'}
3324
    );
3325

            
3326
Create a new L<DBIx::Custom::Where> object.
3327

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

            
3330
=head2 C<DBIX_CUSTOM_DEBUG>
3331

            
3332
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3333
executed SQL and bind values are printed to STDERR.
3334

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

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

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

            
3341
L<DBIx::Custom>
3342

            
3343
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3344
    default_dbi_option # will be removed 2017/1/1
3345
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3346
    data_source # will be removed at 2017/1/1
3347
    dbi_options # will be removed at 2017/1/1
3348
    filter_check # will be removed at 2017/1/1
3349
    reserved_word_quote # will be removed at 2017/1/1
3350
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3351
    
3352
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3353
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3354
    assign_param # will be removed at 2017/1/1
3355
    update_param # will be removed at 2017/1/1
3356
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3357
    create_query # will be removed at 2017/1/1
3358
    apply_filter # will be removed at 2017/1/1
3359
    select_at # will be removed at 2017/1/1
3360
    delete_at # will be removed at 2017/1/1
3361
    update_at # will be removed at 2017/1/1
3362
    insert_at # will be removed at 2017/1/1
3363
    register_tag # will be removed at 2017/1/1
3364
    default_bind_filter # will be removed at 2017/1/1
3365
    default_fetch_filter # will be removed at 2017/1/1
3366
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3367
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3368
    register_tag_processor # will be removed at 2017/1/1
3369
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3370
    
3371
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3372
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3373
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3374
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3375
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3376
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3377
    select method relation option # will be removed at 2017/1/1
3378
    select method column option [COLUMN, as => ALIAS] format
3379
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3380
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3381
    
3382
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3383
    execute("select * from {= title}"); # execute method's
3384
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3385
                                        # will be removed at 2017/1/1
3386
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3387

            
3388
L<DBIx::Custom::Model>
3389

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3390
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3391
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3392
    filter # will be removed at 2017/1/1
3393
    name # will be removed at 2017/1/1
3394
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3395

            
3396
L<DBIx::Custom::Query>
3397
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3398
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3399
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3400
    table # will be removed at 2017/1/1
3401
    filters # will be removed at 2017/1/1
3402
    
3403
    # Methods
3404
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3405

            
3406
L<DBIx::Custom::QueryBuilder>
3407
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3408
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3409
    tags # will be removed at 2017/1/1
3410
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3411
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3412
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3413
    register_tag # will be removed at 2017/1/1
3414
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3415
    
3416
    # Others
3417
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3418
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3419

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

            
3431
L<DBIx::Custom::Tag>
3432

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

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

            
3437
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3438
except for attribute method.
3439
You can check all DEPRECATED functionalities by document.
3440
DEPRECATED functionality is removed after five years,
3441
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
3442
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3443

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

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

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

            
3450
C<< <kimoto.yuki at gmail.com> >>
3451

            
3452
L<http://github.com/yuki-kimoto/DBIx-Custom>
3453

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3454
=head1 AUTHOR
3455

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

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

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

            
3462
This program is free software; you can redistribute it and/or modify it
3463
under the same terms as Perl itself.
3464

            
3465
=cut