DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3564 lines | 92.653kb
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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
4
our $VERSION = '0.1721';
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/;
improved debug message
Yuki Kimoto authored on 2011-05-23
17
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
18
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
19

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

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
120
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
121
    my ($self, $param) = @_;
122
    
123
    # Create set tag
124
    my @params;
125
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
126
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
127
        croak qq{"$column" is not safety column name } . _subname
128
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
129
        my $column_quote = $self->_q($column);
130
        $column_quote =~ s/\./$self->_q(".")/e;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
131
        push @params, ref $param->{$column} eq 'SCALAR'
132
          ? "$column_quote = " . ${$param->{$column}}
133
          : "$column_quote = :$column";
134

            
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
135
    }
136
    my $tag = join(', ', @params);
137
    
138
    return $tag;
139
}
140

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
228
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
229
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
230

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
231
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
232
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
233
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
234
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
235
    my $where            = delete $args{where} || {};
236
    my $append           = delete $args{append};
237
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
238
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
239
    my $id = delete $args{id};
240
    my $primary_key = delete $args{primary_key};
241
    croak "update method primary_key option " .
242
          "must be specified when id is specified " . _subname
243
      if defined $id && !defined $primary_key;
244
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
245
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
246
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
247
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
248
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
249
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
250
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
251
        $where_clause = "where " . $where->[0];
252
        $where_param = $where->[1];
253
    }
254
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
255
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
256
        $where_param = keys %$where_param
257
                     ? $self->merge_param($where_param, $where->param)
258
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
259
        
260
        # String where
261
        $where_clause = $where->to_string;
262
    }
263
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
264
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
265
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
266

            
cleanup
Yuki Kimoto authored on 2011-04-02
267
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
268
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
269
    push @sql, "delete";
270
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
271
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
272
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
273
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
274
    
275
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
276
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
277
}
278

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
283
sub create_model {
284
    my $self = shift;
285
    
cleanup
Yuki Kimoto authored on 2011-04-02
286
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
287
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
288
    $args->{dbi} = $self;
289
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
290
    my $model_name  = delete $args->{name};
291
    my $model_table = delete $args->{table};
292
    $model_name ||= $model_table;
293
    
cleanup
Yuki Kimoto authored on 2011-04-02
294
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
295
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
296
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
297
    $model->name($model_name) unless $model->name;
298
    $model->table($model_table) unless $model->table;
299
    
micro optimization
Yuki Kimoto authored on 2011-07-30
300
    # Apply filter(DEPRECATED logic)
301
    if ($model->{filter}) {
302
        my $filter = ref $model->filter eq 'HASH'
303
                   ? [%{$model->filter}]
304
                   : $model->filter;
305
        $filter ||= [];
306
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
307
          if @$filter;
308
        $self->_apply_filter($model->table, @$filter);
309
    }
310
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
311
    # Set model
312
    $self->model($model->name, $model);
313
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
314
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
315
}
316

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
320
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
321
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
322
    if ($user_column_info) {
323
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
324
    }
325
    else {
326
    
327
        my $re = $self->exclude_table || $options{exclude_table};
328
        # Tables
329
        my %tables;
330
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
331

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
332
        # Iterate all tables
333
        my @tables = sort keys %tables;
334
        for (my $i = 0; $i < @tables; $i++) {
335
            my $table = $tables[$i];
336
            
337
            # Iterate all columns
338
            my $sth_columns;
339
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
340
            next if $@;
341
            while (my $column_info = $sth_columns->fetchrow_hashref) {
342
                my $column = $column_info->{COLUMN_NAME};
343
                $self->$cb($table, $column, $column_info);
344
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
345
        }
346
    }
347
}
348

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
349
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
350
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
351
    
cleanup test
Yuki Kimoto authored on 2011-08-16
352
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
353
    
added test
Yuki Kimoto authored on 2011-08-16
354
    # Iterate tables
355
    if ($user_table_infos) {
356
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
357
    }
358
    else {
359
        my $re = $self->exclude_table || $option{exclude};
360
        my $sth_tables = $self->dbh->table_info;
361
        while (my $table_info = $sth_tables->fetchrow_hashref) {
362
            
363
            # Table
364
            my $table = $table_info->{TABLE_NAME};
365
            next if defined $re && $table =~ /$re/;
366
            $self->$cb($table, $table_info);
367
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
368
    }
369
}
370

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
371
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
372
  allow_update_all bind_type column filter id join param prefix primary_key
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
373
  query relation sqlfilter table table_alias type type_rule_off type_rule1_off
simplified arguments check
Yuki Kimoto authored on 2011-07-11
374
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
375

            
376
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
377
    my $self = shift;
378
    my $query = shift;
379
    my $param;
380
    $param = shift if @_ % 2;
381
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
382
    
cleanup
Yuki Kimoto authored on 2011-04-02
383
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
384
    my $p = delete $args{param} || {};
385
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
386
    my $tables = delete $args{table} || [];
387
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
388
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
389
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
390
    my $bind_type = delete $args{bind_type} || delete $args{type};
391
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
392
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
393
    my $type_rule_off_parts = {
394
        1 => delete $args{type_rule1_off},
395
        2 => delete $args{type_rule2_off}
396
    };
cleanup
Yuki Kimoto authored on 2011-06-09
397
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
398
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
399
    my $sqlfilter = $args{sqlfilter};
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
400
    my $id = delete $args{id};
401
    my $primary_key = delete $args{primary_key};
402
    croak "insert method primary_key option " .
403
          "must be specified when id is specified " . _subname
404
      if defined $id && !defined $primary_key;
405
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
406

            
407
    if (defined $id) {
408
        my $id_param = $self->_create_param_from_id($id, $primary_key);
409
        $param = $self->merge_param($id_param, $param);
410
    }
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
411
    
cleanup
Yuki Kimoto authored on 2011-03-09
412
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
413
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
414
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
415
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
416
    }
417
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
418
    $query = $self->_create_query($query, $sqlfilter) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
419
    
420
    # Save query
421
    $self->last_sql($query->sql);
422

            
cleanup
Yuki Kimoto authored on 2011-06-09
423
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
424
    
425
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
426
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
427
    
cleanup
Yuki Kimoto authored on 2011-04-02
428
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
429
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
430
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
431
    
micro optimization
Yuki Kimoto authored on 2011-07-30
432
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
433
    $tables = $self->_remove_duplicate_table($tables, $main_table)
434
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
435
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
436
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
437
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
438
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
439
        foreach my $i (1, 2) {
440
            unless ($type_rule_off_parts->{$i}) {
441
                $type_filters->{$i} = {};
442
                foreach my $alias (keys %$table_alias) {
443
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
444
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
445
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
446
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
447
                    }
448
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
449
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
450
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
451
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
452
        }
453
    }
cleanup
Yuki Kimoto authored on 2011-04-02
454
    
micro optimization
Yuki Kimoto authored on 2011-07-30
455
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
456
    if ($self->{filter}{on}) {
457
        my $applied_filter = {};
458
        foreach my $table (@$tables) {
459
            $applied_filter = {
460
                %$applied_filter,
461
                %{$self->{filter}{out}->{$table} || {}}
462
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
463
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
464
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
465
    }
466
    
cleanup
Yuki Kimoto authored on 2011-04-02
467
    # Replace filter name to code
468
    foreach my $column (keys %$filter) {
469
        my $name = $filter->{$column};
470
        if (!defined $name) {
471
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
472
        }
cleanup
Yuki Kimoto authored on 2011-04-02
473
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
474
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
475
            unless exists $self->filters->{$name};
476
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
477
        }
478
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
479
    
cleanup
Yuki Kimoto authored on 2011-04-02
480
    # Create bind values
481
    my $bind = $self->_create_bind_values(
482
        $param,
483
        $query->columns,
484
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
485
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
486
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
487
    );
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
488

            
cleanup
yuki-kimoto authored on 2010-10-17
489
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
490
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
491
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
492
    eval {
493
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
494
            my $bind_type = $bind->[$i]->{bind_type};
495
            $sth->bind_param(
496
                $i + 1,
497
                $bind->[$i]->{value},
498
                $bind_type ? $bind_type : ()
499
            );
cleanup
Yuki Kimoto authored on 2011-03-21
500
        }
501
        $affected = $sth->execute;
502
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
503
    
micro optimization
Yuki Kimoto authored on 2011-07-30
504
    $self->_croak($@, qq{. Following SQL is executed.\n}
505
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
506
    
improved debug message
Yuki Kimoto authored on 2011-05-23
507
    # DEBUG message
508
    if (DEBUG) {
509
        print STDERR "SQL:\n" . $query->sql . "\n";
510
        my @output;
511
        foreach my $b (@$bind) {
512
            my $value = $b->{value};
513
            $value = 'undef' unless defined $value;
514
            $value = encode(DEBUG_ENCODING(), $value)
515
              if utf8::is_utf8($value);
516
            push @output, $value;
517
        }
518
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
519
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
520
    
cleanup
Yuki Kimoto authored on 2011-04-02
521
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
522
    if ($sth->{NUM_OF_FIELDS}) {
523
        
micro optimization
Yuki Kimoto authored on 2011-07-30
524
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
525
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
526
        if ($self->{filter}{on}) {
527
            $filter->{in}  = {};
528
            $filter->{end} = {};
529
            push @$tables, $main_table if $main_table;
530
            foreach my $table (@$tables) {
531
                foreach my $way (qw/in end/) {
532
                    $filter->{$way} = {
533
                        %{$filter->{$way}},
534
                        %{$self->{filter}{$way}{$table} || {}}
535
                    };
536
                }
cleanup
Yuki Kimoto authored on 2011-04-02
537
            }
cleanup
Yuki Kimoto authored on 2011-01-12
538
        }
539
        
540
        # Result
541
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
542
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
543
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
544
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
545
            filter => $filter->{in} || {},
546
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
547
            type_rule => {
548
                from1 => $self->type_rule->{from1},
549
                from2 => $self->type_rule->{from2}
550
            },
cleanup
yuki-kimoto authored on 2010-10-17
551
        );
552

            
553
        return $result;
554
    }
cleanup
Yuki Kimoto authored on 2011-04-02
555
    
556
    # Not select statement
557
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
558
}
559

            
added test
Yuki Kimoto authored on 2011-08-16
560
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
561
    my ($self, %args) = @_;
562
    
563
    my $exclude = delete $args{exclude};
564
    croak qq/"$_" is wrong option/ for keys %args;
565
    
added test
Yuki Kimoto authored on 2011-08-16
566
    my $table_info = [];
567
    $self->each_table(
568
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
569
        exclude => $exclude
570
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
571
    
cleanup test
Yuki Kimoto authored on 2011-08-16
572
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
573
}
574

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
575
sub get_column_info {
576
    my ($self, %args) = @_;
577
    
578
    my $exclude_table = delete $args{exclude_table};
579
    croak qq/"$_" is wrong option/ for keys %args;
580
    
581
    my $column_info = [];
582
    $self->each_column(
583
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
584
        exclude_table => $exclude_table
585
    );
586
    
587
    return [
588
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
589
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
590
}
591

            
cleanup
yuki-kimoto authored on 2010-10-17
592
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
593
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
594
    
cleanup
yuki-kimoto authored on 2010-10-17
595
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
596
    my $param;
597
    $param = shift if @_ % 2;
598
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
599
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
600
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
601
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
602
    my $p = delete $args{param} || {};
603
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
604
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
605
    my $id = delete $args{id};
606
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
607
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
608
          "must be specified when id is specified " . _subname
609
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
610
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
611
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
612

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
613
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
614
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
615
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
616
        $param = $self->merge_param($id_param, $param);
617
    }
618

            
cleanup
Yuki Kimoto authored on 2011-04-02
619
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
620
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
621
    push @sql, "insert";
622
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
623
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
624
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
625
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
626
    
627
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
628
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
629
}
630

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
631
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
632
    my ($self, $param) = @_;
633
    
cleanup
Yuki Kimoto authored on 2011-04-02
634
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
635
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
636
    my @columns;
637
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
638
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
639
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
640
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
641
        my $column_quote = $self->_q($column);
642
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
643
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
644
        push @placeholders, ref $param->{$column} eq 'SCALAR'
645
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
646
    }
