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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
232
sub delete {
233
    my ($self, %opt) = @_;
234
    warn "delete method where_param option is DEPRECATED!"
235
      if $opt{where_param};
236
    
cleanup
Yuki Kimoto authored on 2011-10-21
237
    # Don't allow delete all rows
cleanup
Yuki Kimoto authored on 2011-10-21
238
    croak qq{delete method where or id option must be specified } . _subname
239
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
240
    
241
    # Where
242
    my $where = defined $opt{id}
243
           ? $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
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;
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
351
    my $param;
352
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
353
    my %opt = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
354
    
cleanup
Yuki Kimoto authored on 2011-10-21
355
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
356
    my $p = $opt{param} || {};
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
357
    $param ||= $p;
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';
cleanup
Yuki Kimoto authored on 2011-10-21
360
    my $filter = $opt{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
361
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-10-21
362
    my $bind_type = $opt{bind_type} || $opt{type};
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
363
    $bind_type = _array_to_hash($bind_type);
cleanup
Yuki Kimoto authored on 2011-10-21
364
    my $type_rule_off = $opt{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
365
    my $type_rule_off_parts = {
cleanup
Yuki Kimoto authored on 2011-10-21
366
        1 => $opt{type_rule1_off},
367
        2 => $opt{type_rule2_off}
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
368
    };
cleanup
Yuki Kimoto authored on 2011-10-21
369
    my $query_return = $opt{query};
370
    my $table_alias = $opt{table_alias} || {};
371
    my $after_build_sql = $opt{after_build_sql} || $opt{sqlfilter};
372
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
373
    my $id = $opt{id};
374
    my $primary_key = $opt{primary_key};
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
375
    croak "execute method primary_key option " .
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
376
          "must be specified when id is specified " . _subname
377
      if defined $id && !defined $primary_key;
378
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
379
    my $append = $opt{append};
cleanup
Yuki Kimoto authored on 2011-10-20
380
    $sql .= $append if defined $append && !ref $sql;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
381
    
cleanup
Yuki Kimoto authored on 2011-10-20
382
    my $query
383
      = ref $sql ? $sql : $self->_create_query($sql, $after_build_sql);
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
384
    
385
    # Save query
386
    $self->last_sql($query->sql);
387

            
cleanup
Yuki Kimoto authored on 2011-06-09
388
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
389
    
390
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
391
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
392
    
cleanup
Yuki Kimoto authored on 2011-04-02
393
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
394
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
395
    my $main_table = @{$tables}[-1];
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
396

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

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

            
523
        return $result;
524
    }
cleanup
Yuki Kimoto authored on 2011-04-02
525
    
526
    # Not select statement
527
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
528
}
529

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
545
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
546
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
547
    
cleanup
Yuki Kimoto authored on 2011-10-21
548
    my $exclude_table = delete $opt{exclude_table};
549
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
550
    
551
    my $column_info = [];
552
    $self->each_column(
553
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
554
        exclude_table => $exclude_table
555
    );
556
    
557
    return [
558
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
559
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
560
}
561

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
562
sub helper {
563
    my $self = shift;
564
    
565
    # Register method
566
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
567
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
568
    
569
    return $self;
570
}
571

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
605
sub insert_timestamp {
606
    my $self = shift;
607
    
608
    if (@_) {
609
        $self->{insert_timestamp} = [@_];
610
        
611
        return $self;
612
    }
613
    return $self->{insert_timestamp};
614
}
615

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
616
sub include_model {
617
    my ($self, $name_space, $model_infos) = @_;
618
    
cleanup
Yuki Kimoto authored on 2011-04-02
619
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
620
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
621
    
622
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
623
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
624

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
683
sub mapper {
684
    my $self = shift;
685
    return DBIx::Custom::Mapper->new(@_);
686
}
687

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
688
sub merge_param {
689
    my ($self, @params) = @_;
690
    
cleanup
Yuki Kimoto authored on 2011-04-02
691
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
692
    my $merge = {};
cleanup
Yuki Kimoto authored on 2011-10-21
693
    for my $param (@params) {
694
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
695
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
696
            
697
            if (exists $merge->{$column}) {
698
                $merge->{$column} = [$merge->{$column}]
699
                  unless ref $merge->{$column} eq 'ARRAY';
700
                push @{$merge->{$column}},
701
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
702
            }
703
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
704
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
705
            }
706
        }
707
    }
708
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
709
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
710
}
711

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
712
sub model {
713
    my ($self, $name, $model) = @_;
714
    
cleanup
Yuki Kimoto authored on 2011-04-02
715
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
716
    if ($model) {
717
        $self->models->{$name} = $model;
718
        return $self;
719
    }
720
    
721
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
722
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
723
      unless $self->models->{$name};
724
    
cleanup
Yuki Kimoto authored on 2011-04-02
725
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
726
    return $self->models->{$name};
727
}
728

            
cleanup
Yuki Kimoto authored on 2011-03-21
729
sub mycolumn {
730
    my ($self, $table, $columns) = @_;
731
    
cleanup
Yuki Kimoto authored on 2011-04-02
732
    # Create column clause
733
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
734
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
735
    push @column, $self->_q($table) . "." . $self->_q($_) .
736
      " as " . $self->_q($_)
737
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
738
    
739
    return join (', ', @column);
740
}
741

            
added dbi_options attribute
kimoto authored on 2010-12-20
742
sub new {
743
    my $self = shift->SUPER::new(@_);
744
    
cleanup
Yuki Kimoto authored on 2011-04-02
745
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
746
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
747
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
748
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
749
          unless $self->can($attr);
750
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
751

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
752
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
753
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
754
        '?'     => \&DBIx::Custom::Tag::placeholder,
755
        '='     => \&DBIx::Custom::Tag::equal,
756
        '<>'    => \&DBIx::Custom::Tag::not_equal,
757
        '>'     => \&DBIx::Custom::Tag::greater_than,
758
        '<'     => \&DBIx::Custom::Tag::lower_than,
759
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
760
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
761
        'like'  => \&DBIx::Custom::Tag::like,
762
        'in'    => \&DBIx::Custom::Tag::in,
763
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
764
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
765
    };
