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

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

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

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

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

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
70
sub available_datatype {
test cleanup
Yuki Kimoto authored on 2011-08-10
71
    my $self = shift;
72
    
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
73
    my $data_types = '';
cleanup
Yuki Kimoto authored on 2011-10-21
74
    for my $i (-1000 .. 1000) {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
75
         my $type_info = $self->dbh->type_info($i);
76
         my $data_type = $type_info->{DATA_TYPE};
77
         my $type_name = $type_info->{TYPE_NAME};
78
         $data_types .= "$data_type ($type_name)\n"
79
           if defined $data_type;
80
    }
81
    return "Data Type maybe equal to Type Name" unless $data_types;
82
    $data_types = "Data Type (Type name)\n" . $data_types;
83
    return $data_types;
84
}
85

            
86
sub available_typename {
87
    my $self = shift;
88
    
89
    # Type Names
90
    my $type_names = {};
91
    $self->each_column(sub {
92
        my ($self, $table, $column, $column_info) = @_;
93
        $type_names->{$column_info->{TYPE_NAME}} = 1
94
          if $column_info->{TYPE_NAME};
95
    });
96
    my @output = sort keys %$type_names;
97
    unshift @output, "Type Name";
98
    return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
99
}
100

            
added helper method
yuki-kimoto authored on 2010-10-17
101
our $AUTOLOAD;
102
sub AUTOLOAD {
103
    my $self = shift;
104

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
105
    # Method name
106
    my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
107

            
cleanup
Yuki Kimoto authored on 2011-04-02
108
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
109
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
110
    if (my $method = $self->{_methods}->{$mname}) {
111
        return $self->$method(@_)
112
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
113
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
114
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
115
    }
116
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
117
        croak qq{Can't locate object method "$mname" via "$package" }
118
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
119
    }
added helper method
yuki-kimoto authored on 2010-10-17
120
}
121

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1027
sub update_or_insert {
1028
    my $self = shift;
1029

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

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

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

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

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

            
1128
        # Create query
1129
        my $builder = $self->query_builder;
1130
        $query = $builder->build_query($source);
1131

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

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

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

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

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

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

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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1404
sub _quote {
1405
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1406
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1407
}
1408

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

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

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

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

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

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

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

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

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

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

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

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

            
1640
    return $tag;
1641
}
1642

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1949
=item *
1950

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

            
1953
=item *
1954

            
1955
Connection manager support
1956

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

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

            
1963
=item *
1964

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

            
1967
=item *
1968

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2171
You can set the following data.
2172

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2254
Get rows count.
2255

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

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

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

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

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

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

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

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

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

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

            
2284
Execute delete statement.
2285

            
2286
The following opitons are available.
2287

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

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

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

            
2295
=item C<id>
2296

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

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

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

            
2309
The above is same as the followin one.
2310

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

            
2313
=item C<prefix>
2314

            
2315
    prefix => 'some'
2316

            
2317
prefix before table name section.
2318

            
2319
    delete some from book
2320

            
2321
=item C<table>
2322

            
2323
    table => 'book'
2324

            
2325
Table name.
2326

            
2327
=item C<where>
2328

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

            
2331
=back
2332

            
2333
=head2 C<delete_all>
2334

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2435
=over 4
2436

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

            
2439
You can filter sql after the sql is build.
2440

            
2441
    after_build_sql => $code_ref
2442

            
2443
The following one is one example.
2444

            
2445
    $dbi->select(
2446
        table => 'book',
2447
        column => 'distinct(name)',
2448
        after_build_sql => sub {
2449
            "select count(*) from ($_[0]) as t1"
2450
        }
2451
    );
2452

            
2453
The following SQL is executed.
2454

            
2455
    select count(*) from (select distinct(name) from book) as t1;
2456

            
cleanup
Yuki Kimoto authored on 2011-10-20
2457
=item C<append>
2458

            
2459
    append => 'order by name'
2460

            
2461
Append some statement after SQL.
2462

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

            
2465
Specify database bind data type.
2466

            
2467
    bind_type => [image => DBI::SQL_BLOB]