647
    
cleanup
Yuki Kimoto authored on 2011-04-02
648
    return '(' . join(', ', @columns) . ') ' . 'values ' .
649
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
650
}
651

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
652
sub include_model {
653
    my ($self, $name_space, $model_infos) = @_;
654
    
cleanup
Yuki Kimoto authored on 2011-04-02
655
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
656
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
657
    
658
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
659
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
660

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
661
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
662
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
663
          if $name_space =~ /[^\w:]/;
664
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
665
        croak qq{Name space module "$name_space.pm" is needed. $@ }
666
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
667
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
668
        
669
        # Search model modules
670
        my $path = $INC{"$name_space.pm"};
671
        $path =~ s/\.pm$//;
672
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
673
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
674
        $model_infos = [];
675
        while (my $module = readdir $dh) {
676
            push @$model_infos, $module
677
              if $module =~ s/\.pm$//;
678
        }
679
        close $dh;
680
    }
681
    
cleanup
Yuki Kimoto authored on 2011-04-02
682
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
683
    foreach my $model_info (@$model_infos) {
684
        
cleanup
Yuki Kimoto authored on 2011-04-02
685
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
686
        my $model_class;
687
        my $model_name;
688
        my $model_table;
689
        if (ref $model_info eq 'HASH') {
690
            $model_class = $model_info->{class};
691
            $model_name  = $model_info->{name};
692
            $model_table = $model_info->{table};
693
            
694
            $model_name  ||= $model_class;
695
            $model_table ||= $model_name;
696
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
697
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
698
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
699
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
700
          if $mclass =~ /[^\w:]/;
701
        unless ($mclass->can('isa')) {
702
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
703
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
704
        }
705
        
cleanup
Yuki Kimoto authored on 2011-04-02
706
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
707
        my $args = {};
708
        $args->{model_class} = $mclass if $mclass;
709
        $args->{name}        = $model_name if $model_name;
710
        $args->{table}       = $model_table if $model_table;
711
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
712
    }
713
    
714
    return $self;
715
}
716

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
717
sub mapper {
718
    my $self = shift;
719
    return DBIx::Custom::Mapper->new(@_);
720
}
721

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
722
sub map_param {
723
    my $self = shift;
724
    my $param = shift;
725
    my %map = @_;
726
    
727
    # Mapping
728
    my $map_param = {};
729
    foreach my $key (keys %map) {
730
        my $value_cb;
731
        my $condition;
732
        my $map_key;
733
        
734
        # Get mapping information
735
        if (ref $map{$key} eq 'ARRAY') {
736
            foreach my $some (@{$map{$key}}) {
737
                $map_key = $some unless ref $some;
738
                $condition = $some->{if} if ref $some eq 'HASH';
739
                $value_cb = $some if ref $some eq 'CODE';
740
            }
741
        }
742
        else {
743
            $map_key = $map{$key};
744
        }
745
        $value_cb ||= sub { $_[0] };
746
        $condition ||= sub { defined $_[0] && length $_[0] };
747

            
748
        # Map parameter
749
        my $value;
750
        if (ref $condition eq 'CODE') {
751
            $map_param->{$map_key} = $value_cb->($param->{$key})
752
              if $condition->($param->{$key});
753
        }
754
        elsif ($condition eq 'exists') {
755
            $map_param->{$map_key} = $value_cb->($param->{$key})
756
              if exists $param->{$key};
757
        }
758
        else { croak qq/Condition must be code reference or "exists" / . _subname }
759
    }
760
    
761
    return $map_param;
762
}
763

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
764
sub merge_param {
765
    my ($self, @params) = @_;
766
    
cleanup
Yuki Kimoto authored on 2011-04-02
767
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
768
    my $merge = {};
769
    foreach my $param (@params) {
770
        foreach my $column (keys %$param) {
771
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
772
            
773
            if (exists $merge->{$column}) {
774
                $merge->{$column} = [$merge->{$column}]
775
                  unless ref $merge->{$column} eq 'ARRAY';
776
                push @{$merge->{$column}},
777
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
778
            }
779
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
780
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
781
            }
782
        }
783
    }
784
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
785
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
786
}
787

            
cleanup
Yuki Kimoto authored on 2011-03-21
788
sub method {
789
    my $self = shift;
790
    
cleanup
Yuki Kimoto authored on 2011-04-02
791
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
792
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
793
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
794
    
795
    return $self;
796
}
797

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
798
sub model {
799
    my ($self, $name, $model) = @_;
800
    
cleanup
Yuki Kimoto authored on 2011-04-02
801
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
802
    if ($model) {
803
        $self->models->{$name} = $model;
804
        return $self;
805
    }
806
    
807
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
808
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
809
      unless $self->models->{$name};
810
    
cleanup
Yuki Kimoto authored on 2011-04-02
811
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
812
    return $self->models->{$name};
813
}
814

            
cleanup
Yuki Kimoto authored on 2011-03-21
815
sub mycolumn {
816
    my ($self, $table, $columns) = @_;
817
    
cleanup
Yuki Kimoto authored on 2011-04-02
818
    # Create column clause
819
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
820
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
821
    push @column, $self->_q($table) . "." . $self->_q($_) .
822
      " as " . $self->_q($_)
823
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
824
    
825
    return join (', ', @column);
826
}
827

            
added dbi_options attribute
kimoto authored on 2010-12-20
828
sub new {
829
    my $self = shift->SUPER::new(@_);
830
    
cleanup
Yuki Kimoto authored on 2011-04-02
831
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
832
    my @attrs = keys %$self;
833
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
834
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
835
          unless $self->can($attr);
836
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
837

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
838
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
839
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
840
        '?'     => \&DBIx::Custom::Tag::placeholder,
841
        '='     => \&DBIx::Custom::Tag::equal,
842
        '<>'    => \&DBIx::Custom::Tag::not_equal,
843
        '>'     => \&DBIx::Custom::Tag::greater_than,
844
        '<'     => \&DBIx::Custom::Tag::lower_than,
845
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
846
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
847
        'like'  => \&DBIx::Custom::Tag::like,
848
        'in'    => \&DBIx::Custom::Tag::in,
849
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
850
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
851
    };
852
    
853
    return $self;
854
}
855

            
856
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
857
sub not_exists { $not_exists }
858

            
859
sub order {
860
    my $self = shift;
861
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
862
}
863

            
cleanup
yuki-kimoto authored on 2010-10-17
864
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
865
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
866
    
867
    # Register filter
868
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
869
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
870
    
cleanup
Yuki Kimoto authored on 2011-04-02
871
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
872
}
packaging one directory
yuki-kimoto authored on 2009-11-16
873

            
874
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
875
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
876

            
refactoring select
yuki-kimoto authored on 2010-04-28
877
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
878
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
879
    my $tables = ref $table eq 'ARRAY' ? $table
880
               : defined $table ? [$table]
881
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
882
    my $columns   = delete $args{column};
883
    my $where     = delete $args{where} || {};
884
    my $append    = delete $args{append};
885
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
886
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
887
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
888
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
889
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
890
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
891
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
892
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
893
      if keys %$param;
894
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
895
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
896
    my $id = delete $args{id};
897
    my $primary_key = delete $args{primary_key};
898
    croak "update method primary_key option " .
899
          "must be specified when id is specified " . _subname
900
      if defined $id && !defined $primary_key;
901
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
902
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
903
    
cleanup
Yuki Kimoto authored on 2011-03-09
904
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
905
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
906
    
cleanup
Yuki Kimoto authored on 2011-04-02
907
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
908
    my @sql;
909
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
910
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
911
    # Prefix
912
    push @sql, $prefix if defined $prefix;
913
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
914
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
915
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
916
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
917
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
918
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
919
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
920
            }
921
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
922
                if (@$column == 3 && $column->[1] eq 'as') {
923
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
924
                    splice @$column, 1, 1;
925
                }
926
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
927
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
928
            }
cleanup
Yuki Kimoto authored on 2011-04-02
929
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
930
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
931
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
932
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
933
    }
934
    else { push @sql, '*' }
935
    
936
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
937
    push @sql, 'from';
938
    if ($relation) {
939
        my $found = {};
940
        foreach my $table (@$tables) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
941
            push @sql, ($self->_q($table), ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
942
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
943
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
944
    }
cleanup
Yuki Kimoto authored on 2011-03-30
945
    else {
946
        my $main_table = $tables->[-1] || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
947
        push @sql, $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
948
    }
949
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
950
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
951
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
952

            
cleanup
Yuki Kimoto authored on 2011-04-02
953
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
954
    unshift @$tables,
955
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
956
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
957
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
958
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
959
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
960
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
961
        $where_clause = "where " . $where->[0];
962
        $where_param = $where->[1];
963
    }
964
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
965
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
966
        $where_param = keys %$where_param
967
                     ? $self->merge_param($where_param, $where->param)
968
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
969
        
970
        # String where
971
        $where_clause = $where->to_string;
972
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
973
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
974
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
975
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
976
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
977
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
978
    # Push join
979
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
980
    
cleanup
Yuki Kimoto authored on 2011-03-09
981
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
982
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
983
    
cleanup
Yuki Kimoto authored on 2011-03-08
984
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
985
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
986
    
cleanup
Yuki Kimoto authored on 2011-04-02
987
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
988
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
989
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
990
    # Wrap
991
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
992
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
993
          unless ref $wrap eq 'ARRAY';
994
        unshift @sql, $wrap->[0];
995
        push @sql, $wrap->[1];
996
    }
997
    