766
    
767
    return $self;
768
}
769

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

            
772
sub order {
773
    my $self = shift;
774
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
775
}
776

            
cleanup
yuki-kimoto authored on 2010-10-17
777
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
778
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
779
    
780
    # Register filter
781
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
782
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
783
    
cleanup
Yuki Kimoto authored on 2011-04-02
784
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
785
}
packaging one directory
yuki-kimoto authored on 2009-11-16
786

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
849
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
850
    unshift @$tables,
851
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
852
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
853
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
854
    my $where = defined $opt{id}
855
              ? $self->_id_to_param($opt{id}, $opt{primary_key}, $tables->[-1])
856
              : $opt{where};
857
    my $w = $self->_where_clause_and_param($where, $where_param);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
858
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
859
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
860
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
861
    
cleanup
Yuki Kimoto authored on 2011-10-21
862
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
863
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
864
    
cleanup
Yuki Kimoto authored on 2011-03-09
865
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
866
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
867
    
cleanup
Yuki Kimoto authored on 2011-03-08
868
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
869
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
870
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
871
    
packaging one directory
yuki-kimoto authored on 2009-11-16
872
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
873
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
874
    
875
    return $result;
876
}
877

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
878
sub setup_model {
879
    my $self = shift;
880
    
cleanup
Yuki Kimoto authored on 2011-04-02
881
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
882
    $self->each_column(
883
        sub {
884
            my ($self, $table, $column, $column_info) = @_;
885
            if (my $model = $self->models->{$table}) {
886
                push @{$model->columns}, $column;
887
            }
888
        }
889
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
890
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
891
}
892

            
update pod
Yuki Kimoto authored on 2011-08-10
893
sub show_datatype {
894
    my ($self, $table) = @_;
895
    croak "Table name must be specified" unless defined $table;
896
    print "$table\n";
897
    
898
    my $result = $self->select(table => $table, where => "'0' <> '0'");
899
    my $sth = $result->sth;
900

            
901
    my $columns = $sth->{NAME};
902
    my $data_types = $sth->{TYPE};
903
    
904
    for (my $i = 0; $i < @$columns; $i++) {
905
        my $column = $columns->[$i];
906
        my $data_type = $data_types->[$i];
907
        print "$column: $data_type\n";
908
    }
909
}
910

            
911
sub show_typename {
912
    my ($self, $t) = @_;
913
    croak "Table name must be specified" unless defined $t;
914
    print "$t\n";
915
    
916
    $self->each_column(sub {
917
        my ($self, $table, $column, $infos) = @_;
918
        return unless $table eq $t;
919
        my $typename = $infos->{TYPE_NAME};
920
        print "$column: $typename\n";
921
    });
922
    
923
    return $self;
924
}
925

            
test cleanup
Yuki Kimoto authored on 2011-08-15
926
sub show_tables {
927
    my $self = shift;
928
    
929
    my %tables;
930
    $self->each_table(sub { $tables{$_[1]}++ });
931
    print join("\n", sort keys %tables) . "\n";
932
    return $self;
933
}
934

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
935
sub type_rule {
936
    my $self = shift;
937
    
938
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
939
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
940
        
941
        # Into
cleanup
Yuki Kimoto authored on 2011-10-21
942
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
943
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
944
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
945
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
946
            $self->{type_rule} = $type_rule;
947
            $self->{"_$into"} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
948
            for my $type_name (keys %{$type_rule->{$into} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
949
                croak qq{type name of $into section must be lower case}
950
                  if $type_name =~ /[A-Z]/;
951
            }
cleanup
Yuki Kimoto authored on 2011-08-16
952
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
953
            $self->each_column(sub {
954
                my ($dbi, $table, $column, $column_info) = @_;
955
                
956
                my $type_name = lc $column_info->{TYPE_NAME};
957
                if ($type_rule->{$into} &&
958
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
959
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
960
                    return unless exists $type_rule->{$into}->{$type_name};
961
                    if  (defined $filter && ref $filter ne 'CODE') 
962
                    {
963
                        my $fname = $filter;
964
                        croak qq{Filter "$fname" is not registered" } . _subname
965
                          unless exists $self->filters->{$fname};
966
                        
967
                        $filter = $self->filters->{$fname};
968
                    }
969

            
micro optimization
Yuki Kimoto authored on 2011-07-30
970
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
971
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
972
                }
973
            });
974
        }
975

            
976
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
977
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
978
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
979
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
980
                croak qq{data type of from$i section must be lower case or number}
981
                  if $data_type =~ /[A-Z]/;
982
                my $fname = $type_rule->{"from$i"}{$data_type};
983
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
984
                    croak qq{Filter "$fname" is not registered" } . _subname
985
                      unless exists $self->filters->{$fname};
986
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
987
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
988
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
989
            }
990
        }
991
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
992
        return $self;
993
    }
994
    
995
    return $self->{type_rule} || {};
996
}
997

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1001
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1002
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1003
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1004
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1005
    warn "update method where_param option is DEPRECATED!"