2468
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2469

            
2470
This is used to bind parameter by C<bind_param> of statment handle.
2471

            
2472
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2473

            
update pod
Yuki Kimoto authored on 2011-03-13
2474
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2475
    
2476
    filter => {
2477
        title  => sub { uc $_[0] }
2478
        author => sub { uc $_[0] }
2479
    }
update pod
Yuki Kimoto authored on 2011-03-13
2480

            
updated pod
Yuki Kimoto authored on 2011-06-09
2481
    # Filter name
2482
    filter => {
2483
        title  => 'upper_case',
2484
        author => 'upper_case'
2485
    }
2486
        
2487
    # At once
2488
    filter => [
2489
        [qw/title author/]  => sub { uc $_[0] }
2490
    ]
2491

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

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

            
2499
    id => 4
2500
    id => [4, 5]
2501

            
2502
ID corresponding to C<primary_key>.
2503
You can delete rows by C<id> and C<primary_key>.
2504

            
2505
    $dbi->execute(
2506
        "select * from book where id1 = :id1 and id2 = :id2",
2507
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2508
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2509
        id => [4, 5],
2510
    );
2511

            
2512
The above is same as the followin one.
2513

            
2514
    $dbi->execute(
2515
        "select * from book where id1 = :id1 and id2 = :id2",
2516
        {id1 => 4, id2 => 5}
2517
    );
2518

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

            
2521
    query => 1
2522

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

            
2526
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2527
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2528
    my $columns = $query->columns;
2529
    
2530
If you want to execute SQL fast, you can do the following way.
2531

            
2532
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2533
    for my $row (@$rows) {
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2534
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2535
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2536
    }
2537

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

            
2541
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
2542
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2543
    
2544
    my $query;
2545
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2546
    for my $row (@$rows) {
cleanup
Yuki Kimoto authored on 2011-07-30
2547
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2548
      $sth ||= $query->sth;
2549
      $sth->execute(map { $row->{$_} } sort keys %$row);
2550
    }
2551

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2558
    primary_key => 'id'
2559
    primary_key => ['id1', 'id2']
2560

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

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

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

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

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

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

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

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

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2587
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2588
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2589
    reuse_query => $has_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2590

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2591
Reuse query object if the hash reference variable is set.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2592
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2593
    my $queries = {};
2594
    $dbi->execute($sql, $param, reuse => $queries);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2595

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

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

            
2601
    type_rule_off => 1
2602

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

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

            
2607
    type_rule1_off => 1
2608

            
2609
Turn C<into1> type rule off.
2610

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

            
2613
    type_rule2_off => 1
2614

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

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

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

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

            
2623
get column infomation except for one which match C<exclude_table> pattern.
2624

            
2625
    [
2626
        {table => 'book', column => 'title', info => {...}},
2627
        {table => 'author', column => 'name' info => {...}}
2628
    ]