cleanup
Yuki Kimoto authored on 2011-01-27
998
    # SQL
999
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
1000
    
1001
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1002
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
1003
    
1004
    return $result;
1005
}
1006

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1007
sub setup_model {
1008
    my $self = shift;
1009
    
cleanup
Yuki Kimoto authored on 2011-04-02
1010
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1011
    $self->each_column(
1012
        sub {
1013
            my ($self, $table, $column, $column_info) = @_;
1014
            if (my $model = $self->models->{$table}) {
1015
                push @{$model->columns}, $column;
1016
            }
1017
        }
1018
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1019
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1020
}
1021

            
update pod
Yuki Kimoto authored on 2011-08-10
1022
sub show_datatype {
1023
    my ($self, $table) = @_;
1024
    croak "Table name must be specified" unless defined $table;
1025
    print "$table\n";
1026
    
1027
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1028
    my $sth = $result->sth;
1029

            
1030
    my $columns = $sth->{NAME};
1031
    my $data_types = $sth->{TYPE};
1032
    
1033
    for (my $i = 0; $i < @$columns; $i++) {
1034
        my $column = $columns->[$i];
1035
        my $data_type = $data_types->[$i];
1036
        print "$column: $data_type\n";
1037
    }
1038
}
1039

            
1040
sub show_typename {
1041
    my ($self, $t) = @_;
1042
    croak "Table name must be specified" unless defined $t;
1043
    print "$t\n";
1044
    
1045
    $self->each_column(sub {
1046
        my ($self, $table, $column, $infos) = @_;
1047
        return unless $table eq $t;
1048
        my $typename = $infos->{TYPE_NAME};
1049
        print "$column: $typename\n";
1050
    });
1051
    
1052
    return $self;
1053
}
1054

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1055
sub show_tables {
1056
    my $self = shift;
1057
    
1058
    my %tables;
1059
    $self->each_table(sub { $tables{$_[1]}++ });
1060
    print join("\n", sort keys %tables) . "\n";
1061
    return $self;
1062
}
1063

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1064
sub type_rule {
1065
    my $self = shift;
1066
    
1067
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1068
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1069
        
1070
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1071
        foreach my $i (1 .. 2) {
1072
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1073
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1074
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1075
            $self->{type_rule} = $type_rule;
1076
            $self->{"_$into"} = {};
1077
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1078
                croak qq{type name of $into section must be lower case}
1079
                  if $type_name =~ /[A-Z]/;
1080
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1081
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1082
            $self->each_column(sub {
1083
                my ($dbi, $table, $column, $column_info) = @_;
1084
                
1085
                my $type_name = lc $column_info->{TYPE_NAME};
1086
                if ($type_rule->{$into} &&
1087
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1088
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1089
                    return unless exists $type_rule->{$into}->{$type_name};
1090
                    if  (defined $filter && ref $filter ne 'CODE') 
1091
                    {
1092
                        my $fname = $filter;
1093
                        croak qq{Filter "$fname" is not registered" } . _subname
1094
                          unless exists $self->filters->{$fname};
1095
                        
1096
                        $filter = $self->filters->{$fname};
1097
                    }
1098

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1099
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1100
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1101
                }
1102
            });
1103
        }
1104

            
1105
        # From
1106
        foreach my $i (1 .. 2) {
1107
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1108
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1109
                croak qq{data type of from$i section must be lower case or number}
1110
                  if $data_type =~ /[A-Z]/;
1111
                my $fname = $type_rule->{"from$i"}{$data_type};
1112
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1113
                    croak qq{Filter "$fname" is not registered" } . _subname
1114
                      unless exists $self->filters->{$fname};
1115
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1116
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1117
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1118
            }
1119
        }
1120
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1121
        return $self;
1122
    }
1123
    
1124
    return $self->{type_rule} || {};
1125
}
1126

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1130
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1131
    my $param;
1132
    $param = shift if @_ % 2;
1133
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1134
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1135
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1136
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1137
    my $p = delete $args{param} || {};
1138
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1139
    my $where = delete $args{where} || {};
1140
    my $where_param = delete $args{where_param} || {};
1141
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1142
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1143
    my $id = delete $args{id};
1144
    my $primary_key = delete $args{primary_key};
1145
    croak "update method primary_key option " .
1146
          "must be specified when id is specified " . _subname
1147
      if defined $id && !defined $primary_key;
1148
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1149
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1150

            
cleanup
yuki-kimoto authored on 2010-10-17
1151
    # Update clause
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1152
    my $update_clause = $self->update_param($param);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1153

            
1154
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1155
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1156
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1157
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1158
        $where_clause = "where " . $where->[0];
1159
        $where_param = $where->[1];
1160
    }
1161
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1162
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1163
        $where_param = keys %$where_param
1164
                     ? $self->merge_param($where_param, $where->param)
1165
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1166
        
1167
        # String where
1168
        $where_clause = $where->to_string;
1169
    }
1170
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1171
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1172
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1173
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1174
    # Merge param
1175
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1176
    
cleanup
Yuki Kimoto authored on 2011-04-02
1177
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1178
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1179
    push @sql, "update";
1180
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1181
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1182
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1183
    
cleanup
Yuki Kimoto authored on 2011-01-27
1184
    # SQL
1185
    my $sql = join(' ', @sql);
1186
    
cleanup
yuki-kimoto authored on 2010-10-17
1187
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1188
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1189
}
1190

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1193
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1194
    my ($self, $param, $opt) = @_;
1195
    
cleanup
Yuki Kimoto authored on 2011-04-02
1196
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1197
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1198
    $tag = "set $tag" unless $opt->{no_set};
1199

            
cleanup
Yuki Kimoto authored on 2011-04-02
1200
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1201
}
1202

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1205
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1206
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1207
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1208
    
updated pod
Yuki Kimoto authored on 2011-06-21
1209
    # Cache
1210
    my $cache = $self->cache;
1211
    
1212
    # Query
1213
    my $query;
1214
    
1215
    # Get cached query
1216
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1217
        
updated pod
Yuki Kimoto authored on 2011-06-21
1218
        # Get query
1219
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1220
        
updated pod
Yuki Kimoto authored on 2011-06-21
1221
        # Create query
1222
        if ($q) {
1223
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1224
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1225
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1226
    }
1227
    
1228
    # Create query
1229
    unless ($query) {
1230

            
1231
        # Create query
1232
        my $builder = $self->query_builder;
1233
        $query = $builder->build_query($source);
1234

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

            
1241
        # Save query to cache
1242
        $self->cache_method->(
1243
            $self, $source,
1244
            {
1245
                sql     => $query->sql, 
1246
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1247
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1248
            }
1249
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1250
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1251

            
1252
    # Filter SQL
1253
    if ($sqlfilter) {
1254
        my $sql = $query->sql;
1255
        $sql = $sqlfilter->($sql);
1256
        $query->sql($sql);
1257
    }
1258
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1259
    # Save sql
1260
    $self->last_sql($query->sql);
1261
    
updated pod
Yuki Kimoto authored on 2011-06-21
1262
    # Prepare statement handle
1263
    my $sth;
1264
    eval { $sth = $self->dbh->prepare($query->{sql})};
1265
    
1266
    if ($@) {
1267
        $self->_croak($@, qq{. Following SQL is executed.\n}
1268
                        . qq{$query->{sql}\n} . _subname);
1269
    }
1270
    
1271
    # Set statement handle
1272
    $query->sth($sth);
1273
    
1274
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1275
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1276
    
1277
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1278
}
1279

            
cleanup
Yuki Kimoto authored on 2011-04-02
1280
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1281
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1282
    
cleanup
Yuki Kimoto authored on 2011-04-02
1283
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1284
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1285
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1286
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1287
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1288
        
1289
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1290
        my $value;
1291
        if(ref $params->{$column} eq 'ARRAY') {
1292
            my $i = $count->{$column} || 0;
1293
            $i += $not_exists->{$column} || 0;
1294
            my $found;
1295
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1296
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1297
                    $not_exists->{$column}++;
1298
                }
1299
                else  {
1300
                    $value = $params->{$column}->[$k];
1301
                    $found = 1;
1302
                    last
1303
                }
1304
            }
1305
            next unless $found;
1306
        }
1307
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1308
        
cleanup
Yuki Kimoto authored on 2011-01-12
1309
        # Filter
1310
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1311
        $value = $f->($value) if $f;
1312
        
1313
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1314
        foreach my $i (1 .. 2) {
1315
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1316
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1317
            $value = $tf->($value) if $tf;
1318
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1319
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1320
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1321
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1322
        
1323
        # Count up 
1324
        $count->{$column}++;
1325
    }
1326
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1327
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1328
}
1329

            
cleanup
Yuki Kimoto authored on 2011-06-08
1330
sub _create_param_from_id {
1331
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1332
    
cleanup
Yuki Kimoto authored on 2011-06-08
1333
    # Create parameter
1334
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1335
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1336
        $id = [$id] unless ref $id;
1337
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1338
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1339
          unless !ref $id || ref $id eq 'ARRAY';
1340
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1341
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1342
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1343
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1344
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1345
        }
1346
    }
1347
    