1006
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1007
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1008
    
cleanup
Yuki Kimoto authored on 2011-10-21
1009
    # Don't allow update all rows
1010
    croak qq{update method where option must be specified } . _subname
1011
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1012
    
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1013
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1014
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1015
        my $columns = $update_timestamp->[0];
1016
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1017
        my $value = $update_timestamp->[1];
1018
        $value = $value->() if ref $value eq 'CODE';
1019
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1020
    }
1021

            
cleanup
Yuki Kimoto authored on 2011-10-21
1022
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1023
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1024
    
1025
    # Convert id to where parameter
1026
    my $where = defined $opt{id}
1027
      ? $self->_id_to_param($opt{id}, $opt{primary_key}, $opt{table})
1028
      : $opt{where};
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1029

            
1030
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1031
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1032
    
cleanup
Yuki Kimoto authored on 2011-10-21
1033
    # Merge where parameter to parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1034
    $param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1035
    
cleanup
Yuki Kimoto authored on 2011-04-02
1036
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1037
    my $sql = "update ";
1038
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
1039
    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1040
    
cleanup
yuki-kimoto authored on 2010-10-17
1041
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
1042
    return $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1043
}
1044

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1047
sub update_or_insert {
1048
    my $self = shift;
1049

            
cleanup
Yuki Kimoto authored on 2011-10-21
1050
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1051
    my $param  = shift;
1052
    my %opt = @_;
1053
    my $id = $opt{id};
1054
    my $primary_key = $opt{primary_key};
1055
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1056
    croak "update_or_insert method need primary_key option " .
1057
          "when id is specified" . _subname
1058
      if defined $id && !defined $primary_key;
1059
    my $table  = $opt{table};
1060
    croak qq{"table" option must be specified } . _subname
1061
      unless defined $table;
1062
    my $select_option = $opt{select_option};
1063
    
1064
    my $rows = $self->select(table => $table, id => $id,
1065
        primary_key => $primary_key, %$select_option)->all;
1066
    
1067
    croak "selected row count must be one or zero" . _subname
1068
      if @$rows > 1;
1069
    
1070
    my $row = $rows->[0];
1071
    my @opt = (table => $table);
1072
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1073
    push @opt, %opt;
1074
    
1075
    if ($row) {
1076
        return $self->update($param, @opt);
1077
    }
1078
    else {
1079
        return $self->insert($param, @opt);
1080
    }
1081
}
1082

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1083
sub update_timestamp {
1084
    my $self = shift;
1085
    
1086
    if (@_) {
1087
        $self->{update_timestamp} = [@_];
1088
        
1089
        return $self;
1090
    }
1091
    return $self->{update_timestamp};
1092
}
1093

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1094
sub values_clause {
1095
    my ($self, $param, $opts) = @_;
1096
    
1097
    my $wrap = $opts->{wrap} || {};
1098
    
1099
    # Create insert parameter tag
1100
    my $safety = $self->safety_character;
1101
    my @columns;
1102
    my @placeholders;
cleanup
Yuki Kimoto authored on 2011-10-21
1103
    for my $column (sort keys %$param) {
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1104
        croak qq{"$column" is not safety column name } . _subname
1105
          unless $column =~ /^[$safety\.]+$/;
1106
        my $column_quote = $self->_q($column);
1107
        $column_quote =~ s/\./$self->_q(".")/e;
1108
        push @columns, $column_quote;
1109
        
1110
        my $func = $wrap->{$column} || sub { $_[0] };
1111
        push @placeholders,
1112
          ref $param->{$column} eq 'SCALAR' ? ${$param->{$column}}
1113
        : $func->(":$column");
1114
    }
1115
    
1116
    return '(' . join(', ', @columns) . ') ' . 'values ' .
1117
           '(' . join(', ', @placeholders) . ')'
1118
}
1119

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1122
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1123
    
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1124
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1125
    
updated pod
Yuki Kimoto authored on 2011-06-21
1126
    # Cache
1127
    my $cache = $self->cache;
1128
    
1129
    # Query
1130
    my $query;
1131
    
1132
    # Get cached query
1133
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1134
        
updated pod
Yuki Kimoto authored on 2011-06-21
1135
        # Get query
1136
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1137
        
updated pod
Yuki Kimoto authored on 2011-06-21
1138
        # Create query
1139
        if ($q) {
1140
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1141
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1142
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1143
    }
1144
    
1145
    # Create query