2629

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

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

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

            
2636
    [
2637
        {table => 'book', info => {...}},
2638
        {table => 'author', info => {...}}
2639
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2640

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

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

            
2645
    $dbi->helper(
2646
        update_or_insert => sub {
2647
            my $self = shift;
2648
            
2649
            # Process
2650
        },
2651
        find_or_create   => sub {
2652
            my $self = shift;
2653
            
2654
            # Process
2655
        }
2656
    );
2657

            
2658
Register helper. These helper is called directly from L<DBIx::Custom> object.
2659

            
2660
    $dbi->update_or_insert;
2661
    $dbi->find_or_create;
2662

            
cleanup
yuki-kimoto authored on 2010-10-17
2663
=head2 C<insert>
2664

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

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

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

            
2673
    {date => \"NOW()"}
2674

            
cleanup
Yuki Kimoto authored on 2011-10-20
2675
B<options>
2676

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2684
    id => 4
2685
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2686

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2690
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2691
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2692
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2693
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2694
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2695
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2696

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

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

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

            
2706
    prefix => 'or replace'
2707

            
2708
prefix before table name section
2709

            
2710
    insert or replace into book
2711

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

            
2714
    table => 'book'
2715

            
2716
Table name.
2717

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

            
2720
    timestamp => 1
2721

            
2722
If this value is set to 1,
2723
automatically created timestamp column is set based on
2724
C<timestamp> attribute's C<insert> value.
2725

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

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

            
2730
placeholder wrapped string.
2731

            
2732
If the following statement
2733

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

            
2737
is executed, the following SQL is executed.
2738

            
2739
    insert into book price values ( ? + 5 );
2740

            
update pod
Yuki Kimoto authored on 2011-03-13
2741
=back
2742

            
2743
=over 4
2744

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2752
    lib / MyModel.pm
2753
        / MyModel / book.pm
2754
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2755

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

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

            
2760
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2761
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2762
    
2763
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2764

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2769
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2770
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2771
    
2772
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2773

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2776
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2777
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2778
    
2779
    1;
2780
    
updated pod
Yuki Kimoto authored on 2011-06-21
2781
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2782

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

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

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

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

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

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

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

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

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

            
2808
    my $like_value = $dbi->like_value
2809

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

            
2812
    sub { "%$_[0]%" }
2813

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

            
2816
    my $mapper = $dbi->mapper(param => $param);
2817

            
2818
Create a new L<DBIx::Custom::Mapper> object.
2819

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

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

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

            
2826
    {key1 => [1, 1], key2 => 2}
2827

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

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

            
2832
    my $model = $dbi->model('book');
2833

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

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

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

            
2841
Create column clause for myself. The follwoing column clause is created.
2842

            
2843
    book.author as author,
2844
    book.title as title
2845

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

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

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

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

            
2859
    my $not_exists = $dbi->not_exists;
2860

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

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

            
2866
    my $order = $dbi->order;
2867

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2870
=head2 C<register_filter>
2871

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2889
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2890
        table  => 'book',
2891
        column => ['author', 'title'],
2892
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2893
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2894
    
updated document
Yuki Kimoto authored on 2011-06-09
2895
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2896

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2904
=item C<column>
2905
    
updated document
Yuki Kimoto authored on 2011-06-09
2906
    column => 'author'
2907
    column => ['author', 'title']
2908

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2917
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2918
        {book => [qw/author title/]},
2919
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2920
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2921

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

            
2924
    book.author as "book.author",
2925
    book.title as "book.title",
2926
    person.name as "person.name",
2927
    person.age as "person.age"
2928

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

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

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

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

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

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

            
2944
=item C<id>
2945

            
2946
    id => 4
2947
    id => [4, 5]
2948

            
2949
ID corresponding to C<primary_key>.
2950
You can select rows by C<id> and C<primary_key>.
2951

            
2952
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
2953
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
2954
        id => [4, 5],
2955
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2956
    );
2957

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2960
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2961
        where => {id1 => 4, id2 => 5},
2962
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2963
    );
2964
    
cleanup
Yuki Kimoto authored on 2011-10-20
2965
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2966

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

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

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

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

            
2979
    prefix => 'SQL_CALC_FOUND_ROWS'
2980

            
2981
Prefix of column cluase
2982

            
2983
    select SQL_CALC_FOUND_ROWS title, author from book;
2984

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

            
2987
    join => [
2988
        'left outer join company on book.company_id = company_id',
2989
        'left outer join location on company.location_id = location.id'
2990
    ]
2991
        
2992
Join clause. If column cluase or where clause contain table name like "company.name",
2993
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2994

            
2995
    $dbi->select(
2996
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2997
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2998
        where => {'company.name' => 'Orange'},
2999
        join => [
3000
            'left outer join company on book.company_id = company.id',
3001
            'left outer join location on company.location_id = location.id'
3002
        ]
3003
    );
3004

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3008
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3009
    from book