cleanup
Yuki Kimoto authored on 2011-06-08
1348
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1349
}
1350

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1351
sub _connect {
1352
    my $self = shift;
1353
    
1354
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1355
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1356
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1357
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1358
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1359
    croak qq{"dsn" must be specified } . _subname
1360
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1361
    my $user        = $self->user;
1362
    my $password    = $self->password;
1363
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1364
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1365
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1366
    
cleanup
Yuki Kimoto authored on 2011-08-16
1367
    $dbi_option = {%{$self->default_dbi_option}, %$dbi_option};
1368
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1369
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1370
    my $dbh;
1371
    eval {
1372
        $dbh = DBI->connect(
1373
            $dsn,
1374
            $user,
1375
            $password,
1376
            $dbi_option
1377
        );
1378
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1379
    
1380
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1381
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1382
    
1383
    return $dbh;
1384
}
1385

            
cleanup
yuki-kimoto authored on 2010-10-17
1386
sub _croak {
1387
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1388
    
1389
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1390
    $append ||= "";
1391
    
1392
    # Verbose
1393
    if ($Carp::Verbose) { croak $error }
1394
    
1395
    # Not verbose
1396
    else {
1397
        
1398
        # Remove line and module infromation
1399
        my $at_pos = rindex($error, ' at ');
1400
        $error = substr($error, 0, $at_pos);
1401
        $error =~ s/\s+$//;
1402
        croak "$error$append";
1403
    }
1404
}
1405

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1408
sub _need_tables {
1409
    my ($self, $tree, $need_tables, $tables) = @_;
1410
    
cleanup
Yuki Kimoto authored on 2011-04-02
1411
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1412
    foreach my $table (@$tables) {
1413
        if ($tree->{$table}) {
1414
            $need_tables->{$table} = 1;
1415
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1416
        }
1417
    }
1418
}
1419

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1420
sub _push_join {
1421
    my ($self, $sql, $join, $join_tables) = @_;
1422
    
cleanup
Yuki Kimoto authored on 2011-04-02
1423
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1424
    return unless @$join;
1425
    
cleanup
Yuki Kimoto authored on 2011-04-02
1426
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1427
    my $tree = {};
1428
    for (my $i = 0; $i < @$join; $i++) {
1429
        
cleanup
Yuki Kimoto authored on 2011-07-28
1430
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1431
        my $join_clause;;
1432
        my $option;
1433
        if (ref $join->[$i] eq 'HASH') {
1434
            $join_clause = $join->[$i]->{clause};
1435
            $option = {table => $join->[$i]->{table}};
1436
        }
1437
        else {
1438
            $join_clause = $join->[$i];
1439
            $option = {};
1440
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1441

            
1442
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1443
        my $table1;
1444
        my $table2;
1445
        if (my $table = $option->{table}) {
1446
            $table1 = $table->[0];
1447
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1448
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1449
        else {
1450
            my $q = $self->_quote;
1451
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1452
            $j_clause =~ s/'.+?'//g;
1453
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1454
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1455
            my $c = $self->safety_character;
1456
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1457
            if ($j_clause =~ $join_re) {
1458
                $table1 = $1;
1459
                $table2 = $2;
1460
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1461
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1462
        croak qq{join clause must have two table name after "on" keyword. } .
1463
              qq{"$join_clause" is passed }  . _subname
1464
          unless defined $table1 && defined $table2;
1465
        croak qq{right side table of "$join_clause" must be unique }
1466
            . _subname
1467
          if exists $tree->{$table2};
1468
        croak qq{Same table "$table1" is specified} . _subname
1469
          if $table1 eq $table2;
1470
        $tree->{$table2}
1471
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1472
    }
1473
    
cleanup
Yuki Kimoto authored on 2011-04-02
1474
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1475
    my $need_tables = {};
1476
    $self->_need_tables($tree, $need_tables, $join_tables);
1477
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1478
    
1479
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1480
    foreach my $need_table (@need_tables) {
1481
        push @$sql, $tree->{$need_table}{join};
1482
    }
1483
}
cleanup
Yuki Kimoto authored on 2011-03-08
1484

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1485
sub _quote {
1486
    my $self = shift;
1487
    
1488
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1489
         : defined $self->quote ? $self->quote
1490
         : '';
1491
}
1492

            
cleanup
Yuki Kimoto authored on 2011-07-29
1493
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1494
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1495
    
1496
    my $quote = $self->_quote;
1497
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1498
    my $p;
1499
    if (defined $quote && length $quote > 1) {
1500
        $p = substr($quote, 1, 1);
1501
    }
1502
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1503
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1504
    if ($quotemeta) {
1505
        $q = quotemeta($q);
1506
        $p = quotemeta($p);
1507
    }
1508
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1509
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1510
}
1511

            
cleanup
Yuki Kimoto authored on 2011-04-02
1512
sub _remove_duplicate_table {
1513
    my ($self, $tables, $main_table) = @_;
1514
    
1515
    # Remove duplicate table
1516
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1517
    delete $tables{$main_table} if $main_table;
1518
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1519
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1520
    if (my $q = $self->_quote) {
1521
        $q = quotemeta($q);
1522
        $_ =~ s/[$q]//g for @$new_tables;
1523
    }
1524

            
1525
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1526
}
1527

            
cleanup
Yuki Kimoto authored on 2011-04-02
1528
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1529
    my ($self, $source) = @_;
1530
    
cleanup
Yuki Kimoto authored on 2011-04-02
1531
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1532
    my $tables = [];
1533
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1534
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1535
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1536
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1537
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1538
    while ($source =~ /$table_re/g) {
1539
        push @$tables, $1;
1540
    }
1541
    
1542
    return $tables;
1543
}
1544

            
cleanup
Yuki Kimoto authored on 2011-04-02
1545
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1546
    my ($self, $where) = @_;
1547
    
cleanup
Yuki Kimoto authored on 2011-04-02
1548
    my $obj;
1549
    
1550
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1551
    if (ref $where eq 'HASH') {
1552
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1553
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1554
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1555
            my $table;
1556
            my $c;
1557
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1558
                $table = $1;
1559
                $c = $2;
1560
            }
1561
            
1562
            my $table_quote;
1563
            $table_quote = $self->_q($table) if defined $table;
1564
            my $column_quote = $self->_q($c);
1565
            $column_quote = $table_quote . '.' . $column_quote
1566
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1567
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1568
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1569
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1570
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1571
    
1572
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1573
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1574
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1575
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1576
    
updated pod
Yuki Kimoto authored on 2011-06-21
1577
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1578
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1579
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1580
            clause => $where->[0],
1581
            param  => $where->[1]
1582
        );
1583
    }
1584
    
cleanup
Yuki Kimoto authored on 2011-04-02
1585
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1586
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1587
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1588
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1589
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1590
    
cleanup
Yuki Kimoto authored on 2011-04-02
1591
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1592
}
1593

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

            
1597
    # Initialize filters
1598
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1599
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1600
    $self->{filter}{out} ||= {};
1601
    $self->{filter}{in} ||= {};
1602
    $self->{filter}{end} ||= {};
1603
    
1604
    # Usage
1605
    my $usage = "Usage: \$dbi->apply_filter(" .
1606
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1607
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1608
    
1609
    # Apply filter
1610
    for (my $i = 0; $i < @cinfos; $i += 2) {
1611
        
1612
        # Column
1613
        my $column = $cinfos[$i];
1614
        if (ref $column eq 'ARRAY') {
1615
            foreach my $c (@$column) {
1616
                push @cinfos, $c, $cinfos[$i + 1];
1617
            }
1618
            next;
1619
        }
1620
        
1621
        # Filter infomation
1622
        my $finfo = $cinfos[$i + 1] || {};
1623
        croak "$usage (table: $table) " . _subname
1624
          unless  ref $finfo eq 'HASH';
1625
        foreach my $ftype (keys %$finfo) {
1626
            croak "$usage (table: $table) " . _subname
1627
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1628
        }
1629
        
1630
        # Set filters
1631
        foreach my $way (qw/in out end/) {
1632
        
1633
            # Filter
1634
            my $filter = $finfo->{$way};
1635
            
1636
            # Filter state
1637
            my $state = !exists $finfo->{$way} ? 'not_exists'
1638
                      : !defined $filter        ? 'not_defined'
1639
                      : ref $filter eq 'CODE'   ? 'code'
1640
                      : 'name';
1641
            
1642
            # Filter is not exists
1643
            next if $state eq 'not_exists';
1644
            
1645
            # Check filter name
1646
            croak qq{Filter "$filter" is not registered } . _subname
1647
              if  $state eq 'name'
1648
               && ! exists $self->filters->{$filter};
1649
            
1650
            # Set filter
1651
            my $f = $state eq 'not_defined' ? undef
1652
                  : $state eq 'code'        ? $filter
1653
                  : $self->filters->{$filter};
1654
            $self->{filter}{$way}{$table}{$column} = $f;
1655
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1656
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1657
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1658
        }
1659
    }
1660
    
1661
    return $self;
1662
}
1663

            
1664
# DEPRECATED!
1665
sub create_query {
1666
    warn "create_query is DEPRECATED! use query option of each method";
1667
    shift->_create_query(@_);
1668
}
1669

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1678
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1679
our %SELECT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1680
sub select_at {
1681
    my ($self, %args) = @_;
1682

            
updated pod
Yuki Kimoto authored on 2011-06-08
1683
    warn "select_at is DEPRECATED! use update and id option instead";
1684

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1685
    # Arguments
1686
    my $primary_keys = delete $args{primary_key};
1687
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1688
    my $where = delete $args{where};
1689
    my $param = delete $args{param};
1690
    
1691
    # Check arguments
1692
    foreach my $name (keys %args) {
1693
        croak qq{"$name" is wrong option } . _subname
1694
          unless $SELECT_AT_ARGS{$name};
1695
    }
1696
    
1697
    # Table
1698
    croak qq{"table" option must be specified } . _subname
1699
      unless $args{table};
1700
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1701
    
1702
    # Create where parameter
1703
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1704
    
1705
    return $self->select(where => $where_param, %args);
1706
}
1707

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1708
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1709
our %DELETE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1710
sub delete_at {
1711
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1712

            
1713
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1714
    
1715
    # Arguments
1716
    my $primary_keys = delete $args{primary_key};
1717
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1718
    my $where = delete $args{where};
1719
    
1720
    # Check arguments
1721
    foreach my $name (keys %args) {
1722
        croak qq{"$name" is wrong option } . _subname
1723
          unless $DELETE_AT_ARGS{$name};
1724
    }
1725
    
1726
    # Create where parameter
1727
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1728
    
1729
    return $self->delete(where => $where_param, %args);
1730
}
1731

            
cleanup
Yuki Kimoto authored on 2011-06-08
1732
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1733
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1734
sub update_at {
1735
    my $self = shift;
1736

            
1737
    warn "update_at is DEPRECATED! use update and id option instead";
1738
    
1739
    # Arguments
1740
    my $param;
1741
    $param = shift if @_ % 2;
1742
    my %args = @_;
1743
    my $primary_keys = delete $args{primary_key};
1744
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1745
    my $where = delete $args{where};
1746
    my $p = delete $args{param} || {};
1747
    $param  ||= $p;
1748
    
1749
    # Check arguments
1750
    foreach my $name (keys %args) {
1751
        croak qq{"$name" is wrong option } . _subname
1752
          unless $UPDATE_AT_ARGS{$name};
1753
    }
1754
    
1755
    # Create where parameter
1756
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1757
    
1758
    return $self->update(where => $where_param, param => $param, %args);
1759
}
1760

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1761
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1762
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1763
sub insert_at {
1764
    my $self = shift;
1765
    
1766
    warn "insert_at is DEPRECATED! use insert and id option instead";
1767
    
1768
    # Arguments
1769
    my $param;
1770
    $param = shift if @_ % 2;
1771
    my %args = @_;
1772
    my $primary_key = delete $args{primary_key};
1773
    $primary_key = [$primary_key] unless ref $primary_key;
1774
    my $where = delete $args{where};
1775
    my $p = delete $args{param} || {};
1776
    $param  ||= $p;
1777
    
1778
    # Check arguments
1779
    foreach my $name (keys %args) {
1780
        croak qq{"$name" is wrong option } . _subname
1781
          unless $INSERT_AT_ARGS{$name};
1782
    }
1783
    
1784
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1785
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1786
    $param = $self->merge_param($where_param, $param);
1787
    
1788
    return $self->insert(param => $param, %args);
1789
}
1790

            
added warnings
Yuki Kimoto authored on 2011-06-07
1791
# DEPRECATED!
1792
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1793
    my $self = shift;