1146
    unless ($query) {
1147

            
1148
        # Create query
1149
        my $builder = $self->query_builder;
1150
        $query = $builder->build_query($source);
1151

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

            
1158
        # Save query to cache
1159
        $self->cache_method->(
1160
            $self, $source,
1161
            {
1162
                sql     => $query->sql, 
1163
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1164
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1165
            }
1166
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1167
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1168

            
1169
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1170
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1171
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1172
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1173
        $query->sql($sql);
1174
    }
1175
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1176
    # Save sql
1177
    $self->last_sql($query->sql);
1178
    
updated pod
Yuki Kimoto authored on 2011-06-21
1179
    # Prepare statement handle
1180
    my $sth;
1181
    eval { $sth = $self->dbh->prepare($query->{sql})};
1182
    
1183
    if ($@) {
1184
        $self->_croak($@, qq{. Following SQL is executed.\n}
1185
                        . qq{$query->{sql}\n} . _subname);
1186
    }
1187
    
1188
    # Set statement handle
1189
    $query->sth($sth);
1190
    
1191
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1192
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1193
    
1194
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1195
}
1196

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1308
sub _croak {
1309
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1310
    
1311
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1312
    $append ||= "";
1313
    
1314
    # Verbose
1315
    if ($Carp::Verbose) { croak $error }
1316
    
1317
    # Not verbose
1318
    else {
1319
        
1320
        # Remove line and module infromation
1321
        my $at_pos = rindex($error, ' at ');
1322
        $error = substr($error, 0, $at_pos);
1323
        $error =~ s/\s+$//;
1324
        croak "$error$append";
1325
    }
1326
}
1327

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1330
sub _need_tables {
1331
    my ($self, $tree, $need_tables, $tables) = @_;
1332
    
cleanup
Yuki Kimoto authored on 2011-04-02
1333
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1334
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1335
        if ($tree->{$table}) {
1336
            $need_tables->{$table} = 1;
1337
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1338
        }
1339
    }
1340
}
1341

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1342
sub _option {
1343
    my $self = shift;
1344
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1345
    warn "dbi_options is DEPRECATED! use option instead\n"
1346
      if keys %{$self->dbi_options};
1347
    warn "dbi_option is DEPRECATED! use option instead\n"
1348
      if keys %{$self->dbi_option};
1349
    return $option;
1350
}
1351

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1352
sub _push_join {
1353
    my ($self, $sql, $join, $join_tables) = @_;
1354
    
cleanup
Yuki Kimoto authored on 2011-10-21
1355
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1356
    
cleanup
Yuki Kimoto authored on 2011-04-02
1357
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1358
    return unless @$join;
1359
    
cleanup
Yuki Kimoto authored on 2011-04-02
1360
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1361
    my $tree = {};
1362
    for (my $i = 0; $i < @$join; $i++) {
1363
        
cleanup
Yuki Kimoto authored on 2011-07-28
1364
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1365
        my $join_clause;;
1366
        my $option;
1367
        if (ref $join->[$i] eq 'HASH') {
1368
            $join_clause = $join->[$i]->{clause};
1369
            $option = {table => $join->[$i]->{table}};
1370
        }
1371
        else {
1372
            $join_clause = $join->[$i];
1373
            $option = {};
1374
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1375

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1423
sub _quote {
1424
    my $self = shift;
1425
    
1426
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1427
         : defined $self->quote ? $self->quote
1428
         : '';
1429
}
1430

            
cleanup
Yuki Kimoto authored on 2011-07-29
1431
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1432
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1433
    
1434
    my $quote = $self->_quote;
1435
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1436
    my $p;
1437
    if (defined $quote && length $quote > 1) {
1438
        $p = substr($quote, 1, 1);
1439
    }
1440
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1441
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1442
    if ($quotemeta) {
1443
        $q = quotemeta($q);
1444
        $p = quotemeta($p);
1445
    }
1446
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1447
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1448
}
1449

            
cleanup
Yuki Kimoto authored on 2011-04-02
1450
sub _remove_duplicate_table {
1451
    my ($self, $tables, $main_table) = @_;
1452
    
1453
    # Remove duplicate table
1454
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1455
    delete $tables{$main_table} if $main_table;
1456
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1457
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1458
    if (my $q = $self->_quote) {
1459
        $q = quotemeta($q);
1460
        $_ =~ s/[$q]//g for @$new_tables;
1461
    }
1462

            
1463
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1464
}
1465

            
cleanup
Yuki Kimoto authored on 2011-04-02
1466
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1467
    my ($self, $source) = @_;
1468
    
cleanup
Yuki Kimoto authored on 2011-04-02
1469
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1470
    my $tables = [];
1471
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1472
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1473
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1474
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1475
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1476
    while ($source =~ /$table_re/g) {
1477
        push @$tables, $1;
1478
    }
1479
    
1480
    return $tables;
1481
}
1482

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1532
sub _where_clause_and_param {
1533
    my ($self, $where, $param) = @_;
1534
 
1535
    $where ||= {};
1536
    $param ||= {};
1537
    my $w = {};
1538
    my $where_clause = '';
1539
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1540
        $w->{clause} = "where " . $where->[0];
1541
        $w->{param} = $where->[1];
1542
    }
1543
    elsif (ref $where) {
1544
        $where = $self->_where_to_obj($where);
1545
        $w->{param} = keys %$param
1546
                    ? $self->merge_param($param, $where->param)
1547
                    : $where->param;
1548
        $w->{clause} = $where->to_string;
1549
    }
1550
    elsif ($where) {
1551
        $w->{clause} = "where $where";
1552
        $w->{param} = $param;
1553
    }
1554
    
1555
    return $w;
1556
}
1557

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1628
# DEPRECATED!
1629
has 'data_source';
1630
has dbi_options => sub { {} };
1631
has filter_check  => 1;
1632
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1633
has dbi_option => sub { {} };
1634
has default_dbi_option => sub {
1635
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1636
    return shift->default_option;
1637
};
1638

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1639
# DEPRECATED!
1640
sub method {
1641
    warn "method is DEPRECATED! use helper instead";
1642
    return shift->helper(@_);
1643
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1644

            
1645
# DEPRECATED!
1646
sub assign_param {
1647
    my $self = shift;
1648
    warn "assing_param is DEPRECATED! use assign_clause instead";
1649
    return $self->assign_clause(@_);
1650
}
1651

            
1652
# DEPRECATED
1653
sub update_param {
1654
    my ($self, $param, $opts) = @_;
1655
    
1656
    warn "update_param is DEPRECATED! use assing_clause instead.";
1657
    
1658
    # Create update parameter tag
1659
    my $tag = $self->assign_clause($param, $opts);
1660
    $tag = "set $tag" unless $opts->{no_set};
1661

            
1662
    return $tag;
1663
}
1664

            
updated pod
Yuki Kimoto authored on 2011-06-21
1665
# DEPRECATED!
1666
sub create_query {
1667
    warn "create_query is DEPRECATED! use query option of each method";
1668
    shift->_create_query(@_);
1669
}
1670

            
cleanup
Yuki Kimoto authored on 2011-06-13
1671
# DEPRECATED!
1672
sub apply_filter {
1673
    my $self = shift;
1674
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1675
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1676
    return $self->_apply_filter(@_);
1677
}
1678

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1685
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1686
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1687
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1688
    my $where = delete $opt{where};
1689
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1690
    
1691
    # Table
1692
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1693
      unless $opt{table};
1694
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1695
    
1696
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1697
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1698
    
cleanup
Yuki Kimoto authored on 2011-10-21
1699
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1700
}
1701

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1706
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1707
    