3010
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3011
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3012

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3013
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
3014
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3015

            
3016
    $dbi->select(
3017
        table => 'book',
3018
        column => ['company.location_id as location_id'],
3019
        where => {'company.name' => 'Orange'},
3020
        join => [
3021
            {
3022
                clause => 'left outer join location on company.location_id = location.id',
3023
                table => ['company', 'location']
3024
            }
3025
        ]
3026
    );
3027

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3032
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3033

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3060
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3061
    
update pod
Yuki Kimoto authored on 2011-03-12
3062
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3063

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

            
3066
    $dbi->setup_model;
3067

            
3068
Setup all model objects.
3069
C<columns> of model object is automatically set, parsing database information.
3070

            
3071
=head2 C<type_rule>
3072

            
3073
    $dbi->type_rule(
3074
        into1 => {
3075
            date => sub { ... },
3076
            datetime => sub { ... }
3077
        },
3078
        into2 => {
3079
            date => sub { ... },
3080
            datetime => sub { ... }
3081
        },
3082
        from1 => {
3083
            # DATE
3084
            9 => sub { ... },
3085
            # DATETIME or TIMESTAMP
3086
            11 => sub { ... },
3087
        }
3088
        from2 => {
3089
            # DATE
3090
            9 => sub { ... },
3091
            # DATETIME or TIMESTAMP
3092
            11 => sub { ... },
3093
        }
3094
    );
3095

            
3096
Filtering rule when data is send into and get from database.
3097
This has a little complex problem.
3098

            
3099
In C<into1> and C<into2> you can specify
3100
type name as same as type name defined
3101
by create table, such as C<DATETIME> or C<DATE>.
3102

            
3103
Note that type name and data type don't contain upper case.
3104
If these contain upper case charactor, you convert it to lower case.
3105

            
3106
C<into2> is executed after C<into1>.
3107

            
3108
Type rule of C<into1> and C<into2> is enabled on the following
3109
column name.
3110

            
3111
=over 4
3112

            
3113
=item 1. column name
3114

            
3115
    issue_date
3116
    issue_datetime
3117

            
3118
This need C<table> option in each method.
3119

            
3120
=item 2. table name and column name, separator is dot
3121

            
3122
    book.issue_date
3123
    book.issue_datetime
3124

            
3125
=back
3126

            
3127
You get all type name used in database by C<available_typename>.
3128

            
3129
    print $dbi->available_typename;
3130

            
3131
In C<from1> and C<from2> you specify data type, not type name.
3132
C<from2> is executed after C<from1>.
3133
You get all data type by C<available_datatype>.
3134

            
3135
    print $dbi->available_datatype;
3136

            
3137
You can also specify multiple types at once.
3138

            
3139
    $dbi->type_rule(
3140
        into1 => [
3141
            [qw/DATE DATETIME/] => sub { ... },
3142
        ],
3143
    );
3144

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

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

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

            
3151
If you want to set constant value to row data, use scalar reference
3152
as parameter value.
3153

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3165
    id => 4
3166
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3167

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3171
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3172
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3173
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3174
        id => [4, 5],
3175
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3176
    );
update pod
Yuki Kimoto authored on 2011-03-13
3177

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3180
    $dbi->update(
3181
        {title => 'Perl', author => 'Ken'}
3182
        where => {id1 => 4, id2 => 5},
3183
        table => 'book'
3184
    );
update pod
Yuki Kimoto authored on 2011-03-13
3185

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

            
3188
    prefix => 'or replace'
3189

            
3190
prefix before table name section
3191

            
3192
    update or replace book
3193

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

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

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

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

            
3202
    timestamp => 1
3203

            
3204
If this value is set to 1,
3205
automatically updated timestamp column is set based on
3206
C<timestamp> attribute's C<update> value.
3207

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

            
3210
Same as C<select> method's C<where> option.
3211

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

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

            
3216
placeholder wrapped string.
3217

            
3218
If the following statement
3219

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

            
3223
is executed, the following SQL is executed.
3224

            
3225
    update book set price =  ? + 5;
3226

            
updated pod
Yuki Kimoto authored on 2011-06-08
3227
=back
update pod
Yuki Kimoto authored on 2011-03-13
3228

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3236
=head2 C<update_or_insert EXPERIMENTAL>
3237
    