1794
    
added warnings
Yuki Kimoto authored on 2011-06-07
1795
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1796
    
1797
    # Merge tag
1798
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1799
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1800
    
1801
    return $self;
1802
}
1803

            
1804
# DEPRECATED!
1805
sub register_tag_processor {
1806
    my $self = shift;
1807
    warn "register_tag_processor is DEPRECATED!";
1808
    # Merge tag
1809
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1810
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1811
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1812
}
1813

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1814
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1815
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1816
has dbi_options => sub { {} };
1817
has filter_check  => 1;
1818
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1819

            
cleanup
Yuki Kimoto authored on 2011-01-25
1820
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1821
sub default_bind_filter {
1822
    my $self = shift;
1823
    
cleanup
Yuki Kimoto authored on 2011-06-13
1824
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1825
    
cleanup
Yuki Kimoto authored on 2011-01-12
1826
    if (@_) {
1827
        my $fname = $_[0];
1828
        
1829
        if (@_ && !$fname) {
1830
            $self->{default_out_filter} = undef;
1831
        }
1832
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1833
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1834
              unless exists $self->filters->{$fname};
1835
        
1836
            $self->{default_out_filter} = $self->filters->{$fname};
1837
        }
1838
        return $self;
1839
    }
1840
    
1841
    return $self->{default_out_filter};
1842
}
1843

            
cleanup
Yuki Kimoto authored on 2011-01-25
1844
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1845
sub default_fetch_filter {
1846
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1847

            
cleanup
Yuki Kimoto authored on 2011-06-13
1848
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1849
    
1850
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1851
        my $fname = $_[0];
1852

            
cleanup
Yuki Kimoto authored on 2011-01-12
1853
        if (@_ && !$fname) {
1854
            $self->{default_in_filter} = undef;
1855
        }
1856
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1857
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1858
              unless exists $self->filters->{$fname};
1859
        
1860
            $self->{default_in_filter} = $self->filters->{$fname};
1861
        }
1862
        
1863
        return $self;
1864
    }
1865
    
many changed
Yuki Kimoto authored on 2011-01-23
1866
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1867
}
1868

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1869
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1870
sub insert_param_tag {
1871
    warn "insert_param_tag is DEPRECATED! " .
1872
         "use insert_param instead!";
1873
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1874
}
1875

            
1876
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1877
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1878
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1879
         "use update_param instead";
1880
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1881
}
cleanup
Yuki Kimoto authored on 2011-03-08
1882
# DEPRECATED!
1883
sub _push_relation {
1884
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1885
    
1886
    if (keys %{$relation || {}}) {
1887
        push @$sql, $need_where ? 'where' : 'and';
1888
        foreach my $rcolumn (keys %$relation) {
1889
            my $table1 = (split (/\./, $rcolumn))[0];
1890
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1891
            push @$tables, ($table1, $table2);
1892
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1893
        }
1894
    }
1895
    pop @$sql if $sql->[-1] eq 'and';    
1896
}
1897

            
1898
# DEPRECATED!
1899
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1900
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1901
    
1902
    if (keys %{$relation || {}}) {
1903
        foreach my $rcolumn (keys %$relation) {
1904
            my $table1 = (split (/\./, $rcolumn))[0];
1905
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1906
            my $table1_exists;
1907
            my $table2_exists;
1908
            foreach my $table (@$tables) {
1909
                $table1_exists = 1 if $table eq $table1;
1910
                $table2_exists = 1 if $table eq $table2;
1911
            }
1912
            unshift @$tables, $table1 unless $table1_exists;
1913
            unshift @$tables, $table2 unless $table2_exists;
1914
        }
1915
    }
1916
}
1917

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1920
=head1 NAME
1921

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1926
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1927
    
1928
    # Connect
1929
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1930
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1931
        user => 'ken',
1932
        password => '!LFKD%$&',
1933
        dbi_option => {mysql_enable_utf8 => 1}
1934
    );
cleanup
yuki-kimoto authored on 2010-08-05
1935

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1936
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1937
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1938
    
1939
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1940
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1941
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1942
    
1943
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1944
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1945

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1950
    # Select, more complex
1951
    my $result = $dbi->select(
1952
        table  => 'book',
1953
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1954
            {book => [qw/title author/]},
1955
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1956
        ],
1957
        where  => {'book.author' => 'Ken'},
1958
        join => ['left outer join company on book.company_id = company.id'],
1959
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1960
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1961
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1962
    # Fetch
1963
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1964
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1965
    }
1966
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1967
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1968
    while (my $row = $result->fetch_hash) {
1969
        
1970
    }
1971
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1972
    # Execute SQL with parameter.
1973
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1974
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1975
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1976
    );
1977
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1978
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1979

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1995
Named place holder support
1996

            
1997
=item *
1998

            
cleanup
Yuki Kimoto authored on 2011-07-29
1999
Model support
2000

            
2001
=item *
2002

            
2003
Connection manager support
2004

            
2005
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2006

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

            
2011
=item *
2012

            
2013
Filtering by data type or column name(EXPERIMENTAL)
2014

            
2015
=item *
2016

            
2017
Create C<order by> clause flexibly(EXPERIMENTAL)
2018

            
2019
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2020

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2028
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2029
L<DBIx::Custom::Result>,
2030
L<DBIx::Custom::Query>,
2031
L<DBIx::Custom::Where>,
2032
L<DBIx::Custom::Model>,
2033
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2034

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

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

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

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

            
2045
This is L<DBIx::Connector> example. Please pass
updated pod
Yuki Kimoto authored on 2011-06-21
2046
C<default_dbi_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2047

            
2048
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2049
        "dbi:mysql:database=$database",
2050
        $user,
2051
        $password,
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2052
        DBIx::Custom->new->default_dbi_option
2053
    );
2054
    
updated pod
Yuki Kimoto authored on 2011-06-21
2055
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2056

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

            
2060
    my $dbi = DBIx::Custom->connect(
2061
      dsn => $dsn, user => $user, password => $password, connector => 1);
2062
    
2063
    my $connector = $dbi->connector; # DBIx::Connector
2064

            
2065
Note that L<DBIx::Connector> must be installed.
2066

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

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

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
2074
=head2 C<dbi_option>
added dbi_options attribute
kimoto authored on 2010-12-20
2075

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
2076
    my $dbi_option = $dbi->dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2077
    $dbi = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2078

            