cleanup
Yuki Kimoto authored on 2011-10-21
1708
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1709
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1710
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1711
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1712
    
1713
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1714
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1715
    
cleanup
Yuki Kimoto authored on 2011-10-21
1716
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1717
}
1718

            
cleanup
Yuki Kimoto authored on 2011-06-08
1719
# DEPRECATED!
1720
sub update_at {
1721
    my $self = shift;
1722

            
cleanup
Yuki Kimoto authored on 2011-10-21
1723
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1724
    
cleanup
Yuki Kimoto authored on 2011-10-21
1725
    # Options
cleanup
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_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1730
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1731
    my $where = delete $opt{where};
1732
    my $p = delete $opt{param} || {};
cleanup
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_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1737
    
cleanup
Yuki Kimoto authored on 2011-10-21
1738
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1739
}
1740

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1741
# DEPRECATED!
1742
sub insert_at {
1743
    my $self = shift;
1744
    
cleanup
Yuki Kimoto authored on 2011-10-21
1745
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1746
    
cleanup
Yuki Kimoto authored on 2011-10-21
1747
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1748
    my $param;
1749
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1750
    my %opt = @_;
1751
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1752
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1753
    my $where = delete $opt{where};
1754
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1755
    $param  ||= $p;
1756
    
1757
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1758
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1759
    $param = $self->merge_param($where_param, $param);
1760
    
cleanup
Yuki Kimoto authored on 2011-10-21
1761
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1762
}
1763

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

            
1777
# DEPRECATED!
1778
sub register_tag_processor {
1779
    my $self = shift;
1780
    warn "register_tag_processor is DEPRECATED!";
1781
    # Merge tag
1782
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1783
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1784
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1785
}
1786

            
cleanup
Yuki Kimoto authored on 2011-01-25
1787
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1788
sub default_bind_filter {
1789
    my $self = shift;
1790
    
cleanup
Yuki Kimoto authored on 2011-06-13
1791
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1792
    
cleanup
Yuki Kimoto authored on 2011-01-12
1793
    if (@_) {
1794
        my $fname = $_[0];
1795
        
1796
        if (@_ && !$fname) {
1797
            $self->{default_out_filter} = undef;
1798
        }
1799
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1800
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1801
              unless exists $self->filters->{$fname};
1802
        
1803
            $self->{default_out_filter} = $self->filters->{$fname};
1804
        }
1805
        return $self;
1806
    }
1807
    
1808
    return $self->{default_out_filter};
1809
}
1810

            
cleanup
Yuki Kimoto authored on 2011-01-25
1811
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1812
sub default_fetch_filter {
1813
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1814

            
cleanup
Yuki Kimoto authored on 2011-06-13
1815
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1816
    
1817
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1818
        my $fname = $_[0];
1819

            
cleanup
Yuki Kimoto authored on 2011-01-12
1820
        if (@_ && !$fname) {
1821
            $self->{default_in_filter} = undef;
1822
        }
1823
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1824
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1825
              unless exists $self->filters->{$fname};
1826
        
1827
            $self->{default_in_filter} = $self->filters->{$fname};
1828
        }
1829
        
1830
        return $self;
1831
    }
1832
    
many changed
Yuki Kimoto authored on 2011-01-23
1833
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1834
}
1835

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1836
# DEPRECATED!
1837
sub insert_param {
1838
    my $self = shift;
1839
    warn "insert_param is DEPRECATED! use values_clause instead";
1840
    return $self->values_clause(@_);
1841
}
1842

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1843
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1844
sub insert_param_tag {
1845
    warn "insert_param_tag is DEPRECATED! " .
1846
         "use insert_param instead!";
1847
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1848
}
1849

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

            
1872
# DEPRECATED!
1873
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1874
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1875
    
