DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3469 lines | 89.579kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
- removed argument checking ...
Yuki Kimoto authored on 2011-10-21
4
our $VERSION = '0.1733';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
22
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
improved debug message
Yuki Kimoto authored on 2011-05-23
23
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
added environment variable D...
Yuki Kimoto authored on 2011-04-02
24

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
25
has [qw/connector dsn password quote user exclude_table user_table_info
26
        user_column_info/],
removed from cache() and cac...
Yuki Kimoto authored on 2011-03-29
27
    cache => 0,
many changed
Yuki Kimoto authored on 2011-01-23
28
    cache_method => sub {
29
        sub {
30
            my $self = shift;
31
            
32
            $self->{_cached} ||= {};
33
            
34
            if (@_ > 1) {
update pod
Yuki Kimoto authored on 2011-03-13
35
                $self->{_cached}{$_[0]} = $_[1];
many changed
Yuki Kimoto authored on 2011-01-23
36
            }
37
            else {
update pod
Yuki Kimoto authored on 2011-03-13
38
                return $self->{_cached}{$_[0]};
many changed
Yuki Kimoto authored on 2011-01-23
39
            }
40
        }
update pod
Yuki Kimoto authored on 2011-03-13
41
    },
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
42
    option => sub { {} },
43
    default_option => sub {
update pod
Yuki Kimoto authored on 2011-03-13
44
        {
45
            RaiseError => 1,
46
            PrintError => 0,
47
            AutoCommit => 1
48
        }
49
    },
fix tests
Yuki Kimoto authored on 2011-01-13
50
    filters => sub {
51
        {
52
            encode_utf8 => sub { encode_utf8($_[0]) },
53
            decode_utf8 => sub { decode_utf8($_[0]) }
54
        }
update pod
Yuki Kimoto authored on 2011-03-13
55
    },
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
56
    last_sql => '',
update pod
Yuki Kimoto authored on 2011-03-13
57
    models => sub { {} },
cleanup
Yuki Kimoto authored on 2011-08-13
58
    query_builder => sub {
59
        my $self = shift;
60
        my $builder = DBIx::Custom::QueryBuilder->new(dbi => $self);
61
        weaken $builder->{dbi};
62
        return $builder;
63
    },
update pod
Yuki Kimoto authored on 2011-03-13
64
    result_class  => 'DBIx::Custom::Result',
65
    safety_character => '\w',
cleanup test
Yuki Kimoto authored on 2011-08-10
66
    separator => '.',
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
67
    stash => sub { {} },
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
68
    tag_parse => 1;
cleanup
yuki-kimoto authored on 2010-10-17
69

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1400
sub _quote {
1401
    my $self = shift;
1402
    
1403
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1404
         : defined $self->quote ? $self->quote
1405
         : '';
1406
}
1407

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

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

            
1440
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1441
}
1442

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

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

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

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

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

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

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

            
1622
# DEPRECATED!
1623
sub assign_param {
1624
    my $self = shift;
1625
    warn "assing_param is DEPRECATED! use assign_clause instead";
1626
    return $self->assign_clause(@_);
1627
}
1628

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

            
1639
    return $tag;