updated pod
Yuki Kimoto authored on 2011-06-21
2079
L<DBI> option, used when C<connect> method is executed.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2080
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2081

            
2082
=head2 C<default_dbi_option>
2083

            
2084
    my $default_dbi_option = $dbi->default_dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2085
    $dbi = $dbi->default_dbi_option($default_dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2086

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2090
    {
2091
        RaiseError => 1,
2092
        PrintError => 0,
2093
        AutoCommit => 1,
2094
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2095

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

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

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

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

            
2105
    my $last_sql = $dbi->last_sql;
2106
    $dbi = $dbi->last_sql($last_sql);
2107

            
2108
Get last successed SQL executed by C<execute> method.
2109

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2117
=head2 C<password>
2118

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2139
You can set quote pair.
2140

            
2141
    $dbi->quote('[]');
2142

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2152
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2153
    $dbi = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2154

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

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

            
2160
    my $separator = $self->separator;
2161
    $dbi = $self->separator($separator);
2162

            
2163
Separator whichi join table and column.
2164
This is used by C<column> and C<mycolumn> method.
2165

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2166
=head2 C<exclude_table EXPERIMENTAL>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2167

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2168
    my $exclude_table = $self->exclude_table;
2169
    $dbi = $self->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2170

            
2171
Regex matching system table.
2172
this regex match is used by C<each_table> method and C<each_column> method
2173
System table is ignored.
2174
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2175
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2176
The performance is up.
2177

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

            
2180
    my $tag_parse = $dbi->tag_parse(0);
2181
    $dbi = $dbi->tag_parse;
2182

            
2183
Enable DEPRECATED tag parsing functionality, default to 1.
2184
If you want to disable tag parsing functionality, set to 0.
2185

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

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2193
=head2 C<user_column_info EXPERIMENTAL>
2194

            
2195
    my $user_column_info = $dbi->user_column_info;
2196
    $dbi = $dbi->user_column_info($user_column_info);
2197

            
2198
You can set the following data.
2199

            
2200
    [
2201
        {table => 'book', column => 'title', info => {...}},
2202
        {table => 'author', column => 'name', info => {...}}
2203
    ]
2204

            
2205
Usually, you can set return value of C<get_column_info>.
2206

            
2207
    my $user_column_info
2208
      = $dbi->get_column_info(exclude_table => qr/^system/);
2209
    $dbi->user_column_info($user_column_info);
2210

            
2211
If C<user_column_info> is set, C<each_column> use C<user_column_info>
2212
to find column info.
2213

            
added test
Yuki Kimoto authored on 2011-08-16
2214
=head2 C<user_table_info EXPERIMENTAL>
2215

            
2216
    my $user_table_info = $dbi->user_table_info;
2217
    $dbi = $dbi->user_table_info($user_table_info);
2218

            
2219
You can set the following data.
2220

            
2221
    [
2222
        {table => 'book', info => {...}},
2223
        {table => 'author', info => {...}}
2224
    ]
2225

            
2226
Usually, you can set return value of C<get_table_info>.
2227

            
2228
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2229
    $dbi->user_table_info($user_table_info);
2230

            
2231
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2232
to find table info.
2233

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2240
=head2 C<available_datatype> EXPERIMENTAL
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2241

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2247
=head2 C<available_typename> EXPERIMENTAL
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2248

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2254
=head2 C<assign_param> EXPERIMENTAL
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2255

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2256
    my $assign_param = $dbi->assign_param({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2257

            
updated pod
Yuki Kimoto authored on 2011-06-09
2258
Create assign parameter.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2259

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2262
This is equal to C<update_param> exept that set is not added.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2263

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

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

            
2268
Create column clause. The follwoing column clause is created.
2269

            
2270
    book.author as "book.author",
2271
    book.title as "book.title"
2272

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2275
    # Separator is double underbar
2276
    $dbi->separator('__');
2277
    
2278
    book.author as "book__author",
2279
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2280

            
cleanup
Yuki Kimoto authored on 2011-06-13
2281
    # Separator is hyphen
2282
    $dbi->separator('-');
2283
    
2284
    book.author as "book-author",
2285
    book.title as "book-title"
2286
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2287
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2288

            
update pod
Yuki Kimoto authored on 2011-03-13
2289
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2290
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2291
        user => 'ken',
2292
        password => '!LFKD%$&',
2293
        dbi_option => {mysql_enable_utf8 => 1}
2294
    );
2295

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2302
=head2 C<count> EXPERIMENTAL
2303

            
2304
    my $count = $model->count(table => 'book');
2305

            
2306
Get rows count.
2307

            
2308
Options is same as C<select> method's ones.
2309

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2312
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2313
        table => 'book',
2314
        primary_key => 'id',
2315
        join => [
2316
            'inner join company on book.comparny_id = company.id'
2317
        ],
2318
    );
2319

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

            
2323
   $dbi->model('book')->select(...);
2324

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

            
2327
    my $dbh = $dbi->dbh;
2328

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

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

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

            
2336
Execute delete statement.
2337

            
2338
The following opitons are available.
2339

            
2340
=over 4
2341

            
2342
=item C<append>
2343

            
2344
Same as C<select> method's C<append> option.
2345

            
2346
=item C<filter>
2347

            
2348
Same as C<execute> method's C<filter> option.
2349

            
2350
=item C<id>
2351

            
2352
    id => 4
2353
    id => [4, 5]
2354

            
2355
ID corresponding to C<primary_key>.
2356
You can delete rows by C<id> and C<primary_key>.
2357

            
2358
    $dbi->delete(
2359
        parimary_key => ['id1', 'id2'],
2360
        id => [4, 5],
2361
        table => 'book',
2362
    );
2363

            
2364
The above is same as the followin one.
2365

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

            
2368
=item C<prefix>
2369

            
2370
    prefix => 'some'
2371

            
2372
prefix before table name section.
2373

            
2374
    delete some from book
2375

            
2376
=item C<query>
2377

            
2378
Same as C<execute> method's C<query> option.
2379

            
2380
=item C<sqlfilter EXPERIMENTAL>
2381

            
2382
Same as C<execute> method's C<sqlfilter> option.
2383

            
2384
=item C<table>
2385

            
2386
    table => 'book'
2387

            
2388
Table name.
2389

            
2390
=item C<where>
2391

            
2392
Same as C<select> method's C<where> option.
2393

            
2394
=item C<primary_key>
2395

            
2396
See C<id> option.
2397

            
2398
=item C<bind_type>
2399

            
2400
Same as C<execute> method's C<bind_type> option.
2401

            
2402
=item C<type_rule_off> EXPERIMENTAL
2403

            
2404
Same as C<execute> method's C<type_rule_off> option.
2405

            
2406
=item C<type_rule1_off> EXPERIMENTAL
2407

            
2408
    type_rule1_off => 1
2409

            
2410
Same as C<execute> method's C<type_rule1_off> option.
2411

            
2412
=item C<type_rule2_off> EXPERIMENTAL
2413

            
2414
    type_rule2_off => 1
2415

            
2416
Same as C<execute> method's C<type_rule2_off> option.
2417

            
2418
=back
2419

            
2420
=head2 C<delete_all>
2421

            
2422
    $dbi->delete_all(table => $table);
2423

            
2424
Execute delete statement for all rows.
2425
Options is same as C<delete>.
2426

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

            
2429
    $dbi->each_column(
2430
        sub {
2431
            my ($dbi, $table, $column, $column_info) = @_;
2432
            
2433
            my $type = $column_info->{TYPE_NAME};
2434
            
2435
            if ($type eq 'DATE') {
2436
                # ...
2437
            }
2438
        }
2439
    );
2440

            
2441
Iterate all column informations of all table from database.
2442
Argument is callback when one column is found.
2443
Callback receive four arguments, dbi object, table name,
2444
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2445

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

            
2448
    $dbi->each_table(
2449
        sub {
2450
            my ($dbi, $table, $table_info) = @_;
2451
            
2452
            my $table_name = $table_info->{TABLE_NAME};
2453
        }
2454
    );
2455

            
2456
Iterate all table informationsfrom database.
2457
Argument is callback when one table is found.
2458
Callback receive three arguments, dbi object, table name,
2459
table information.
2460

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

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

            
2468
    my $result = $dbi->execute(
2469
      "select * from book where title = :book.title and author like :book.author",
2470
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2471
    );
2472

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2479
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2480
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2481
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2482
    select * from book where title = :title and author like :author
2483
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2484
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2485
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2486

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2487
You can specify operator with named placeholder
2488
 by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2489

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2490
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2491
    select * from book where :title{=} and :author{like}
2492
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2493
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2494
    select * from where title = ? and author like ?;
2495

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

            
2500
    select * from where title = "aa\\:bb";
2501

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

            
2504
=over 4
2505

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

            
2508
Specify database bind data type.
2509

            
2510
    bind_type => [image => DBI::SQL_BLOB]
2511
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2512

            
2513
This is used to bind parameter by C<bind_param> of statment handle.
2514

            
2515
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2516

            
update pod
Yuki Kimoto authored on 2011-03-13
2517
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2518
    
2519
    filter => {
2520
        title  => sub { uc $_[0] }
2521
        author => sub { uc $_[0] }
2522
    }
update pod
Yuki Kimoto authored on 2011-03-13
2523

            
updated pod
Yuki Kimoto authored on 2011-06-09
2524
    # Filter name
2525
    filter => {
2526
        title  => 'upper_case',
2527
        author => 'upper_case'
2528
    }
2529
        
2530
    # At once
2531
    filter => [
2532
        [qw/title author/]  => sub { uc $_[0] }
2533
    ]
2534

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

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

            
2542
    id => 4
2543
    id => [4, 5]
2544

            
2545
ID corresponding to C<primary_key>.
2546
You can delete rows by C<id> and C<primary_key>.
2547

            
2548
    $dbi->execute(
2549
        "select * from book where id1 = :id1 and id2 = :id2",
2550
        {},
2551
        parimary_key => ['id1', 'id2'],
2552
        id => [4, 5],
2553
    );
2554

            
2555
The above is same as the followin one.
2556

            
2557
    $dbi->execute(
2558
        "select * from book where id1 = :id1 and id2 = :id2",
2559
        {id1 => 4, id2 => 5}
2560
    );
2561

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

            
2564
    query => 1
2565

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

            
2569
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2570
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2571
    my $columns = $query->columns;
2572
    
2573
If you want to execute SQL fast, you can do the following way.
2574

            
2575
    my $query;
2576
    foreach my $row (@$rows) {
2577
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2578
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2579
    }
2580

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

            
2584
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
2585
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2586
    
2587
    my $query;
2588
    my $sth;
2589
    foreach my $row (@$rows) {
2590
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2591
      $sth ||= $query->sth;
2592
      $sth->execute(map { $row->{$_} } sort keys %$row);
2593
    }
2594

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

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

            
2601
See C<id> option.
2602

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2603
=item C<sqlfilter EXPERIMENTAL> 
2604

            
2605
SQL filter function.
2606

            
2607
    sqlfilter => $code_ref
2608

            
2609
This option is generally for Oracle and SQL Server paging process.
2610
    
2611
    my $limit = sub {
2612
        my ($sql, $count, $offset) = @_;
2613
        
2614
        my $min = $offset + 1;
2615
        my $max = $offset + $count;
2616
        
2617
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2618
        
2619
        return $sql;
2620
    }
2621
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2622
        my $sql = shift;
2623
        return $limit->($sql, 100, 50);
2624
    })
2625

            
updated pod
Yuki Kimoto authored on 2011-06-09
2626
=item C<table>
2627
    
2628
    table => 'author'
2629

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2637
    # Same