1876
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1877
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1878
            my $table1 = (split (/\./, $rcolumn))[0];
1879
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1880
            my $table1_exists;
1881
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1882
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1883
                $table1_exists = 1 if $table eq $table1;
1884
                $table2_exists = 1 if $table eq $table2;
1885
            }
1886
            unshift @$tables, $table1 unless $table1_exists;
1887
            unshift @$tables, $table2 unless $table2_exists;
1888
        }
1889
    }
1890
}
1891

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1894
=head1 NAME
1895

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1896
DBIx::Custom - Execute insert, update, delete, and select statement easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1897

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1900
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1901
    
1902
    # Connect
1903
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1904
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1905
        user => 'ken',
1906
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1907
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1908
    );
cleanup
yuki-kimoto authored on 2010-08-05
1909

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1910
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1911
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1912
    
1913
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1914
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1915
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1916
    
1917
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1918
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1919

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1969
Named place holder support
1970

            
1971
=item *
1972

            
cleanup
Yuki Kimoto authored on 2011-07-29
1973
Model support
1974

            
1975
=item *
1976

            
1977
Connection manager support
1978

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

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

            
1985
=item *
1986

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

            
1989
=item *
1990

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

            
1993
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1994

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2002
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2003
L<DBIx::Custom::Result>,
2004
L<DBIx::Custom::Query>,
2005
L<DBIx::Custom::Where>,
2006
L<DBIx::Custom::Model>,
2007
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2008

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

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

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

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

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

            
2022
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2023
        "dbi:mysql:database=$database",
2024
        $user,
2025
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2026
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2027
    );
2028
    
updated pod
Yuki Kimoto authored on 2011-06-21
2029
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2030

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

            
2034
    my $dbi = DBIx::Custom->connect(
2035
      dsn => $dsn, user => $user, password => $password, connector => 1);
2036
    
2037
    my $connector = $dbi->connector; # DBIx::Connector
2038

            
2039
Note that L<DBIx::Connector> must be installed.
2040

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2056
    {
2057
        RaiseError => 1,
2058
        PrintError => 0,
2059
        AutoCommit => 1,
2060
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2061

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

            
2064
    my $exclude_table = $dbi->exclude_table;
2065
    $dbi = $dbi->exclude_table(qr/pg_/);
2066

            
2067
Excluded table regex.
2068
C<each_column>, C<each_table>, C<type_rule>,
2069
and C<setup_model> methods ignore matching tables.
2070

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

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

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

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

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

            
2083
Get last successed SQL executed by C<execute> method.
2084

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

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

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

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

            
2094
    my $option = $dbi->option;
2095
    $dbi = $dbi->option($option);
2096

            
2097
L<DBI> option, used when C<connect> method is executed.
2098
Each value in option override the value of C<default_option>.
2099

            
cleanup
yuki-kimoto authored on 2010-10-17
2100
=head2 C<password>
2101

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2122
You can set quote pair.
2123

            
2124
    $dbi->quote('[]');
2125

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2135
    my $safety_character = $dbi->safety_character;
2136
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2137

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

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

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

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

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

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

            
2154
    my $tag_parse = $dbi->tag_parse(0);
2155
    $dbi = $dbi->tag_parse;
2156

            
2157
Enable DEPRECATED tag parsing functionality, default to 1.
2158
If you want to disable tag parsing functionality, set to 0.
2159

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

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

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

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

            
2169
    my $user_column_info = $dbi->user_column_info;
2170
    $dbi = $dbi->user_column_info($user_column_info);
2171

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

            
2174
    [
2175
        {table => 'book', column => 'title', info => {...}},
2176
        {table => 'author', column => 'name', info => {...}}
2177
    ]
2178

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

            
2181
    my $user_column_info
2182
      = $dbi->get_column_info(exclude_table => qr/^system/);
2183
    $dbi->user_column_info($user_column_info);
2184

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

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

            
2190
    my $user_table_info = $dbi->user_table_info;
2191
    $dbi = $dbi->user_table_info($user_table_info);
2192

            
2193
You can set the following data.
2194

            
2195
    [
2196
        {table => 'book', info => {...}},
2197
        {table => 'author', info => {...}}
2198
    ]
2199

            
2200
Usually, you can set return value of C<get_table_info>.
2201

            
2202
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2203
    $dbi->user_table_info($user_table_info);
2204

            
2205
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2206
to find table info.
2207

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2244
Create column clause. The follwoing column clause is created.
2245

            
2246
    book.author as "book.author",
2247
    book.title as "book.title"
2248

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2251
    # Separator is hyphen
2252
    $dbi->separator('-');
2253
    
2254
    book.author as "book-author",
2255
    book.title as "book-title"
2256
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2257
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2258

            
update pod
Yuki Kimoto authored on 2011-03-13
2259
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2260
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2261
        user => 'ken',
2262
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2263
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2264
    );
2265

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

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

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

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

            
2276
Get rows count.
2277

            
2278
Options is same as C<select> method's ones.
2279

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2282
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2283
        table => 'book',
2284
        primary_key => 'id',
2285
        join => [
2286
            'inner join company on book.comparny_id = company.id'
2287
        ],
2288
    );