3238
    # Where
3239
    $dbi->update_or_insert(
3240
        {id => 1, title => 'Perl'},
3241
        table => 'book',
3242
        where => {id => 1},
3243
        select_option => {append => 'for update'}
3244
    );
3245
    
3246
    # ID
3247
    $dbi->update_or_insert(
3248
        {title => 'Perl'},
3249
        table => 'book',
3250
        id => 1,
3251
        primary_key => 'id',
3252
        select_option => {append => 'for update'}
3253
    );
3254
    
3255
Update or insert.
3256

            
3257
In both examples, the following SQL is executed.
3258

            
3259
    # In case insert
3260
    insert into book (id, title) values (?, ?)
3261
    
3262
    # In case update
3263
    update book set (id = ?, title = ?) where book.id = ?
3264

            
3265
The following opitons are available adding to C<update> option.
3266

            
3267
=over 4
3268

            
3269
=item C<select_option>
3270

            
3271
    select_option => {append => 'for update'}
3272

            
3273
select method option,
3274
select method is used to check the row is already exists.
3275

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

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

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

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

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

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

            
3296
    $dbi->show_datatype($table);
3297

            
3298
Show data type of the columns of specified table.
3299

            
3300
    book
3301
    title: 5
3302
    issue_date: 91
3303

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

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

            
3308
    $dbi->show_tables;
3309

            
3310
Show tables.
3311

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

            
3314
    $dbi->show_typename($table);
3315

            
3316
Show type name of the columns of specified table.
3317

            
3318
    book
3319
    title: varchar
3320
    issue_date: date
3321

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

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

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

            
3328
Create values clause.
3329

            
3330
    (title, author) values (title = :title, age = :age);
3331

            
3332
You can use this in insert statement.
3333

            
3334
    my $insert_sql = "insert into book $values_clause";
3335

            
3336
=head2 C<where>
3337

            
3338
    my $where = $dbi->where(
3339
        clause => ['and', 'title = :title', 'author = :author'],
3340
        param => {title => 'Perl', author => 'Ken'}
3341
    );
3342

            
3343
Create a new L<DBIx::Custom::Where> object.
3344

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

            
3347
=head2 C<DBIX_CUSTOM_DEBUG>
3348

            
3349
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3350
executed SQL and bind values are printed to STDERR.
3351

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

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

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

            
3358
L<DBIx::Custom>
3359

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

            
3405
L<DBIx::Custom::Model>
3406

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3407
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3408
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3409
    filter # will be removed at 2017/1/1
3410
    name # will be removed at 2017/1/1
3411
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3412

            
3413
L<DBIx::Custom::Query>
3414
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3415
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3416
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3417
    table # will be removed at 2017/1/1
3418
    filters # will be removed at 2017/1/1
3419
    
3420
    # Methods
3421
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3422

            
3423
L<DBIx::Custom::QueryBuilder>
3424
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3425
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3426
    tags # will be removed at 2017/1/1
3427
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3428
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3429
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3430
    register_tag # will be removed at 2017/1/1
3431
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3432
    
3433
    # Others
3434
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3435
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3436

            
3437
L<DBIx::Custom::Result>
3438
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3439
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3440
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3441
    
3442
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3443
    end_filter # will be removed at 2017/1/1
3444
    remove_end_filter # will be removed at 2017/1/1
3445
    remove_filter # will be removed at 2017/1/1
3446
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3447

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

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

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

            
3454
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3455
except for attribute method.
3456
You can check all DEPRECATED functionalities by document.
3457
DEPRECATED functionality is removed after five years,
3458
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
3459
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3460

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

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

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

            
3467
C<< <kimoto.yuki at gmail.com> >>
3468

            
3469
L<http://github.com/yuki-kimoto/DBIx-Custom>
3470

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3471
=head1 AUTHOR
3472

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

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

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

            
3479
This program is free software; you can redistribute it and/or modify it
3480
under the same terms as Perl itself.
3481

            
3482
=cut