2638
    $dbi->execute(
2639
      "select * from book where title = :book.title and author = :book.author",
2640
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2641

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2642
=item C<table_alias> EXPERIMENTAL
2643

            
2644
    table_alias => {user => 'hiker'}
2645

            
2646
Table alias. Key is real table name, value is alias table name.
2647
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2648
on alias table name.
2649

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2650
=item C<type_rule_off> EXPERIMENTAL
2651

            
2652
    type_rule_off => 1
2653

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

            
2656
=item C<type_rule1_off> EXPERIMENTAL
2657

            
2658
    type_rule1_off => 1
2659

            
2660
Turn C<into1> type rule off.
2661

            
2662
=item C<type_rule2_off> EXPERIMENTAL
2663

            
2664
    type_rule2_off => 1
2665

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2670
=head2 C<get_column_info EXPERIMENTAL>
2671

            
2672
    my $tables = $self->get_column_info(exclude_table => qr/^system_/);
2673

            
2674
get column infomation except for one which match C<exclude_table> pattern.
2675

            
2676
    [
2677
        {table => 'book', column => 'title', info => {...}},
2678
        {table => 'author', column => 'name' info => {...}}
2679
    ]
2680

            
added test
Yuki Kimoto authored on 2011-08-16
2681
=head2 C<get_table_info EXPERIMENTAL>
2682

            
2683
    my $tables = $self->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2684

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

            
2687
    [
2688
        {table => 'book', info => {...}},
2689
        {table => 'author', info => {...}}
2690
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2691

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2694
=head2 C<insert>
2695

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

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

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

            
2704
    {date => \"NOW()"}
2705

            
cleanup
Yuki Kimoto authored on 2011-06-09
2706
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2707

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2710
=item C<append>
2711

            
cleanup
Yuki Kimoto authored on 2011-06-09
2712
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2713

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

            
2716
Same as C<execute> method's C<bind_type> option.
2717

            
update pod
Yuki Kimoto authored on 2011-03-13
2718
=item C<filter>
2719

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2720
Same as C<execute> method's C<filter> option.
2721

            
2722
=item C<id>
2723

            
updated document
Yuki Kimoto authored on 2011-06-09
2724
    id => 4
2725
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2726

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2730
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2731
        {title => 'Perl', author => 'Ken'}
2732
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2733
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2734
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2735
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2736

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

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

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

            
2746
    prefix => 'or replace'
2747

            
2748
prefix before table name section
2749

            
2750
    insert or replace into book
2751

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2752
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2753

            
updated document
Yuki Kimoto authored on 2011-06-09
2754
    primary_key => 'id'
2755
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
2756

            
updated document
Yuki Kimoto authored on 2011-06-09
2757
Primary key. This is used by C<id> option.
cleanup
Yuki Kimoto authored on 2011-06-09
2758

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

            
2761
Same as C<execute> method's C<query> option.
2762

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2763
=item C<sqlfilter EXPERIMENTAL>
2764

            
2765
Same as C<execute> method's C<sqlfilter> option.
2766

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

            
2769
    table => 'book'
2770

            
2771
Table name.
2772

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2773
=item C<type_rule_off> EXPERIMENTAL
2774

            
updated document
Yuki Kimoto authored on 2011-06-09
2775
Same as C<execute> method's C<type_rule_off> option.
update pod
Yuki Kimoto authored on 2011-03-13
2776

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2777
=item C<type_rule1_off> EXPERIMENTAL
2778

            
2779
    type_rule1_off => 1
2780

            
2781
Same as C<execute> method's C<type_rule1_off> option.
2782

            
2783
=item C<type_rule2_off> EXPERIMENTAL
2784

            
2785
    type_rule2_off => 1
2786

            
2787
Same as C<execute> method's C<type_rule2_off> option.
2788

            
update pod
Yuki Kimoto authored on 2011-03-13
2789
=back
2790

            
2791
=over 4
2792

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2793
=head2 C<insert_param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2794

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2795
    my $insert_param = $dbi->insert_param({title => 'a', age => 2});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2796

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2797
Create insert parameters.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2798

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2799
    (title, author) values (title = :title, age = :age);
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2800

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2808
    lib / MyModel.pm
2809
        / MyModel / book.pm
2810
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2811

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

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

            
2816
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2817
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2818
    
2819
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2820

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2825
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2826
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2827
    
2828
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2829

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2832
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2833
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2834
    
2835
    1;
2836
    
updated pod
Yuki Kimoto authored on 2011-06-21
2837
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2838

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

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

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
2846
=head2 C<map_param> EXPERIMENTAL
2847

            
2848
    my $map_param = $dbi->map_param(
2849
        {id => 1, authro => 'Ken', price => 1900},
2850
        'id' => 'book.id',
2851
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2852
        'price' => [
2853
            'book.price', {if => sub { length $_[0] }}
2854
        ]
2855
    );
2856

            
2857
Map paramters to other key and value. First argument is original
2858
parameter. this is hash reference. Rest argument is mapping.
2859
By default, Mapping is done if the value length is not zero.
2860

            
2861
=over 4
2862

            
2863
=item Key mapping
2864

            
2865
    'id' => 'book.id'
2866

            
2867
This is only key mapping. Value is same as original one.
2868

            
2869
    (id => 1) is mapped to ('book.id' => 1) if value length is not zero.
2870

            
2871
=item Key and value mapping
2872

            
2873
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2874

            
2875
This is key and value mapping. Frist element of array reference
2876
is mapped key name, second element is code reference to map the value.
2877

            
2878
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2879
      if value length is not zero.
2880

            
2881
=item Condition
2882

            
2883
    'price' => ['book.price', {if => 'exists'}]
2884
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2885
    'price' => ['book.price', {if => sub { defined shift }}]
2886

            
2887
If you need condition, you can sepecify it. this is code reference
2888
or 'exists'. By default, condition is the following one.
2889

            
2890
    sub { defined $_[0] && length $_[0] }
2891

            
2892
=back
2893

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

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

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2898
Merge parameters.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2899

            
2900
    {key1 => [1, 1], key2 => 2}
2901

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2902
=head2 C<method>
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2903

            
2904
    $dbi->method(
2905
        update_or_insert => sub {
2906
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2907
            
2908
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2909
        },
2910
        find_or_create   => sub {
2911
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2912
            
2913
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2914
        }
2915
    );
2916

            
update pod
Yuki Kimoto authored on 2011-03-13
2917
Register method. These method is called directly from L<DBIx::Custom> object.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2918

            
2919
    $dbi->update_or_insert;
2920
    $dbi->find_or_create;
2921

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

            
2924
    my $model = $dbi->model('book');
2925

            
updated pod
Yuki Kimoto authored on 2011-06-21
2926
Get a L<DBIx::Custom::Model> object,
update pod
Yuki Kimoto authored on 2011-03-13
2927

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

            
2930
    my $column = $self->mycolumn(book => ['author', 'title']);
2931

            
2932
Create column clause for myself. The follwoing column clause is created.
2933

            
2934
    book.author as author,
2935
    book.title as title
2936

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2939
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2940
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2941
        user => 'ken',
2942
        password => '!LFKD%$&',
2943
        dbi_option => {mysql_enable_utf8 => 1}
2944
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2945

            
2946
Create a new L<DBIx::Custom> object.
2947

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

            
2950
    my $not_exists = $dbi->not_exists;
2951

            
update pod
Yuki Kimoto authored on 2011-03-13
2952
DBIx::Custom::NotExists object, indicating the column is not exists.
2953
This is used by C<clause> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2954

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2955
=head2 C<order> EXPERIMENTAL
2956

            
2957
    my $order = $dbi->order;
2958

            
2959
Create a new L<DBIx::Custom::Order> object.
2960

            
cleanup
yuki-kimoto authored on 2010-10-17
2961
=head2 C<register_filter>
2962

            
update pod
Yuki Kimoto authored on 2011-03-13
2963
    $dbi->register_filter(
2964
        # Time::Piece object to database DATE format
2965
        tp_to_date => sub {
2966
            my $tp = shift;
2967
            return $tp->strftime('%Y-%m-%d');
2968
        },
2969
        # database DATE format to Time::Piece object
2970
        date_to_tp => sub {
2971
           my $date = shift;
2972
           return Time::Piece->strptime($date, '%Y-%m-%d');
2973
        }
2974
    );
cleanup
yuki-kimoto authored on 2010-10-17
2975
    
update pod
Yuki Kimoto authored on 2011-03-13
2976
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2977

            
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2978
=head2 C<type_rule> EXPERIMENTAL
2979

            
2980
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2981
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2982
            date => sub { ... },
2983
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2984
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2985
        into2 => {
2986
            date => sub { ... },
2987
            datetime => sub { ... }
2988
        },
2989
        from1 => {
2990
            # DATE
2991
            9 => sub { ... },
2992
            # DATETIME or TIMESTAMP
2993
            11 => sub { ... },
2994
        }
2995
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2996
            # DATE
2997
            9 => sub { ... },
2998
            # DATETIME or TIMESTAMP
2999
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3000
        }
3001
    );
3002

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3003
Filtering rule when data is send into and get from database.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
3004
This has a little complex problem.
cleanup
Yuki Kimoto authored on 2011-06-13
3005

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3006
In C<into1> and C<into2> you can specify
3007
type name as same as type name defined
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3008
by create table, such as C<DATETIME> or C<DATE>.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3009

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
3010
Note that type name and data type don't contain upper case.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3011
If these contain upper case charactor, you convert it to lower case.
3012

            
updated pod
Yuki Kimoto authored on 2011-06-21
3013
C<into2> is executed after C<into1>.
3014

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3015
Type rule of C<into1> and C<into2> is enabled on the following
3016
column name.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
3017

            
cleanup
Yuki Kimoto authored on 2011-06-13
3018
=over 4
3019

            
3020
=item 1. column name
3021

            
3022
    issue_date
3023
    issue_datetime
3024

            
updated pod
Yuki Kimoto authored on 2011-06-21
3025
This need C<table> option in each method.
3026

            
cleanup
Yuki Kimoto authored on 2011-06-13
3027
=item 2. table name and column name, separator is dot
3028

            
3029
    book.issue_date
3030
    book.issue_datetime
3031

            
3032
=back
3033

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
3034
You get all type name used in database by C<available_typename>.
update pod
Yuki Kimoto authored on 2011-06-15
3035

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
3036
    print $dbi->available_typename;
update pod
Yuki Kimoto authored on 2011-06-15
3037

            
updated pod
Yuki Kimoto authored on 2011-06-21
3038
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3039
C<from2> is executed after C<from1>.
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
3040
You get all data type by C<available_datatype>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3041

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3044
You can also specify multiple types at once.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3045

            
3046
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3047
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3048
            [qw/DATE DATETIME/] => sub { ... },
3049
        ],
3050
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3051

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3054
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3055
        table  => 'book',
3056
        column => ['author', 'title'],
3057
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3058
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3059
    
updated document
Yuki Kimoto authored on 2011-06-09
3060
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3061

            
updated document
Yuki Kimoto authored on 2011-06-09
3062
The following opitons are available.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3063

            
3064
=over 4
3065

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3068
    append => 'order by title'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3069

            
updated document
Yuki Kimoto authored on 2011-06-09
3070
Append statement to last of SQL.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3071

            
3072
=item C<bind_type>
3073

            
3074
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3075
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3076
=item C<column>
3077
    
updated document
Yuki Kimoto authored on 2011-06-09
3078
    column => 'author'
3079
    column => ['author', 'title']
3080

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3089
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3090
        {book => [qw/author title/]},
3091
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3092
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3093

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

            
3096
    book.author as "book.author",
3097
    book.title as "book.title",
3098
    person.name as "person.name",
3099
    person.age as "person.age"
3100

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

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

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

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

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

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

            
3116
=item C<id>
3117

            
3118
    id => 4
3119
    id => [4, 5]
3120

            
3121
ID corresponding to C<primary_key>.
3122
You can select rows by C<id> and C<primary_key>.
3123

            
3124
    $dbi->select(
3125
        parimary_key => ['id1', 'id2'],
3126
        id => [4, 5],
3127
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3128
    );
3129

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3132
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3133
        where => {id1 => 4, id2 => 5},
3134
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3135
    );
3136
    
updated document
Yuki Kimoto authored on 2011-06-09
3137
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3138

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

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

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

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

            
3151
    prefix => 'SQL_CALC_FOUND_ROWS'
3152

            
3153
Prefix of column cluase
3154

            
3155
    select SQL_CALC_FOUND_ROWS title, author from book;
3156

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

            
3159
    join => [
3160
        'left outer join company on book.company_id = company_id',
3161
        'left outer join location on company.location_id = location.id'
3162
    ]
3163
        
3164
Join clause. If column cluase or where clause contain table name like "company.name",
3165
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3166

            
3167
    $dbi->select(
3168
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3169
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3170
        where => {'company.name' => 'Orange'},
3171
        join => [
3172
            'left outer join company on book.company_id = company.id',
3173
            'left outer join location on company.location_id = location.id'
3174
        ]
3175
    );
3176

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3180
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3181
    from book
3182
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3183
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3184

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3185
You can specify two table by yourself. This is useful when join parser can't parse
cleanup
Yuki Kimoto authored on 2011-07-28
3186
the join clause correctly. This is EXPERIMENTAL.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3187

            
3188
    $dbi->select(
3189
        table => 'book',
3190
        column => ['company.location_id as location_id'],
3191
        where => {'company.name' => 'Orange'},
3192
        join => [
3193
            {
3194
                clause => 'left outer join location on company.location_id = location.id',
3195
                table => ['company', 'location']
3196
            }
3197
        ]
3198
    );
3199

            
updated document
Yuki Kimoto authored on 2011-06-09
3200
=item C<primary_key>
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
3201

            
updated document
Yuki Kimoto authored on 2011-06-09
3202
    primary_key => 'id'
3203
    primary_key => ['id1', 'id2']
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
3204

            
updated document
Yuki Kimoto authored on 2011-06-09
3205
Primary key. This is used by C<id> option.
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
3206

            
updated document
Yuki Kimoto authored on 2011-06-09
3207
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-12
3208

            
updated document
Yuki Kimoto authored on 2011-06-09
3209
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-12
3210

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3211
=item C<sqlfilter EXPERIMENTAL>
updated pod
Yuki Kimoto authored on 2011-06-08
3212

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3213
Same as C<execute> method's C<sqlfilter> option
updated pod
Yuki Kimoto authored on 2011-06-08
3214

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3219
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3220

            
updated document
Yuki Kimoto authored on 2011-06-09
3221
=item C<type_rule_off> EXPERIMENTAL
updated pod
Yuki Kimoto authored on 2011-06-08
3222

            
updated document
Yuki Kimoto authored on 2011-06-09
3223
Same as C<execute> method's C<type_rule_off> option.
updated pod
Yuki Kimoto authored on 2011-06-08
3224

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3225
=item C<type_rule1_off> EXPERIMENTAL
3226

            
3227
    type_rule1_off => 1