2289

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

            
2293
   $dbi->model('book')->select(...);
2294

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

            
2297
    my $dbh = $dbi->dbh;
2298

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

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

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

            
2306
Execute delete statement.
2307

            
2308
The following opitons are available.
2309

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

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

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

            
2317
=item C<id>
2318

            
2319
    id => 4
2320
    id => [4, 5]
2321

            
2322
ID corresponding to C<primary_key>.
2323
You can delete rows by C<id> and C<primary_key>.
2324

            
2325
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2326
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2327
        id => [4, 5],
2328
        table => 'book',
2329
    );
2330

            
2331
The above is same as the followin one.
2332

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

            
2335
=item C<prefix>
2336

            
2337
    prefix => 'some'
2338

            
2339
prefix before table name section.
2340

            
2341
    delete some from book
2342

            
2343
=item C<table>
2344

            
2345
    table => 'book'
2346

            
2347
Table name.
2348

            
2349
=item C<where>
2350

            
2351
Same as C<select> method's C<where> option.
2352

            
2353
=back
2354

            
2355
=head2 C<delete_all>
2356

            
2357
    $dbi->delete_all(table => $table);
2358

            
2359
Execute delete statement for all rows.
2360
Options is same as C<delete>.
2361

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

            
2364
    $dbi->each_column(
2365
        sub {
2366
            my ($dbi, $table, $column, $column_info) = @_;
2367
            
2368
            my $type = $column_info->{TYPE_NAME};
2369
            
2370
            if ($type eq 'DATE') {
2371
                # ...
2372
            }
2373
        }
2374
    );
2375

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

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

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

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

            
2391
    $dbi->each_table(
2392
        sub {
2393
            my ($dbi, $table, $table_info) = @_;
2394
            
2395
            my $table_name = $table_info->{TABLE_NAME};
2396
        }
2397
    );
2398

            
improved pod
Yuki Kimoto authored on 2011-10-14
2399
Iterate all table informationsfrom in database.
2400
Argument is callback which is executed when one table is found.
2401
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2402
C<table information>.
2403

            
2404
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2405
infromation, you can improve the performance of C<each_table> in
2406
the following way.
2407

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

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

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

            
2419
    my $result = $dbi->execute(
2420
      "select * from book where title = :book.title and author like :book.author",
2421
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2422
    );
2423

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2430
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2431
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2432
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2433
    select * from book where title = :title and author like :author
2434
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2435
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2436
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2437

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2441
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2442
    select * from book where :title{=} and :author{like}
2443
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2444
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2445
    select * from where title = ? and author like ?;
2446

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

            
2451
    select * from where title = "aa\\:bb";
2452

            
cleanup
Yuki Kimoto authored on 2011-10-20
2453
B<OPTIONS>
2454

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

            
2457
=over 4
2458

            
cleanup
Yuki Kimoto authored on 2011-10-20
2459
=item C<append>
2460

            
2461
    append => 'order by name'
2462

            
2463
Append some statement after SQL.
2464

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

            
2467
Specify database bind data type.
2468

            
2469
    bind_type => [image => DBI::SQL_BLOB]
2470
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2471

            
2472
This is used to bind parameter by C<bind_param> of statment handle.
2473

            
2474
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2475

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

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

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

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

            
2501
    id => 4
2502
    id => [4, 5]
2503

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

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

            
2514
The above is same as the followin one.
2515

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

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

            
2523
    query => 1
2524

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2573
    $dbi->select(
2574
        table => 'book',
2575
        column => 'distinct(name)',
2576
        after_build_sql => sub {
2577
            "select count(*) from ($_[0]) as t1"
2578
        }
2579
    );
2580

            
2581
The following SQL is executed.
2582

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2585
=item C<table>
2586
    
2587
    table => 'author'
2588

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2596
    # Same