1640
}
1641

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1696
# DEPRECATED!
1697
sub update_at {
1698
    my $self = shift;
1699

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1788
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1789
sub default_fetch_filter {
1790
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1791

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1871
=head1 NAME
1872

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

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

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

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

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1934
=over 4
- 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
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- 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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1946
Named place holder support
1947

            
1948
=item *
1949

            
cleanup
Yuki Kimoto authored on 2011-07-29
1950
Model support
1951

            
1952
=item *
1953

            
1954
Connection manager support
1955

            
1956
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1957

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

            
1962
=item *
1963

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

            
1966
=item *
1967

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

            
1970
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1971

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

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

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

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

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

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

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

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

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

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

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

            
2011
    my $dbi = DBIx::Custom->connect(
2012
      dsn => $dsn, user => $user, password => $password, connector => 1);
2013
    
2014
    my $connector = $dbi->connector; # DBIx::Connector
2015

            
2016
Note that L<DBIx::Connector> must be installed.
2017

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

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

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

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

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

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

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

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

            
2041
    my $exclude_table = $dbi->exclude_table;
2042
    $dbi = $dbi->exclude_table(qr/pg_/);
2043

            
2044
Excluded table regex.
2045
C<each_column>, C<each_table>, C<type_rule>,
2046
and C<setup_model> methods ignore matching tables.
2047

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

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

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

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

            
2057
    my $last_sql = $dbi->last_sql;
2058
    $dbi = $dbi->last_sql($last_sql);
2059

            
2060
Get last successed SQL executed by C<execute> method.
2061

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

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

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

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

            
2071
    my $option = $dbi->option;
2072
    $dbi = $dbi->option($option);
2073

            
2074
L<DBI> option, used when C<connect> method is executed.
2075
Each value in option override the value of C<default_option>.
2076

            
cleanup
yuki-kimoto authored on 2010-10-17
2077
=head2 C<password>
2078

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2099
You can set quote pair.
2100

            
2101
    $dbi->quote('[]');
2102

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2112
    my $safety_character = $dbi->safety_character;
2113
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2114

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

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

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

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

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

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

            
2131
    my $tag_parse = $dbi->tag_parse(0);
2132
    $dbi = $dbi->tag_parse;
2133

            
2134
Enable DEPRECATED tag parsing functionality, default to 1.
2135
If you want to disable tag parsing functionality, set to 0.
2136

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

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

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

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

            
2146
    my $user_column_info = $dbi->user_column_info;
2147
    $dbi = $dbi->user_column_info($user_column_info);
2148

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

            
2151
    [
2152
        {table => 'book', column => 'title', info => {...}},
2153
        {table => 'author', column => 'name', info => {...}}
2154
    ]
2155

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

            
2158
    my $user_column_info
2159
      = $dbi->get_column_info(exclude_table => qr/^system/);
2160
    $dbi->user_column_info($user_column_info);
2161

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

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

            
2167
    my $user_table_info = $dbi->user_table_info;
2168
    $dbi = $dbi->user_table_info($user_table_info);
2169

            
2170
You can set the following data.
2171

            
2172
    [
2173
        {table => 'book', info => {...}},
2174
        {table => 'author', info => {...}}
2175
    ]
2176

            
2177
Usually, you can set return value of C<get_table_info>.
2178

            
2179
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2180
    $dbi->user_table_info($user_table_info);
2181

            
2182
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2183
to find table info.
2184

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2221
Create column clause. The follwoing column clause is created.
2222

            
2223
    book.author as "book.author",
2224
    book.title as "book.title"
2225

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

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

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

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

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

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

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

            
2253
Get rows count.
2254

            
2255
Options is same as C<select> method's ones.
2256

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

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

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

            
2270
   $dbi->model('book')->select(...);
2271

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

            
2274
    my $dbh = $dbi->dbh;
2275

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

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

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

            
2283
Execute delete statement.
2284

            
2285
The following opitons are available.
2286

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

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

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

            
2294
=item C<id>
2295

            
2296
    id => 4
2297
    id => [4, 5]
2298

            
2299
ID corresponding to C<primary_key>.
2300
You can delete rows by C<id> and C<primary_key>.
2301

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

            
2308
The above is same as the followin one.
2309

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

            
2312
=item C<prefix>
2313

            
2314
    prefix => 'some'
2315

            
2316
prefix before table name section.
2317

            
2318
    delete some from book
2319

            
2320
=item C<table>
2321

            
2322
    table => 'book'
2323

            
2324
Table name.
2325

            
2326
=item C<where>
2327

            
2328
Same as C<select> method's C<where> option.
2329

            
2330
=back
2331

            
2332
=head2 C<delete_all>
2333

            
2334
    $dbi->delete_all(table => $table);
2335

            
2336
Execute delete statement for all rows.
2337
Options is same as C<delete>.
2338

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

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

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

            
2358
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2359
infromation, you can improve the performance of C<each_column> in
2360
the following way.
2361

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

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

            
2368
    $dbi->each_table(
2369
        sub {
2370
            my ($dbi, $table, $table_info) = @_;
2371
            
2372
            my $table_name = $table_info->{TABLE_NAME};
2373
        }
2374
    );
2375

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

            
2381
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2382
infromation, you can improve the performance of C<each_table> in
2383
the following way.
2384

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

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

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

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

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

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

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

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

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

            
2428
    select * from where title = "aa\\:bb";
2429

            
cleanup
Yuki Kimoto authored on 2011-10-20
2430
B<OPTIONS>
2431

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

            
2434
=over 4
2435

            
cleanup
Yuki Kimoto authored on 2011-10-20
2436
=item C<append>
2437

            
2438
    append => 'order by name'
2439

            
2440
Append some statement after SQL.
2441

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

            
2444
Specify database bind data type.
2445

            
2446
    bind_type => [image => DBI::SQL_BLOB]
2447
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2448

            
2449
This is used to bind parameter by C<bind_param> of statment handle.
2450

            
2451
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2452

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

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

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

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

            
2478
    id => 4
2479
    id => [4, 5]
2480

            
2481
ID corresponding to C<primary_key>.
2482
You can delete rows by C<id> and C<primary_key>.
2483

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

            
2491
The above is same as the followin one.
2492

            
2493
    $dbi->execute(
2494
        "select * from book where id1 = :id1 and id2 = :id2",
2495
        {id1 => 4, id2 => 5}
2496
    );
2497

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

            
2500
    query => 1
2501

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2537
    primary_key => 'id'
2538
    primary_key => ['id1', 'id2']
2539

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

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

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

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

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

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

            
2558
The following SQL is executed.
2559

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2562
=item C<table>
2563
    
2564
    table => 'author'
2565

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

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

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

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

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

            
2582
Table alias. Key is real table name, value is alias table name.
2583
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2584
on alias table name.
2585

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

            
2588
    type_rule_off => 1
2589

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

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

            
2594
    type_rule1_off => 1
2595

            
2596
Turn C<into1> type rule off.
2597

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

            
2600
    type_rule2_off => 1
2601

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

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

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

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

            
2610
get column infomation except for one which match C<exclude_table> pattern.
2611

            
2612
    [
2613
        {table => 'book', column => 'title', info => {...}},
2614
        {table => 'author', column => 'name' info => {...}}
2615
    ]
2616

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

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

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

            
2623
    [
2624
        {table => 'book', info => {...}},
2625
        {table => 'author', info => {...}}
2626
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2627

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

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

            
2632
    $dbi->helper(
2633
        update_or_insert => sub {
2634
            my $self = shift;
2635
            
2636
            # Process
2637
        },
2638
        find_or_create   => sub {
2639
            my $self = shift;
2640
            
2641
            # Process
2642
        }
2643
    );
2644

            
2645
Register helper. These helper is called directly from L<DBIx::Custom> object.
2646

            
2647
    $dbi->update_or_insert;
2648
    $dbi->find_or_create;
2649

            
cleanup
yuki-kimoto authored on 2010-10-17
2650
=head2 C<insert>
2651

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

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

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

            
2660
    {date => \"NOW()"}
2661

            
cleanup
Yuki Kimoto authored on 2011-10-20
2662
B<options>
2663

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2671
    id => 4
2672
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2673

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

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

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

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

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

            
2693
    prefix => 'or replace'
2694

            
2695
prefix before table name section
2696

            
2697
    insert or replace into book
2698

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

            
2701
    table => 'book'
2702

            
2703
Table name.
2704

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

            
2707
    timestamp => 1
2708

            
2709
If this value is set to 1,
2710
automatically created timestamp column is set based on
2711
C<timestamp> attribute's C<insert> value.
2712

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

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

            
2717
placeholder wrapped string.
2718

            
2719
If the following statement
2720

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

            
2724
is executed, the following SQL is executed.
2725

            
2726
    insert into book price values ( ? + 5 );
2727

            
update pod
Yuki Kimoto authored on 2011-03-13
2728
=back
2729

            
2730
=over 4
2731

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2739
    lib / MyModel.pm
2740
        / MyModel / book.pm
2741
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2742

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2756
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2757
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2758
    
2759
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2760

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

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

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

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

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

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

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

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

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

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

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

            
2795
    my $like_value = $dbi->like_value
2796

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

            
2799
    sub { "%$_[0]%" }
2800

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

            
2803
    my $mapper = $dbi->mapper(param => $param);
2804

            
2805
Create a new L<DBIx::Custom::Mapper> object.
2806

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

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

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

            
2813
    {key1 => [1, 1], key2 => 2}
2814

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

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

            
2819
    my $model = $dbi->model('book');
2820

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

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

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

            
2828
Create column clause for myself. The follwoing column clause is created.
2829

            
2830
    book.author as author,
2831
    book.title as title
2832

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

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

            
2842
Create a new L<DBIx::Custom> object.
2843

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

            
2846
    my $not_exists = $dbi->not_exists;
2847

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

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

            
2853
    my $order = $dbi->order;
2854

            
2855
Create a new L<DBIx::Custom::Order> object.
2856

            
cleanup
yuki-kimoto authored on 2010-10-17
2857
=head2 C<register_filter>
2858

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

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2904
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2905
        {book => [qw/author title/]},
2906
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2907
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2908

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

            
2911
    book.author as "book.author",
2912
    book.title as "book.title",
2913
    person.name as "person.name",
2914
    person.age as "person.age"
2915

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

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

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

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

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

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

            
2931
=item C<id>
2932

            
2933
    id => 4
2934
    id => [4, 5]
2935

            
2936
ID corresponding to C<primary_key>.
2937
You can select rows by C<id> and C<primary_key>.
2938

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

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

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

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

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

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

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

            
2966
    prefix => 'SQL_CALC_FOUND_ROWS'
2967

            
2968
Prefix of column cluase
2969

            
2970
    select SQL_CALC_FOUND_ROWS title, author from book;
2971

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2995
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2996
    from book
2997
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2998
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2999

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3000
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
3001
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3002

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3019
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3020

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3047
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3048
    
update pod
Yuki Kimoto authored on 2011-03-12
3049
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3050

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

            
3053
    $dbi->setup_model;
3054

            
3055
Setup all model objects.
3056
C<columns> of model object is automatically set, parsing database information.
3057

            
3058
=head2 C<type_rule>
3059

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

            
3083
Filtering rule when data is send into and get from database.
3084
This has a little complex problem.
3085

            
3086
In C<into1> and C<into2> you can specify
3087
type name as same as type name defined
3088
by create table, such as C<DATETIME> or C<DATE>.
3089

            
3090
Note that type name and data type don't contain upper case.
3091
If these contain upper case charactor, you convert it to lower case.
3092

            
3093
C<into2> is executed after C<into1>.
3094

            
3095
Type rule of C<into1> and C<into2> is enabled on the following
3096
column name.
3097

            
3098
=over 4
3099

            
3100
=item 1. column name
3101

            
3102
    issue_date
3103
    issue_datetime
3104

            
3105
This need C<table> option in each method.
3106

            
3107
=item 2. table name and column name, separator is dot
3108

            
3109
    book.issue_date
3110
    book.issue_datetime
3111

            
3112
=back
3113

            
3114
You get all type name used in database by C<available_typename>.
3115

            
3116
    print $dbi->available_typename;
3117

            
3118
In C<from1> and C<from2> you specify data type, not type name.
3119
C<from2> is executed after C<from1>.
3120
You get all data type by C<available_datatype>.
3121

            
3122
    print $dbi->available_datatype;
3123

            
3124
You can also specify multiple types at once.
3125

            
3126
    $dbi->type_rule(
3127
        into1 => [
3128
            [qw/DATE DATETIME/] => sub { ... },
3129
        ],
3130
    );
3131

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

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

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

            
3138
If you want to set constant value to row data, use scalar reference
3139
as parameter value.
3140

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3152
    id => 4
3153
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3154

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

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

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

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

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

            
3175
    prefix => 'or replace'
3176

            
3177
prefix before table name section
3178

            
3179
    update or replace book
3180

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

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

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

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

            
3189
    timestamp => 1
3190

            
3191
If this value is set to 1,
3192
automatically updated timestamp column is set based on
3193
C<timestamp> attribute's C<update> value.
3194

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

            
3197
Same as C<select> method's C<where> option.
3198

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

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

            
3203
placeholder wrapped string.
3204

            
3205
If the following statement
3206

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

            
3210
is executed, the following SQL is executed.
3211

            
3212
    update book set price =  ? + 5;
3213

            
updated pod
Yuki Kimoto authored on 2011-06-08
3214
=back
update pod
Yuki Kimoto authored on 2011-03-13
3215

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

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

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

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

            
3244
In both examples, the following SQL is executed.
3245

            
3246
    # In case insert
3247
    insert into book (id, title) values (?, ?)
3248
    
3249
    # In case update
3250
    update book set (id = ?, title = ?) where book.id = ?
3251

            
3252
The following opitons are available adding to C<update> option.
3253

            
3254
=over 4
3255

            
3256
=item C<select_option>
3257

            
3258
    select_option => {append => 'for update'}
3259

            
3260
select method option,
3261
select method is used to check the row is already exists.
3262

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

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

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

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

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

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

            
3283
    $dbi->show_datatype($table);
3284

            
3285
Show data type of the columns of specified table.
3286

            
3287
    book
3288
    title: 5
3289
    issue_date: 91
3290

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

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

            
3295
    $dbi->show_tables;
3296

            
3297
Show tables.
3298

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

            
3301
    $dbi->show_typename($table);
3302

            
3303
Show type name of the columns of specified table.
3304

            
3305
    book
3306
    title: varchar
3307
    issue_date: date
3308

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

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

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

            
3315
Create values clause.
3316

            
3317
    (title, author) values (title = :title, age = :age);
3318

            
3319
You can use this in insert statement.
3320

            
3321
    my $insert_sql = "insert into book $values_clause";
3322

            
3323
=head2 C<where>
3324

            
3325
    my $where = $dbi->where(
3326
        clause => ['and', 'title = :title', 'author = :author'],
3327
        param => {title => 'Perl', author => 'Ken'}
3328
    );
3329

            
3330
Create a new L<DBIx::Custom::Where> object.
3331

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

            
3334
=head2 C<DBIX_CUSTOM_DEBUG>
3335

            
3336
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3337
executed SQL and bind values are printed to STDERR.
3338

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

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

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

            
3345
L<DBIx::Custom>
3346

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

            
3392
L<DBIx::Custom::Model>
3393

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

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

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

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

            
3435
L<DBIx::Custom::Tag>
3436

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

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

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

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

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

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

            
3454
C<< <kimoto.yuki at gmail.com> >>
3455

            
3456
L<http://github.com/yuki-kimoto/DBIx-Custom>
3457

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3458
=head1 AUTHOR
3459

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

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

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

            
3466
This program is free software; you can redistribute it and/or modify it
3467
under the same terms as Perl itself.
3468

            
3469
=cut