3228

            
3229
Same as C<execute> method's C<type_rule1_off> option.
3230

            
3231
=item C<type_rule2_off> EXPERIMENTAL
3232

            
3233
    type_rule2_off => 1
3234

            
3235
Same as C<execute> method's C<type_rule2_off> option.
3236

            
updated document
Yuki Kimoto authored on 2011-06-09
3237
=item C<where>
3238
    
3239
    # Hash refrence
3240
    where => {author => 'Ken', 'title' => 'Perl'}
3241
    
3242
    # DBIx::Custom::Where object
3243
    where => $dbi->where(
3244
        clause => ['and', 'author = :author', 'title like :title'],
3245
        param  => {author => 'Ken', title => '%Perl%'}
3246
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3247
    
3248
    # Array reference 1 (array reference, hash referenc). same as above
3249
    where => [
3250
        ['and', 'author = :author', 'title like :title'],
3251
        {author => 'Ken', title => '%Perl%'}
3252
    ];    
3253
    
3254
    # Array reference 2 (String, hash reference)
3255
    where => [
3256
        'title like :title',
3257
        {title => '%Perl%'}
3258
    ]
3259
    
3260
    # String
3261
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3262

            
updated document
Yuki Kimoto authored on 2011-06-09
3263
Where clause.
3264
    
improved pod
Yuki Kimoto authored on 2011-04-19
3265
=item C<wrap> EXPERIMENTAL
3266

            
3267
Wrap statement. This is array reference.
3268

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3269
    wrap => ['select * from (', ') as t where ROWNUM < 10']
improved pod
Yuki Kimoto authored on 2011-04-19
3270

            
3271
This option is for Oracle and SQL Server paging process.
3272

            
update pod
Yuki Kimoto authored on 2011-03-12
3273
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3274

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

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

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

            
3281
If you want to set constant value to row data, use scalar reference
3282
as parameter value.
3283

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3286
The following opitons are available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3287

            
update pod
Yuki Kimoto authored on 2011-03-13
3288
=over 4
3289

            
updated document
Yuki Kimoto authored on 2011-06-09
3290
=item C<append>
update pod
Yuki Kimoto authored on 2011-03-13
3291

            
updated document
Yuki Kimoto authored on 2011-06-09
3292
Same as C<select> method's C<append> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3293

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

            
3296
Same as C<execute> method's C<bind_type> option.
3297

            
updated document
Yuki Kimoto authored on 2011-06-09
3298
=item C<filter>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3299

            
updated document
Yuki Kimoto authored on 2011-06-09
3300
Same as C<execute> method's C<filter> option.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3301

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3304
    id => 4
3305
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3306

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3310
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3311
        {title => 'Perl', author => 'Ken'}
3312
        parimary_key => ['id1', 'id2'],
3313
        id => [4, 5],
3314
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3315
    );
update pod
Yuki Kimoto authored on 2011-03-13
3316

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3319
    $dbi->update(
3320
        {title => 'Perl', author => 'Ken'}
3321
        where => {id1 => 4, id2 => 5},
3322
        table => 'book'
3323
    );
update pod
Yuki Kimoto authored on 2011-03-13
3324

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

            
3327
    prefix => 'or replace'
3328

            
3329
prefix before table name section
3330

            
3331
    update or replace book
3332

            
updated document
Yuki Kimoto authored on 2011-06-09
3333
=item C<primary_key>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
3334

            
updated document
Yuki Kimoto authored on 2011-06-09
3335
    primary_key => 'id'
3336
    primary_key => ['id1', 'id2']
update pod
Yuki Kimoto authored on 2011-03-13
3337

            
updated document
Yuki Kimoto authored on 2011-06-09
3338
Primary key. This is used by C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
3339

            
updated document
Yuki Kimoto authored on 2011-06-09
3340
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
3341

            
updated document
Yuki Kimoto authored on 2011-06-09
3342
Same as C<execute> method's C<query> option.
update pod
Yuki Kimoto authored on 2011-03-13
3343

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3344
=item C<sqlfilter EXPERIMENTAL>
3345

            
3346
Same as C<execute> method's C<sqlfilter> option.
3347

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

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3354
=item C<type_rule_off> EXPERIMENTAL
3355

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3356
Same as C<execute> method's C<type_rule_off> option.
3357

            
3358
=item C<type_rule1_off> EXPERIMENTAL
3359

            
3360
    type_rule1_off => 1
3361

            
3362
Same as C<execute> method's C<type_rule1_off> option.
3363

            
3364
=item C<type_rule2_off> EXPERIMENTAL
3365

            
3366
    type_rule2_off => 1
3367

            
3368
Same as C<execute> method's C<type_rule2_off> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3369

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

            
3372
Same as C<select> method's C<where> option.
3373

            
updated pod
Yuki Kimoto authored on 2011-06-08
3374
=back
update pod
Yuki Kimoto authored on 2011-03-13
3375

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3383
=head2 C<update_param>
update pod
Yuki Kimoto authored on 2011-03-13
3384

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3385
    my $update_param = $dbi->update_param({title => 'a', age => 2});
update pod
Yuki Kimoto authored on 2011-03-13
3386

            
3387
Create update parameter tag.
3388

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3389
    set title = :title, author = :author
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
3390

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
3391
=head2 C<where>
fix tests
Yuki Kimoto authored on 2011-01-18
3392

            
cleanup
Yuki Kimoto authored on 2011-03-09
3393
    my $where = $dbi->where(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
3394
        clause => ['and', 'title = :title', 'author = :author'],
cleanup
Yuki Kimoto authored on 2011-03-09
3395
        param => {title => 'Perl', author => 'Ken'}
3396
    );
fix tests
Yuki Kimoto authored on 2011-01-18
3397

            
3398
Create a new L<DBIx::Custom::Where> object.
3399

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
3400
=head2 C<setup_model>
cleanup
Yuki Kimoto authored on 2011-01-12
3401

            
update pod
Yuki Kimoto authored on 2011-03-13
3402
    $dbi->setup_model;
cleanup
Yuki Kimoto authored on 2011-01-12
3403

            
update pod
Yuki Kimoto authored on 2011-03-13
3404
Setup all model objects.
update pod
Yuki Kimoto authored on 2011-03-13
3405
C<columns> of model object is automatically set, parsing database information.
cleanup
Yuki Kimoto authored on 2011-01-12
3406

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3407
=head1 ENVIRONMENTAL VARIABLES
added environment variable D...
Yuki Kimoto authored on 2011-04-02
3408

            
3409
=head2 C<DBIX_CUSTOM_DEBUG>
3410

            
3411
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
improved debug message
Yuki Kimoto authored on 2011-05-23
3412
executed SQL and bind values are printed to STDERR.
3413

            
update pod
Yuki Kimoto authored on 2011-08-10
3414
=head2 C<show_datatype EXPERIMENTAL>
3415

            
3416
    $dbi->show_datatype($table);
3417

            
3418
Show data type of the columns of specified table.
3419

            
3420
    book
3421
    title: 5
3422
    issue_date: 91
3423

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

            
test cleanup
Yuki Kimoto authored on 2011-08-15
3426
=head2 C<show_tables EXPERIMETNAL>
3427

            
3428
    $dbi->show_tables;
3429

            
3430
Show tables.
3431

            
update pod
Yuki Kimoto authored on 2011-08-10
3432
=head2 C<show_typename EXPERIMENTAL>
3433

            
3434
    $dbi->show_typename($table);
3435

            
3436
Show type name of the columns of specified table.
3437

            
3438
    book
3439
    title: varchar
3440
    issue_date: date
3441

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

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

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

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

            
3450
L<DBIx::Custom>
3451

            
3452
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3453
    data_source # will be removed at 2017/1/1
3454
    dbi_options # will be removed at 2017/1/1
3455
    filter_check # will be removed at 2017/1/1
3456
    reserved_word_quote # will be removed at 2017/1/1
3457
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3458
    
3459
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3460
    create_query # will be removed at 2017/1/1
3461
    apply_filter # will be removed at 2017/1/1
3462
    select_at # will be removed at 2017/1/1
3463
    delete_at # will be removed at 2017/1/1
3464
    update_at # will be removed at 2017/1/1
3465
    insert_at # will be removed at 2017/1/1
3466
    register_tag # will be removed at 2017/1/1
3467
    default_bind_filter # will be removed at 2017/1/1
3468
    default_fetch_filter # will be removed at 2017/1/1
3469
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3470
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3471
    register_tag_processor # will be removed at 2017/1/1
3472
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3473
    
3474
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3475
    select method relation option # will be removed at 2017/1/1
3476
    select method param option # will be removed at 2017/1/1
3477
    select method column option [COLUMN, as => ALIAS] format
3478
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3479
    
3480
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3481
    execute("select * from {= title}"); # execute method's
3482
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3483
                                        # will be removed at 2017/1/1
3484
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3485

            
3486
L<DBIx::Custom::Model>
3487

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3488
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3489
    filter # will be removed at 2017/1/1
3490
    name # will be removed at 2017/1/1
3491
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3492

            
3493
L<DBIx::Custom::Query>
3494
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3495
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3496
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3497
    table # will be removed at 2017/1/1
3498
    filters # will be removed at 2017/1/1
3499
    
3500
    # Methods
3501
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3502

            
3503
L<DBIx::Custom::QueryBuilder>
3504
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3505
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3506
    tags # will be removed at 2017/1/1
3507
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3508
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3509
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3510
    register_tag # will be removed at 2017/1/1
3511
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3512
    
3513
    # Others
3514
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3515
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3516

            
3517
L<DBIx::Custom::Result>
3518
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3519
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3520
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3521
    
3522
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3523
    end_filter # will be removed at 2017/1/1
3524
    remove_end_filter # will be removed at 2017/1/1
3525
    remove_filter # will be removed at 2017/1/1
3526
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3527

            
3528
L<DBIx::Custom::Tag>
3529

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

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

            
3534
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3535
except for attribute method.
3536
You can check all DEPRECATED functionalities by document.
3537
DEPRECATED functionality is removed after five years,
3538
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
3539
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3540

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

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3543
This policy was changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3544

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

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

            
3549
C<< <kimoto.yuki at gmail.com> >>
3550

            
3551
L<http://github.com/yuki-kimoto/DBIx-Custom>
3552

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3553
=head1 AUTHOR
3554

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

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

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

            
3561
This program is free software; you can redistribute it and/or modify it
3562
under the same terms as Perl itself.
3563

            
3564
=cut