2597
    $dbi->execute(
2598
      "select * from book where title = :book.title and author = :book.author",
2599
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2600

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

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

            
2605
Table alias. Key is real table name, value is alias table name.
2606
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2607
on alias table name.
2608

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

            
2611
    type_rule_off => 1
2612

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

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

            
2617
    type_rule1_off => 1
2618

            
2619
Turn C<into1> type rule off.
2620

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

            
2623
    type_rule2_off => 1
2624

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

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

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

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

            
2633
get column infomation except for one which match C<exclude_table> pattern.
2634

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

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

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

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

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

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

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

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

            
2668
Register helper. These helper is called directly from L<DBIx::Custom> object.
2669

            
2670
    $dbi->update_or_insert;
2671
    $dbi->find_or_create;
2672

            
cleanup
yuki-kimoto authored on 2010-10-17
2673
=head2 C<insert>
2674

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

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

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

            
2683
    {date => \"NOW()"}
2684

            
cleanup
Yuki Kimoto authored on 2011-10-20
2685
B<options>
2686

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

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

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

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

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

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

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

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

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

            
2716
    prefix => 'or replace'
2717

            
2718
prefix before table name section
2719

            
2720
    insert or replace into book
2721

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

            
2724
    table => 'book'
2725

            
2726
Table name.
2727

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

            
2730
    timestamp => 1
2731

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

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

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

            
2740
placeholder wrapped string.
2741

            
2742
If the following statement
2743

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

            
2747
is executed, the following SQL is executed.
2748

            
2749
    insert into book price values ( ? + 5 );
2750

            
update pod
Yuki Kimoto authored on 2011-03-13
2751
=back
2752

            
2753
=over 4
2754

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2802
$dbi->insert_timestamp(
2803
  [qw/created_at updated_at/]
2804
    => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
2805
);
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2806

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

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

            
2814
$dbi->insert($param, table => 'book', timestamp => 1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2815

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

            
2818
    my $like_value = $dbi->like_value
2819

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

            
2822
    sub { "%$_[0]%" }
2823

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

            
2826
    my $mapper = $dbi->mapper(param => $param);
2827

            
2828
Create a new L<DBIx::Custom::Mapper> object.
2829

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

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

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

            
2836
    {key1 => [1, 1], key2 => 2}
2837

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

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

            
2842
    my $model = $dbi->model('book');
2843

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

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

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

            
2851
Create column clause for myself. The follwoing column clause is created.
2852

            
2853
    book.author as author,
2854
    book.title as title
2855

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

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

            
2865
Create a new L<DBIx::Custom> object.
2866

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

            
2869
    my $not_exists = $dbi->not_exists;
2870

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

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

            
2876
    my $order = $dbi->order;
2877

            
2878
Create a new L<DBIx::Custom::Order> object.
2879

            
cleanup
yuki-kimoto authored on 2010-10-17
2880
=head2 C<register_filter>
2881

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

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

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

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

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

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

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

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

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

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

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

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

            
2934
    book.author as "book.author",
2935
    book.title as "book.title",
2936
    person.name as "person.name",
2937
    person.age as "person.age"
2938

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

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

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

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

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

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

            
2954
=item C<id>
2955

            
2956
    id => 4
2957
    id => [4, 5]
2958

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

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

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

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

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

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

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

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

            
2989
    prefix => 'SQL_CALC_FOUND_ROWS'
2990

            
2991
Prefix of column cluase
2992

            
2993
    select SQL_CALC_FOUND_ROWS title, author from book;
2994

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3042
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3043

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

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

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

            
3076
    $dbi->setup_model;
3077

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

            
3081
=head2 C<type_rule>
3082

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

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

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

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

            
3116
C<into2> is executed after C<into1>.
3117

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

            
3121
=over 4
3122

            
3123
=item 1. column name
3124

            
3125
    issue_date
3126
    issue_datetime
3127

            
3128
This need C<table> option in each method.
3129

            
3130
=item 2. table name and column name, separator is dot
3131

            
3132
    book.issue_date
3133
    book.issue_datetime
3134

            
3135
=back
3136

            
3137
You get all type name used in database by C<available_typename>.
3138

            
3139
    print $dbi->available_typename;
3140

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

            
3145
    print $dbi->available_datatype;
3146

            
3147
You can also specify multiple types at once.
3148

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3198
    prefix => 'or replace'
3199

            
3200
prefix before table name section
3201

            
3202
    update or replace book
3203

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

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

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

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

            
3212
    timestamp => 1
3213

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

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

            
3220
Same as C<select> method's C<where> option.
3221

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

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

            
3226
placeholder wrapped string.
3227

            
3228
If the following statement
3229

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

            
3233
is executed, the following SQL is executed.
3234

            
3235
    update book set price =  ? + 5;
3236

            
updated pod
Yuki Kimoto authored on 2011-06-08
3237
=back
update pod
Yuki Kimoto authored on 2011-03-13
3238

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

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

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

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

            
3267
In both examples, the following SQL is executed.
3268

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

            
3275
The following opitons are available adding to C<update> option.
3276

            
3277
=over 4
3278

            
3279
=item C<select_option>
3280

            
3281
    select_option => {append => 'for update'}
3282

            
3283
select method option,
3284
select method is used to check the row is already exists.
3285

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

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

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

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

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

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

            
3306
    $dbi->show_datatype($table);
3307

            
3308
Show data type of the columns of specified table.
3309

            
3310
    book
3311
    title: 5
3312
    issue_date: 91
3313

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

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

            
3318
    $dbi->show_tables;
3319

            
3320
Show tables.
3321

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

            
3324
    $dbi->show_typename($table);
3325

            
3326
Show type name of the columns of specified table.
3327

            
3328
    book
3329
    title: varchar
3330
    issue_date: date
3331

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

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

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

            
3338
Create values clause.
3339

            
3340
    (title, author) values (title = :title, age = :age);
3341

            
3342
You can use this in insert statement.
3343

            
3344
    my $insert_sql = "insert into book $values_clause";
3345

            
3346
=head2 C<where>
3347

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

            
3353
Create a new L<DBIx::Custom::Where> object.
3354

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

            
3357
=head2 C<DBIX_CUSTOM_DEBUG>
3358

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

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

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

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

            
3368
L<DBIx::Custom>
3369

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

            
3415
L<DBIx::Custom::Model>
3416

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

            
3423
L<DBIx::Custom::Query>
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
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3427
    table # will be removed at 2017/1/1
3428
    filters # will be removed at 2017/1/1
3429
    
3430
    # Methods
3431
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3432

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

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

            
3458
L<DBIx::Custom::Tag>
3459

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

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

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

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

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

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

            
3477
C<< <kimoto.yuki at gmail.com> >>
3478

            
3479
L<http://github.com/yuki-kimoto/DBIx-Custom>
3480

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3481
=head1 AUTHOR
3482

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

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

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

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

            
3492
=cut