DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3512 lines | 91.391kb
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 EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
4
our $VERSION = '0.1717';
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

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

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

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

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

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

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

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

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

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

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

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

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

            
374
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
375
    my $self = shift;
376
    my $query = shift;
377
    my $param;
378
    $param = shift if @_ % 2;
379
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
380
    
cleanup
Yuki Kimoto authored on 2011-04-02
381
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
382
    my $p = delete $args{param} || {};
383
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
384
    my $tables = delete $args{table} || [];
385
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
386
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
387
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
388
    my $bind_type = delete $args{bind_type} || delete $args{type};
389
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
390
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
391
    my $type_rule_off_parts = {
392
        1 => delete $args{type_rule1_off},
393
        2 => delete $args{type_rule2_off}
394
    };
cleanup
Yuki Kimoto authored on 2011-06-09
395
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
396
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
397
    my $sqlfilter = $args{sqlfilter};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
398
    
cleanup
Yuki Kimoto authored on 2011-03-09
399
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
400
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
401
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
402
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
403
    }
404
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
405
    $query = $self->_create_query($query, $sqlfilter) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
406
    
407
    # Save query
408
    $self->last_sql($query->sql);
409

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

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

            
540
        return $result;
541
    }
cleanup
Yuki Kimoto authored on 2011-04-02
542
    
543
    # Not select statement
544
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
545
}
546

            
added test
Yuki Kimoto authored on 2011-08-16
547
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
548
    my ($self, %args) = @_;
549
    
550
    my $exclude = delete $args{exclude};
551
    croak qq/"$_" is wrong option/ for keys %args;
552
    
added test
Yuki Kimoto authored on 2011-08-16
553
    my $table_info = [];
554
    $self->each_table(
555
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
556
        exclude => $exclude
557
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
558
    
cleanup test
Yuki Kimoto authored on 2011-08-16
559
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
560
}
561

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
562
sub get_column_info {
563
    my ($self, %args) = @_;
564
    
565
    my $exclude_table = delete $args{exclude_table};
566
    croak qq/"$_" is wrong option/ for keys %args;
567
    
568
    my $column_info = [];
569
    $self->each_column(
570
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
571
        exclude_table => $exclude_table
572
    );
573
    
574
    return [
575
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
576
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
577
}
578

            
cleanup
yuki-kimoto authored on 2010-10-17
579
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
580
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
581
    
cleanup
yuki-kimoto authored on 2010-10-17
582
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
583
    my $param;
584
    $param = shift if @_ % 2;
585
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
586
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
587
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
588
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
589
    my $p = delete $args{param} || {};
590
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
591
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
592
    my $id = delete $args{id};
593
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
594
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
595
          "must be specified when id is specified " . _subname
596
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
597
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
598
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
599

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
600
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
601
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
602
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
603
        $param = $self->merge_param($id_param, $param);
604
    }
605

            
cleanup
Yuki Kimoto authored on 2011-04-02
606
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
607
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
608
    push @sql, "insert";
609
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
610
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
611
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
612
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
613
    
614
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
615
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
616
}
617

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
618
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
619
    my ($self, $param) = @_;
620
    
cleanup
Yuki Kimoto authored on 2011-04-02
621
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
622
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
623
    my @columns;
624
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
625
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
626
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
627
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
628
        my $column_quote = $self->_q($column);
629
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
630
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
631
        push @placeholders, ref $param->{$column} eq 'SCALAR'
632
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
633
    }
634
    
cleanup
Yuki Kimoto authored on 2011-04-02
635
    return '(' . join(', ', @columns) . ') ' . 'values ' .
636
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
637
}
638

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
639
sub include_model {
640
    my ($self, $name_space, $model_infos) = @_;
641
    
cleanup
Yuki Kimoto authored on 2011-04-02
642
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
643
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
644
    
645
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
646
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
647

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
704
sub map_param {
705
    my $self = shift;
706
    my $param = shift;
707
    my %map = @_;
708
    
709
    # Mapping
710
    my $map_param = {};
711
    foreach my $key (keys %map) {
712
        my $value_cb;
713
        my $condition;
714
        my $map_key;
715
        
716
        # Get mapping information
717
        if (ref $map{$key} eq 'ARRAY') {
718
            foreach my $some (@{$map{$key}}) {
719
                $map_key = $some unless ref $some;
720
                $condition = $some->{if} if ref $some eq 'HASH';
721
                $value_cb = $some if ref $some eq 'CODE';
722
            }
723
        }
724
        else {
725
            $map_key = $map{$key};
726
        }
727
        $value_cb ||= sub { $_[0] };
728
        $condition ||= sub { defined $_[0] && length $_[0] };
729

            
730
        # Map parameter
731
        my $value;
732
        if (ref $condition eq 'CODE') {
733
            $map_param->{$map_key} = $value_cb->($param->{$key})
734
              if $condition->($param->{$key});
735
        }
736
        elsif ($condition eq 'exists') {
737
            $map_param->{$map_key} = $value_cb->($param->{$key})
738
              if exists $param->{$key};
739
        }
740
        else { croak qq/Condition must be code reference or "exists" / . _subname }
741
    }
742
    
743
    return $map_param;
744
}
745

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
746
sub merge_param {
747
    my ($self, @params) = @_;
748
    
cleanup
Yuki Kimoto authored on 2011-04-02
749
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
750
    my $merge = {};
751
    foreach my $param (@params) {
752
        foreach my $column (keys %$param) {
753
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
754
            
755
            if (exists $merge->{$column}) {
756
                $merge->{$column} = [$merge->{$column}]
757
                  unless ref $merge->{$column} eq 'ARRAY';
758
                push @{$merge->{$column}},
759
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
760
            }
761
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
762
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
763
            }
764
        }
765
    }
766
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
767
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
768
}
769

            
cleanup
Yuki Kimoto authored on 2011-03-21
770
sub method {
771
    my $self = shift;
772
    
cleanup
Yuki Kimoto authored on 2011-04-02
773
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
774
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
775
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
776
    
777
    return $self;
778
}
779

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
780
sub model {
781
    my ($self, $name, $model) = @_;
782
    
cleanup
Yuki Kimoto authored on 2011-04-02
783
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
784
    if ($model) {
785
        $self->models->{$name} = $model;
786
        return $self;
787
    }
788
    
789
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
790
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
791
      unless $self->models->{$name};
792
    
cleanup
Yuki Kimoto authored on 2011-04-02
793
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
794
    return $self->models->{$name};
795
}
796

            
cleanup
Yuki Kimoto authored on 2011-03-21
797
sub mycolumn {
798
    my ($self, $table, $columns) = @_;
799
    
cleanup
Yuki Kimoto authored on 2011-04-02
800
    # Create column clause
801
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
802
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
803
    push @column, $self->_q($table) . "." . $self->_q($_) .
804
      " as " . $self->_q($_)
805
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
806
    
807
    return join (', ', @column);
808
}
809

            
added dbi_options attribute
kimoto authored on 2010-12-20
810
sub new {
811
    my $self = shift->SUPER::new(@_);
812
    
cleanup
Yuki Kimoto authored on 2011-04-02
813
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
814
    my @attrs = keys %$self;
815
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
816
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
817
          unless $self->can($attr);
818
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
819

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
820
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
821
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
822
        '?'     => \&DBIx::Custom::Tag::placeholder,
823
        '='     => \&DBIx::Custom::Tag::equal,
824
        '<>'    => \&DBIx::Custom::Tag::not_equal,
825
        '>'     => \&DBIx::Custom::Tag::greater_than,
826
        '<'     => \&DBIx::Custom::Tag::lower_than,
827
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
828
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
829
        'like'  => \&DBIx::Custom::Tag::like,
830
        'in'    => \&DBIx::Custom::Tag::in,
831
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
832
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
833
    };
834
    
835
    return $self;
836
}
837

            
838
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
839
sub not_exists { $not_exists }
840

            
841
sub order {
842
    my $self = shift;
843
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
844
}
845

            
cleanup
yuki-kimoto authored on 2010-10-17
846
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
847
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
848
    
849
    # Register filter
850
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
851
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
852
    
cleanup
Yuki Kimoto authored on 2011-04-02
853
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
854
}
packaging one directory
yuki-kimoto authored on 2009-11-16
855

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
989
sub setup_model {
990
    my $self = shift;
991
    
cleanup
Yuki Kimoto authored on 2011-04-02
992
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
993
    $self->each_column(
994
        sub {
995
            my ($self, $table, $column, $column_info) = @_;
996
            if (my $model = $self->models->{$table}) {
997
                push @{$model->columns}, $column;
998
            }
999
        }
1000
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1001
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1002
}
1003

            
update pod
Yuki Kimoto authored on 2011-08-10
1004
sub show_datatype {
1005
    my ($self, $table) = @_;
1006
    croak "Table name must be specified" unless defined $table;
1007
    print "$table\n";
1008
    
1009
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1010
    my $sth = $result->sth;
1011

            
1012
    my $columns = $sth->{NAME};
1013
    my $data_types = $sth->{TYPE};
1014
    
1015
    for (my $i = 0; $i < @$columns; $i++) {
1016
        my $column = $columns->[$i];
1017
        my $data_type = $data_types->[$i];
1018
        print "$column: $data_type\n";
1019
    }
1020
}
1021

            
1022
sub show_typename {
1023
    my ($self, $t) = @_;
1024
    croak "Table name must be specified" unless defined $t;
1025
    print "$t\n";
1026
    
1027
    $self->each_column(sub {
1028
        my ($self, $table, $column, $infos) = @_;
1029
        return unless $table eq $t;
1030
        my $typename = $infos->{TYPE_NAME};
1031
        print "$column: $typename\n";
1032
    });
1033
    
1034
    return $self;
1035
}
1036

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1037
sub show_tables {
1038
    my $self = shift;
1039
    
1040
    my %tables;
1041
    $self->each_table(sub { $tables{$_[1]}++ });
1042
    print join("\n", sort keys %tables) . "\n";
1043
    return $self;
1044
}
1045

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1046
sub type_rule {
1047
    my $self = shift;
1048
    
1049
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1050
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1051
        
1052
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1053
        foreach my $i (1 .. 2) {
1054
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1055
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1056
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1057
            $self->{type_rule} = $type_rule;
1058
            $self->{"_$into"} = {};
1059
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1060
                croak qq{type name of $into section must be lower case}
1061
                  if $type_name =~ /[A-Z]/;
1062
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1063
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1064
            $self->each_column(sub {
1065
                my ($dbi, $table, $column, $column_info) = @_;
1066
                
1067
                my $type_name = lc $column_info->{TYPE_NAME};
1068
                if ($type_rule->{$into} &&
1069
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1070
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1071
                    return unless exists $type_rule->{$into}->{$type_name};
1072
                    if  (defined $filter && ref $filter ne 'CODE') 
1073
                    {
1074
                        my $fname = $filter;
1075
                        croak qq{Filter "$fname" is not registered" } . _subname
1076
                          unless exists $self->filters->{$fname};
1077
                        
1078
                        $filter = $self->filters->{$fname};
1079
                    }
1080

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1081
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1082
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1083
                }
1084
            });
1085
        }
1086

            
1087
        # From
1088
        foreach my $i (1 .. 2) {
1089
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1090
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1091
                croak qq{data type of from$i section must be lower case or number}
1092
                  if $data_type =~ /[A-Z]/;
1093
                my $fname = $type_rule->{"from$i"}{$data_type};
1094
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1095
                    croak qq{Filter "$fname" is not registered" } . _subname
1096
                      unless exists $self->filters->{$fname};
1097
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1098
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1099
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1100
            }
1101
        }
1102
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1103
        return $self;
1104
    }
1105
    
1106
    return $self->{type_rule} || {};
1107
}
1108

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1112
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1113
    my $param;
1114
    $param = shift if @_ % 2;
1115
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1116
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1117
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1118
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1119
    my $p = delete $args{param} || {};
1120
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1121
    my $where = delete $args{where} || {};
1122
    my $where_param = delete $args{where_param} || {};
1123
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1124
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1125
    my $id = delete $args{id};
1126
    my $primary_key = delete $args{primary_key};
1127
    croak "update method primary_key option " .
1128
          "must be specified when id is specified " . _subname
1129
      if defined $id && !defined $primary_key;
1130
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1131
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1132

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

            
1136
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1137
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1138
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1139
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1140
        $where_clause = "where " . $where->[0];
1141
        $where_param = $where->[1];
1142
    }
1143
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1144
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1145
        $where_param = keys %$where_param
1146
                     ? $self->merge_param($where_param, $where->param)
1147
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1148
        
1149
        # String where
1150
        $where_clause = $where->to_string;
1151
    }
1152
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1153
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1154
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1155
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1156
    # Merge param
1157
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1158
    
cleanup
Yuki Kimoto authored on 2011-04-02
1159
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1160
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1161
    push @sql, "update";
1162
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1163
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1164
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1165
    
cleanup
Yuki Kimoto authored on 2011-01-27
1166
    # SQL
1167
    my $sql = join(' ', @sql);
1168
    
cleanup
yuki-kimoto authored on 2010-10-17
1169
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1170
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1171
}
1172

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1175
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1176
    my ($self, $param, $opt) = @_;
1177
    
cleanup
Yuki Kimoto authored on 2011-04-02
1178
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1179
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1180
    $tag = "set $tag" unless $opt->{no_set};
1181

            
cleanup
Yuki Kimoto authored on 2011-04-02
1182
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1183
}
1184

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1187
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1188
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1189
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1190
    
updated pod
Yuki Kimoto authored on 2011-06-21
1191
    # Cache
1192
    my $cache = $self->cache;
1193
    
1194
    # Query
1195
    my $query;
1196
    
1197
    # Get cached query
1198
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1199
        
updated pod
Yuki Kimoto authored on 2011-06-21
1200
        # Get query
1201
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1202
        
updated pod
Yuki Kimoto authored on 2011-06-21
1203
        # Create query
1204
        if ($q) {
1205
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1206
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1207
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1208
    }
1209
    
1210
    # Create query
1211
    unless ($query) {
1212

            
1213
        # Create query
1214
        my $builder = $self->query_builder;
1215
        $query = $builder->build_query($source);
1216

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

            
1223
        # Save query to cache
1224
        $self->cache_method->(
1225
            $self, $source,
1226
            {
1227
                sql     => $query->sql, 
1228
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1229
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1230
            }
1231
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1232
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1233

            
1234
    # Filter SQL
1235
    if ($sqlfilter) {
1236
        my $sql = $query->sql;
1237
        $sql = $sqlfilter->($sql);
1238
        $query->sql($sql);
1239
    }
1240
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1241
    # Save sql
1242
    $self->last_sql($query->sql);
1243
    
updated pod
Yuki Kimoto authored on 2011-06-21
1244
    # Prepare statement handle
1245
    my $sth;
1246
    eval { $sth = $self->dbh->prepare($query->{sql})};
1247
    
1248
    if ($@) {
1249
        $self->_croak($@, qq{. Following SQL is executed.\n}
1250
                        . qq{$query->{sql}\n} . _subname);
1251
    }
1252
    
1253
    # Set statement handle
1254
    $query->sth($sth);
1255
    
1256
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1257
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1258
    
1259
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1260
}
1261

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1312
sub _create_param_from_id {
1313
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1314
    
cleanup
Yuki Kimoto authored on 2011-06-08
1315
    # Create parameter
1316
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1317
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1318
        $id = [$id] unless ref $id;
1319
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1320
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1321
          unless !ref $id || ref $id eq 'ARRAY';
1322
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1323
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1324
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1325
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1326
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1327
        }
1328
    }
1329
    
cleanup
Yuki Kimoto authored on 2011-06-08
1330
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1331
}
1332

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1333
sub _connect {
1334
    my $self = shift;
1335
    
1336
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1337
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1338
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1339
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1340
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1341
    croak qq{"dsn" must be specified } . _subname
1342
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1343
    my $user        = $self->user;
1344
    my $password    = $self->password;
1345
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1346
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1347
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1348
    
cleanup
Yuki Kimoto authored on 2011-08-16
1349
    $dbi_option = {%{$self->default_dbi_option}, %$dbi_option};
1350
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1351
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1352
    my $dbh;
1353
    eval {
1354
        $dbh = DBI->connect(
1355
            $dsn,
1356
            $user,
1357
            $password,
1358
            $dbi_option
1359
        );
1360
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1361
    
1362
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1363
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1364
    
1365
    return $dbh;
1366
}
1367

            
cleanup
yuki-kimoto authored on 2010-10-17
1368
sub _croak {
1369
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1370
    
1371
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1372
    $append ||= "";
1373
    
1374
    # Verbose
1375
    if ($Carp::Verbose) { croak $error }
1376
    
1377
    # Not verbose
1378
    else {
1379
        
1380
        # Remove line and module infromation
1381
        my $at_pos = rindex($error, ' at ');
1382
        $error = substr($error, 0, $at_pos);
1383
        $error =~ s/\s+$//;
1384
        croak "$error$append";
1385
    }
1386
}
1387

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1390
sub _need_tables {
1391
    my ($self, $tree, $need_tables, $tables) = @_;
1392
    
cleanup
Yuki Kimoto authored on 2011-04-02
1393
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1394
    foreach my $table (@$tables) {
1395
        if ($tree->{$table}) {
1396
            $need_tables->{$table} = 1;
1397
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1398
        }
1399
    }
1400
}
1401

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1402
sub _push_join {
1403
    my ($self, $sql, $join, $join_tables) = @_;
1404
    
cleanup
Yuki Kimoto authored on 2011-04-02
1405
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1406
    return unless @$join;
1407
    
cleanup
Yuki Kimoto authored on 2011-04-02
1408
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1409
    my $tree = {};
1410
    for (my $i = 0; $i < @$join; $i++) {
1411
        
cleanup
Yuki Kimoto authored on 2011-07-28
1412
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1413
        my $join_clause;;
1414
        my $option;
1415
        if (ref $join->[$i] eq 'HASH') {
1416
            $join_clause = $join->[$i]->{clause};
1417
            $option = {table => $join->[$i]->{table}};
1418
        }
1419
        else {
1420
            $join_clause = $join->[$i];
1421
            $option = {};
1422
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1423

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1467
sub _quote {
1468
    my $self = shift;
1469
    
1470
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1471
         : defined $self->quote ? $self->quote
1472
         : '';
1473
}
1474

            
cleanup
Yuki Kimoto authored on 2011-07-29
1475
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1476
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1477
    
1478
    my $quote = $self->_quote;
1479
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1480
    my $p;
1481
    if (defined $quote && length $quote > 1) {
1482
        $p = substr($quote, 1, 1);
1483
    }
1484
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1485
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1486
    if ($quotemeta) {
1487
        $q = quotemeta($q);
1488
        $p = quotemeta($p);
1489
    }
1490
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1491
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1492
}
1493

            
cleanup
Yuki Kimoto authored on 2011-04-02
1494
sub _remove_duplicate_table {
1495
    my ($self, $tables, $main_table) = @_;
1496
    
1497
    # Remove duplicate table
1498
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1499
    delete $tables{$main_table} if $main_table;
1500
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1501
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1502
    if (my $q = $self->_quote) {
1503
        $q = quotemeta($q);
1504
        $_ =~ s/[$q]//g for @$new_tables;
1505
    }
1506

            
1507
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1508
}
1509

            
cleanup
Yuki Kimoto authored on 2011-04-02
1510
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1511
    my ($self, $source) = @_;
1512
    
cleanup
Yuki Kimoto authored on 2011-04-02
1513
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1514
    my $tables = [];
1515
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1516
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1517
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1518
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1519
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1520
    while ($source =~ /$table_re/g) {
1521
        push @$tables, $1;
1522
    }
1523
    
1524
    return $tables;
1525
}
1526

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

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

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

            
1646
# DEPRECATED!
1647
sub create_query {
1648
    warn "create_query is DEPRECATED! use query option of each method";
1649
    shift->_create_query(@_);
1650
}
1651

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

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1667
    # Arguments
1668
    my $primary_keys = delete $args{primary_key};
1669
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1670
    my $where = delete $args{where};
1671
    my $param = delete $args{param};
1672
    
1673
    # Check arguments
1674
    foreach my $name (keys %args) {
1675
        croak qq{"$name" is wrong option } . _subname
1676
          unless $SELECT_AT_ARGS{$name};
1677
    }
1678
    
1679
    # Table
1680
    croak qq{"table" option must be specified } . _subname
1681
      unless $args{table};
1682
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1683
    
1684
    # Create where parameter
1685
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1686
    
1687
    return $self->select(where => $where_param, %args);
1688
}
1689

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

            
1695
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1696
    
1697
    # Arguments
1698
    my $primary_keys = delete $args{primary_key};
1699
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1700
    my $where = delete $args{where};
1701
    
1702
    # Check arguments
1703
    foreach my $name (keys %args) {
1704
        croak qq{"$name" is wrong option } . _subname
1705
          unless $DELETE_AT_ARGS{$name};
1706
    }
1707
    
1708
    # Create where parameter
1709
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1710
    
1711
    return $self->delete(where => $where_param, %args);
1712
}
1713

            
cleanup
Yuki Kimoto authored on 2011-06-08
1714
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1715
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1716
sub update_at {
1717
    my $self = shift;
1718

            
1719
    warn "update_at is DEPRECATED! use update and id option instead";
1720
    
1721
    # Arguments
1722
    my $param;
1723
    $param = shift if @_ % 2;
1724
    my %args = @_;
1725
    my $primary_keys = delete $args{primary_key};
1726
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1727
    my $where = delete $args{where};
1728
    my $p = delete $args{param} || {};
1729
    $param  ||= $p;
1730
    
1731
    # Check arguments
1732
    foreach my $name (keys %args) {
1733
        croak qq{"$name" is wrong option } . _subname
1734
          unless $UPDATE_AT_ARGS{$name};
1735
    }
1736
    
1737
    # Create where parameter
1738
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1739
    
1740
    return $self->update(where => $where_param, param => $param, %args);
1741
}
1742

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1743
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1744
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1745
sub insert_at {
1746
    my $self = shift;
1747
    
1748
    warn "insert_at is DEPRECATED! use insert and id option instead";
1749
    
1750
    # Arguments
1751
    my $param;
1752
    $param = shift if @_ % 2;
1753
    my %args = @_;
1754
    my $primary_key = delete $args{primary_key};
1755
    $primary_key = [$primary_key] unless ref $primary_key;
1756
    my $where = delete $args{where};
1757
    my $p = delete $args{param} || {};
1758
    $param  ||= $p;
1759
    
1760
    # Check arguments
1761
    foreach my $name (keys %args) {
1762
        croak qq{"$name" is wrong option } . _subname
1763
          unless $INSERT_AT_ARGS{$name};
1764
    }
1765
    
1766
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1767
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1768
    $param = $self->merge_param($where_param, $param);
1769
    
1770
    return $self->insert(param => $param, %args);
1771
}
1772

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

            
1786
# DEPRECATED!
1787
sub register_tag_processor {
1788
    my $self = shift;
1789
    warn "register_tag_processor is DEPRECATED!";
1790
    # Merge tag
1791
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1792
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1793
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1794
}
1795

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1796
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1797
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1798
has dbi_options => sub { {} };
1799
has filter_check  => 1;
1800
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1801

            
cleanup
Yuki Kimoto authored on 2011-01-25
1802
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1803
sub default_bind_filter {
1804
    my $self = shift;
1805
    
cleanup
Yuki Kimoto authored on 2011-06-13
1806
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1807
    
cleanup
Yuki Kimoto authored on 2011-01-12
1808
    if (@_) {
1809
        my $fname = $_[0];
1810
        
1811
        if (@_ && !$fname) {
1812
            $self->{default_out_filter} = undef;
1813
        }
1814
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1815
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1816
              unless exists $self->filters->{$fname};
1817
        
1818
            $self->{default_out_filter} = $self->filters->{$fname};
1819
        }
1820
        return $self;
1821
    }
1822
    
1823
    return $self->{default_out_filter};
1824
}
1825

            
cleanup
Yuki Kimoto authored on 2011-01-25
1826
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1827
sub default_fetch_filter {
1828
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1829

            
cleanup
Yuki Kimoto authored on 2011-06-13
1830
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1831
    
1832
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1833
        my $fname = $_[0];
1834

            
cleanup
Yuki Kimoto authored on 2011-01-12
1835
        if (@_ && !$fname) {
1836
            $self->{default_in_filter} = undef;
1837
        }
1838
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1839
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1840
              unless exists $self->filters->{$fname};
1841
        
1842
            $self->{default_in_filter} = $self->filters->{$fname};
1843
        }
1844
        
1845
        return $self;
1846
    }
1847
    
many changed
Yuki Kimoto authored on 2011-01-23
1848
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1849
}
1850

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1851
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1852
sub insert_param_tag {
1853
    warn "insert_param_tag is DEPRECATED! " .
1854
         "use insert_param instead!";
1855
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1856
}
1857

            
1858
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1859
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1860
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1861
         "use update_param instead";
1862
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1863
}
cleanup
Yuki Kimoto authored on 2011-03-08
1864
# DEPRECATED!
1865
sub _push_relation {
1866
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1867
    
1868
    if (keys %{$relation || {}}) {
1869
        push @$sql, $need_where ? 'where' : 'and';
1870
        foreach my $rcolumn (keys %$relation) {
1871
            my $table1 = (split (/\./, $rcolumn))[0];
1872
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1873
            push @$tables, ($table1, $table2);
1874
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1875
        }
1876
    }
1877
    pop @$sql if $sql->[-1] eq 'and';    
1878
}
1879

            
1880
# DEPRECATED!
1881
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1882
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1883
    
1884
    if (keys %{$relation || {}}) {
1885
        foreach my $rcolumn (keys %$relation) {
1886
            my $table1 = (split (/\./, $rcolumn))[0];
1887
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1888
            my $table1_exists;
1889
            my $table2_exists;
1890
            foreach my $table (@$tables) {
1891
                $table1_exists = 1 if $table eq $table1;
1892
                $table2_exists = 1 if $table eq $table2;
1893
            }
1894
            unshift @$tables, $table1 unless $table1_exists;
1895
            unshift @$tables, $table2 unless $table2_exists;
1896
        }
1897
    }
1898
}
1899

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1902
=head1 NAME
1903

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

            
1906
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1907

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1908
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1909
    
1910
    # Connect
1911
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1912
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1913
        user => 'ken',
1914
        password => '!LFKD%$&',
1915
        dbi_option => {mysql_enable_utf8 => 1}
1916
    );
cleanup
yuki-kimoto authored on 2010-08-05
1917

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1918
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1919
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1920
    
1921
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1922
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1923
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1924
    
1925
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1926
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1927

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1977
Named place holder support
1978

            
1979
=item *
1980

            
cleanup
Yuki Kimoto authored on 2011-07-29
1981
Model support
1982

            
1983
=item *
1984

            
1985
Connection manager support
1986

            
1987
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1988

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

            
1993
=item *
1994

            
1995
Filtering by data type or column name(EXPERIMENTAL)
1996

            
1997
=item *
1998

            
1999
Create C<order by> clause flexibly(EXPERIMENTAL)
2000

            
2001
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2002

            
cleanup
Yuki Kimoto authored on 2011-07-29
2003
=head1 DOCUMENTATIONS
pod fix
Yuki Kimoto authored on 2011-01-21
2004

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2010
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2011
L<DBIx::Custom::Result>,
2012
L<DBIx::Custom::Query>,
2013
L<DBIx::Custom::Where>,
2014
L<DBIx::Custom::Model>,
2015
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2016

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

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

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

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

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

            
2030
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2031
        "dbi:mysql:database=$database",
2032
        $user,
2033
        $password,
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2034
        DBIx::Custom->new->default_dbi_option
2035
    );
2036
    
updated pod
Yuki Kimoto authored on 2011-06-21
2037
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2038

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

            
2042
    my $dbi = DBIx::Custom->connect(
2043
      dsn => $dsn, user => $user, password => $password, connector => 1);
2044
    
2045
    my $connector = $dbi->connector; # DBIx::Connector
2046

            
2047
Note that L<DBIx::Connector> must be installed.
2048

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

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

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

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

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

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

            
2064
=head2 C<default_dbi_option>
2065

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2072
    {
2073
        RaiseError => 1,
2074
        PrintError => 0,
2075
        AutoCommit => 1,
2076
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2077

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

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

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

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

            
2087
    my $last_sql = $dbi->last_sql;
2088
    $dbi = $dbi->last_sql($last_sql);
2089

            
2090
Get last successed SQL executed by C<execute> method.
2091

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2145
Separator whichi join table and column.
2146
This is used by C<column> and C<mycolumn> method.
2147

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

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

            
2153
Regex matching system table.
2154
this regex match is used by C<each_table> method and C<each_column> method
2155
System table is ignored.
2156
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2157
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2158
The performance is up.
2159

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

            
2162
    my $tag_parse = $dbi->tag_parse(0);
2163
    $dbi = $dbi->tag_parse;
2164

            
2165
Enable DEPRECATED tag parsing functionality, default to 1.
2166
If you want to disable tag parsing functionality, set to 0.
2167

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

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

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

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

            
2177
    my $user_column_info = $dbi->user_column_info;
2178
    $dbi = $dbi->user_column_info($user_column_info);
2179

            
2180
You can set the following data.
2181

            
2182
    [
2183
        {table => 'book', column => 'title', info => {...}},
2184
        {table => 'author', column => 'name', info => {...}}
2185
    ]
2186

            
2187
Usually, you can set return value of C<get_column_info>.
2188

            
2189
    my $user_column_info
2190
      = $dbi->get_column_info(exclude_table => qr/^system/);
2191
    $dbi->user_column_info($user_column_info);
2192

            
2193
If C<user_column_info> is set, C<each_column> use C<user_column_info>
2194
to find column info.
2195

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

            
2198
    my $user_table_info = $dbi->user_table_info;
2199
    $dbi = $dbi->user_table_info($user_table_info);
2200

            
2201
You can set the following data.
2202

            
2203
    [
2204
        {table => 'book', info => {...}},
2205
        {table => 'author', info => {...}}
2206
    ]
2207

            
2208
Usually, you can set return value of C<get_table_info>.
2209

            
2210
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2211
    $dbi->user_table_info($user_table_info);
2212

            
2213
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2214
to find table info.
2215

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2250
Create column clause. The follwoing column clause is created.
2251

            
2252
    book.author as "book.author",
2253
    book.title as "book.title"
2254

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2257
    # Separator is double underbar
2258
    $dbi->separator('__');
2259
    
2260
    book.author as "book__author",
2261
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2262

            
cleanup
Yuki Kimoto authored on 2011-06-13
2263
    # Separator is hyphen
2264
    $dbi->separator('-');
2265
    
2266
    book.author as "book-author",
2267
    book.title as "book-title"
2268
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2269
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2270

            
update pod
Yuki Kimoto authored on 2011-03-13
2271
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2272
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2273
        user => 'ken',
2274
        password => '!LFKD%$&',
2275
        dbi_option => {mysql_enable_utf8 => 1}
2276
    );
2277

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2284
=head2 create_model
2285

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

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

            
2297
   $dbi->model('book')->select(...);
2298

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

            
2301
    my $dbh = $dbi->dbh;
2302

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

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

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

            
2310
Execute delete statement.
2311

            
2312
The following opitons are available.
2313

            
2314
=over 4
2315

            
2316
=item C<append>
2317

            
2318
Same as C<select> method's C<append> option.
2319

            
2320
=item C<filter>
2321

            
2322
Same as C<execute> method's C<filter> option.
2323

            
2324
=item C<id>
2325

            
2326
    id => 4
2327
    id => [4, 5]
2328

            
2329
ID corresponding to C<primary_key>.
2330
You can delete rows by C<id> and C<primary_key>.
2331

            
2332
    $dbi->delete(
2333
        parimary_key => ['id1', 'id2'],
2334
        id => [4, 5],
2335
        table => 'book',
2336
    );
2337

            
2338
The above is same as the followin one.
2339

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

            
2342
=item C<prefix>
2343

            
2344
    prefix => 'some'
2345

            
2346
prefix before table name section.
2347

            
2348
    delete some from book
2349

            
2350
=item C<query>
2351

            
2352
Same as C<execute> method's C<query> option.
2353

            
2354
=item C<sqlfilter EXPERIMENTAL>
2355

            
2356
Same as C<execute> method's C<sqlfilter> option.
2357

            
2358
=item C<table>
2359

            
2360
    table => 'book'
2361

            
2362
Table name.
2363

            
2364
=item C<where>
2365

            
2366
Same as C<select> method's C<where> option.
2367

            
2368
=item C<primary_key>
2369

            
2370
See C<id> option.
2371

            
2372
=item C<bind_type>
2373

            
2374
Same as C<execute> method's C<bind_type> option.
2375

            
2376
=item C<type_rule_off> EXPERIMENTAL
2377

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

            
2380
=item C<type_rule1_off> EXPERIMENTAL
2381

            
2382
    type_rule1_off => 1
2383

            
2384
Same as C<execute> method's C<type_rule1_off> option.
2385

            
2386
=item C<type_rule2_off> EXPERIMENTAL
2387

            
2388
    type_rule2_off => 1
2389

            
2390
Same as C<execute> method's C<type_rule2_off> option.
2391

            
2392
=back
2393

            
2394
=head2 C<delete_all>
2395

            
2396
    $dbi->delete_all(table => $table);
2397

            
2398
Execute delete statement for all rows.
2399
Options is same as C<delete>.
2400

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

            
2403
    $dbi->each_column(
2404
        sub {
2405
            my ($dbi, $table, $column, $column_info) = @_;
2406
            
2407
            my $type = $column_info->{TYPE_NAME};
2408
            
2409
            if ($type eq 'DATE') {
2410
                # ...
2411
            }
2412
        }
2413
    );
2414

            
2415
Iterate all column informations of all table from database.
2416
Argument is callback when one column is found.
2417
Callback receive four arguments, dbi object, table name,
2418
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2419

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

            
2422
    $dbi->each_table(
2423
        sub {
2424
            my ($dbi, $table, $table_info) = @_;
2425
            
2426
            my $table_name = $table_info->{TABLE_NAME};
2427
        }
2428
    );
2429

            
2430
Iterate all table informationsfrom database.
2431
Argument is callback when one table is found.
2432
Callback receive three arguments, dbi object, table name,
2433
table information.
2434

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

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

            
2442
    my $result = $dbi->execute(
2443
      "select * from book where title = :book.title and author like :book.author",
2444
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2445
    );
2446

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2453
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2454
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2455
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2456
    select * from book where title = :title and author like :author
2457
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2458
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2459
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2460

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2464
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2465
    select * from book where :title{=} and :author{like}
2466
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2467
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2468
    select * from where title = ? and author like ?;
2469

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

            
2474
    select * from where title = "aa\\:bb";
2475

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

            
2478
=over 4
2479

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

            
2482
Specify database bind data type.
2483

            
2484
    bind_type => [image => DBI::SQL_BLOB]
2485
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2486

            
2487
This is used to bind parameter by C<bind_param> of statment handle.
2488

            
2489
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2490

            
update pod
Yuki Kimoto authored on 2011-03-13
2491
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2492
    
2493
    filter => {
2494
        title  => sub { uc $_[0] }
2495
        author => sub { uc $_[0] }
2496
    }
update pod
Yuki Kimoto authored on 2011-03-13
2497

            
updated pod
Yuki Kimoto authored on 2011-06-09
2498
    # Filter name
2499
    filter => {
2500
        title  => 'upper_case',
2501
        author => 'upper_case'
2502
    }
2503
        
2504
    # At once
2505
    filter => [
2506
        [qw/title author/]  => sub { uc $_[0] }
2507
    ]
2508

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

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

            
2516
    query => 1
2517

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

            
2521
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2522
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2523
    my $columns = $query->columns;
2524
    
2525
If you want to execute SQL fast, you can do the following way.
2526

            
2527
    my $query;
2528
    foreach my $row (@$rows) {
2529
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2530
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2531
    }
2532

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

            
2536
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
2537
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2538
    
2539
    my $query;
2540
    my $sth;
2541
    foreach my $row (@$rows) {
2542
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2543
      $sth ||= $query->sth;
2544
      $sth->execute(map { $row->{$_} } sort keys %$row);
2545
    }
2546

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

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

            
2553
SQL filter function.
2554

            
2555
    sqlfilter => $code_ref
2556

            
2557
This option is generally for Oracle and SQL Server paging process.
2558
    
2559
    my $limit = sub {
2560
        my ($sql, $count, $offset) = @_;
2561
        
2562
        my $min = $offset + 1;
2563
        my $max = $offset + $count;
2564
        
2565
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2566
        
2567
        return $sql;
2568
    }
2569
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2570
        my $sql = shift;
2571
        return $limit->($sql, 100, 50);
2572
    })
2573

            
updated pod
Yuki Kimoto authored on 2011-06-09
2574
=item C<table>
2575
    
2576
    table => 'author'
2577

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2585
    # Same
2586
    $dbi->execute(
2587
      "select * from book where title = :book.title and author = :book.author",
2588
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2589

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

            
2592
    table_alias => {user => 'hiker'}
2593

            
2594
Table alias. Key is real table name, value is alias table name.
2595
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2596
on alias table name.
2597

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

            
2600
    type_rule_off => 1
2601

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

            
2604
=item C<type_rule1_off> EXPERIMENTAL
2605

            
2606
    type_rule1_off => 1
2607

            
2608
Turn C<into1> type rule off.
2609

            
2610
=item C<type_rule2_off> EXPERIMENTAL
2611

            
2612
    type_rule2_off => 1
2613

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2642
=head2 C<insert>
2643

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

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

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

            
2652
    {date => \"NOW()"}
2653

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

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

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

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

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

            
2664
Same as C<execute> method's C<bind_type> option.
2665

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

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

            
2670
=item C<id>
2671

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

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

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

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

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

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

            
2694
    prefix => 'or replace'
2695

            
2696
prefix before table name section
2697

            
2698
    insert or replace into book
2699

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

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

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

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

            
2709
Same as C<execute> method's C<query> option.
2710

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

            
2713
Same as C<execute> method's C<sqlfilter> option.
2714

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

            
2717
    table => 'book'
2718

            
2719
Table name.
2720

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

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

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

            
2727
    type_rule1_off => 1
2728

            
2729
Same as C<execute> method's C<type_rule1_off> option.
2730

            
2731
=item C<type_rule2_off> EXPERIMENTAL
2732

            
2733
    type_rule2_off => 1
2734

            
2735
Same as C<execute> method's C<type_rule2_off> option.
2736

            
update pod
Yuki Kimoto authored on 2011-03-13
2737
=back
2738

            
2739
=over 4
2740

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2756
    lib / MyModel.pm
2757
        / MyModel / book.pm
2758
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2759

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2773
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2774
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2775
    
2776
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2777

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

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

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

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

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

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

            
2796
    my $map_param = $dbi->map_param(
2797
        {id => 1, authro => 'Ken', price => 1900},
2798
        'id' => 'book.id',
2799
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2800
        'price' => [
2801
            'book.price', {if => sub { length $_[0] }}
2802
        ]
2803
    );
2804

            
2805
Map paramters to other key and value. First argument is original
2806
parameter. this is hash reference. Rest argument is mapping.
2807
By default, Mapping is done if the value length is not zero.
2808

            
2809
=over 4
2810

            
2811
=item Key mapping
2812

            
2813
    'id' => 'book.id'
2814

            
2815
This is only key mapping. Value is same as original one.
2816

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

            
2819
=item Key and value mapping
2820

            
2821
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2822

            
2823
This is key and value mapping. Frist element of array reference
2824
is mapped key name, second element is code reference to map the value.
2825

            
2826
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2827
      if value length is not zero.
2828

            
2829
=item Condition
2830

            
2831
    'price' => ['book.price', {if => 'exists'}]
2832
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2833
    'price' => ['book.price', {if => sub { defined shift }}]
2834

            
2835
If you need condition, you can sepecify it. this is code reference
2836
or 'exists'. By default, condition is the following one.
2837

            
2838
    sub { defined $_[0] && length $_[0] }
2839

            
2840
=back
2841

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

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

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

            
2848
    {key1 => [1, 1], key2 => 2}
2849

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

            
2852
    $dbi->method(
2853
        update_or_insert => sub {
2854
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2855
            
2856
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2857
        },
2858
        find_or_create   => sub {
2859
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2860
            
2861
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2862
        }
2863
    );
2864

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

            
2867
    $dbi->update_or_insert;
2868
    $dbi->find_or_create;
2869

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

            
2872
    my $model = $dbi->model('book');
2873

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

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

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

            
2880
Create column clause for myself. The follwoing column clause is created.
2881

            
2882
    book.author as author,
2883
    book.title as title
2884

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2887
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2888
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2889
        user => 'ken',
2890
        password => '!LFKD%$&',
2891
        dbi_option => {mysql_enable_utf8 => 1}
2892
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2893

            
2894
Create a new L<DBIx::Custom> object.
2895

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

            
2898
    my $not_exists = $dbi->not_exists;
2899

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

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

            
2905
    my $order = $dbi->order;
2906

            
2907
Create a new L<DBIx::Custom::Order> object.
2908

            
cleanup
yuki-kimoto authored on 2010-10-17
2909
=head2 C<register_filter>
2910

            
update pod
Yuki Kimoto authored on 2011-03-13
2911
    $dbi->register_filter(
2912
        # Time::Piece object to database DATE format
2913
        tp_to_date => sub {
2914
            my $tp = shift;
2915
            return $tp->strftime('%Y-%m-%d');
2916
        },
2917
        # database DATE format to Time::Piece object
2918
        date_to_tp => sub {
2919
           my $date = shift;
2920
           return Time::Piece->strptime($date, '%Y-%m-%d');
2921
        }
2922
    );
cleanup
yuki-kimoto authored on 2010-10-17
2923
    
update pod
Yuki Kimoto authored on 2011-03-13
2924
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2925

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

            
2928
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2929
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2930
            date => sub { ... },
2931
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2932
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2933
        into2 => {
2934
            date => sub { ... },
2935
            datetime => sub { ... }
2936
        },
2937
        from1 => {
2938
            # DATE
2939
            9 => sub { ... },
2940
            # DATETIME or TIMESTAMP
2941
            11 => sub { ... },
2942
        }
2943
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2944
            # DATE
2945
            9 => sub { ... },
2946
            # DATETIME or TIMESTAMP
2947
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2948
        }
2949
    );
2950

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2966
=over 4
2967

            
2968
=item 1. column name
2969

            
2970
    issue_date
2971
    issue_datetime
2972

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

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

            
2977
    book.issue_date
2978
    book.issue_datetime
2979

            
2980
=back
2981

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

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

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

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

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

            
2994
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2995
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2996
            [qw/DATE DATETIME/] => sub { ... },
2997
        ],
2998
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2999

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3002
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3003
        table  => 'book',
3004
        column => ['author', 'title'],
3005
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3006
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3007
    
updated document
Yuki Kimoto authored on 2011-06-09
3008
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3009

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

            
3012
=over 4
3013

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

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

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

            
3020
=item C<bind_type>
3021

            
3022
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3023
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3024
=item C<column>
3025
    
updated document
Yuki Kimoto authored on 2011-06-09
3026
    column => 'author'
3027
    column => ['author', 'title']
3028

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3037
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3038
        {book => [qw/author title/]},
3039
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3040
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3041

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

            
3044
    book.author as "book.author",
3045
    book.title as "book.title",
3046
    person.name as "person.name",
3047
    person.age as "person.age"
3048

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

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

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

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

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

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

            
3064
=item C<id>
3065

            
3066
    id => 4
3067
    id => [4, 5]
3068

            
3069
ID corresponding to C<primary_key>.
3070
You can select rows by C<id> and C<primary_key>.
3071

            
3072
    $dbi->select(
3073
        parimary_key => ['id1', 'id2'],
3074
        id => [4, 5],
3075
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3076
    );
3077

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3080
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3081
        where => {id1 => 4, id2 => 5},
3082
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3083
    );
3084
    
updated document
Yuki Kimoto authored on 2011-06-09
3085
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3086

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

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

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

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

            
3099
    prefix => 'SQL_CALC_FOUND_ROWS'
3100

            
3101
Prefix of column cluase
3102

            
3103
    select SQL_CALC_FOUND_ROWS title, author from book;
3104

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

            
3107
    join => [
3108
        'left outer join company on book.company_id = company_id',
3109
        'left outer join location on company.location_id = location.id'
3110
    ]
3111
        
3112
Join clause. If column cluase or where clause contain table name like "company.name",
3113
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3114

            
3115
    $dbi->select(
3116
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3117
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3118
        where => {'company.name' => 'Orange'},
3119
        join => [
3120
            'left outer join company on book.company_id = company.id',
3121
            'left outer join location on company.location_id = location.id'
3122
        ]
3123
    );
3124

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3128
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3129
    from book
3130
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3131
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3132

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

            
3136
    $dbi->select(
3137
        table => 'book',
3138
        column => ['company.location_id as location_id'],
3139
        where => {'company.name' => 'Orange'},
3140
        join => [
3141
            {
3142
                clause => 'left outer join location on company.location_id = location.id',
3143
                table => ['company', 'location']
3144
            }
3145
        ]
3146
    );
3147

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3167
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3168

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

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

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

            
3175
    type_rule1_off => 1
3176

            
3177
Same as C<execute> method's C<type_rule1_off> option.
3178

            
3179
=item C<type_rule2_off> EXPERIMENTAL
3180

            
3181
    type_rule2_off => 1
3182

            
3183
Same as C<execute> method's C<type_rule2_off> option.
3184

            
updated document
Yuki Kimoto authored on 2011-06-09
3185
=item C<where>
3186
    
3187
    # Hash refrence
3188
    where => {author => 'Ken', 'title' => 'Perl'}
3189
    
3190
    # DBIx::Custom::Where object
3191
    where => $dbi->where(
3192
        clause => ['and', 'author = :author', 'title like :title'],
3193
        param  => {author => 'Ken', title => '%Perl%'}
3194
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3195
    
3196
    # Array reference 1 (array reference, hash referenc). same as above
3197
    where => [
3198
        ['and', 'author = :author', 'title like :title'],
3199
        {author => 'Ken', title => '%Perl%'}
3200
    ];    
3201
    
3202
    # Array reference 2 (String, hash reference)
3203
    where => [
3204
        'title like :title',
3205
        {title => '%Perl%'}
3206
    ]
3207
    
3208
    # String
3209
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3210

            
updated document
Yuki Kimoto authored on 2011-06-09
3211
Where clause.
3212
    
improved pod
Yuki Kimoto authored on 2011-04-19
3213
=item C<wrap> EXPERIMENTAL
3214

            
3215
Wrap statement. This is array reference.
3216

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

            
3219
This option is for Oracle and SQL Server paging process.
3220

            
update pod
Yuki Kimoto authored on 2011-03-12
3221
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3222

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

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

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

            
3229
If you want to set constant value to row data, use scalar reference
3230
as parameter value.
3231

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3236
=over 4
3237

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

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

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

            
3244
Same as C<execute> method's C<bind_type> option.
3245

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3252
    id => 4
3253
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3254

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3258
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3259
        {title => 'Perl', author => 'Ken'}
3260
        parimary_key => ['id1', 'id2'],
3261
        id => [4, 5],
3262
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3263
    );
update pod
Yuki Kimoto authored on 2011-03-13
3264

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3267
    $dbi->update(
3268
        {title => 'Perl', author => 'Ken'}
3269
        where => {id1 => 4, id2 => 5},
3270
        table => 'book'
3271
    );
update pod
Yuki Kimoto authored on 2011-03-13
3272

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

            
3275
    prefix => 'or replace'
3276

            
3277
prefix before table name section
3278

            
3279
    update or replace book
3280

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

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

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

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

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

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

            
3294
Same as C<execute> method's C<sqlfilter> option.
3295

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

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

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

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

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

            
3306
=item C<type_rule1_off> EXPERIMENTAL
3307

            
3308
    type_rule1_off => 1
3309

            
3310
Same as C<execute> method's C<type_rule1_off> option.
3311

            
3312
=item C<type_rule2_off> EXPERIMENTAL
3313

            
3314
    type_rule2_off => 1
3315

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

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

            
3320
Same as C<select> method's C<where> option.
3321

            
updated pod
Yuki Kimoto authored on 2011-06-08
3322
=back
update pod
Yuki Kimoto authored on 2011-03-13
3323

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

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

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

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

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

            
3335
Create update parameter tag.
3336

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

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

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

            
3346
Create a new L<DBIx::Custom::Where> object.
3347

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

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

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

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
3355
=head1 ENVIRONMENT VARIABLE
3356

            
3357
=head2 C<DBIX_CUSTOM_DEBUG>
3358

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

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

            
3364
    $dbi->show_datatype($table);
3365

            
3366
Show data type of the columns of specified table.
3367

            
3368
    book
3369
    title: 5
3370
    issue_date: 91
3371

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

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

            
3376
    $dbi->show_tables;
3377

            
3378
Show tables.
3379

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

            
3382
    $dbi->show_typename($table);
3383

            
3384
Show type name of the columns of specified table.
3385

            
3386
    book
3387
    title: varchar
3388
    issue_date: date
3389

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

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

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3396
=head1 DEPRECATED FUNCTIONALITIES
3397

            
3398
L<DBIx::Custom>
3399

            
3400
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3401
    data_source # will be removed at 2017/1/1
3402
    dbi_options # will be removed at 2017/1/1
3403
    filter_check # will be removed at 2017/1/1
3404
    reserved_word_quote # will be removed at 2017/1/1
3405
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3406
    
3407
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3408
    create_query # will be removed at 2017/1/1
3409
    apply_filter # will be removed at 2017/1/1
3410
    select_at # will be removed at 2017/1/1
3411
    delete_at # will be removed at 2017/1/1
3412
    update_at # will be removed at 2017/1/1
3413
    insert_at # will be removed at 2017/1/1
3414
    register_tag # will be removed at 2017/1/1
3415
    default_bind_filter # will be removed at 2017/1/1
3416
    default_fetch_filter # will be removed at 2017/1/1
3417
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3418
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3419
    register_tag_processor # will be removed at 2017/1/1
3420
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3421
    
3422
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3423
    select method relation option # will be removed at 2017/1/1
3424
    select method param option # will be removed at 2017/1/1
3425
    select method column option [COLUMN, as => ALIAS] format
3426
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3427
    
3428
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3429
    execute("select * from {= title}"); # execute method's
3430
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3431
                                        # will be removed at 2017/1/1
3432
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3433

            
3434
L<DBIx::Custom::Model>
3435

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3436
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3437
    filter # will be removed at 2017/1/1
3438
    name # will be removed at 2017/1/1
3439
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3440

            
3441
L<DBIx::Custom::Query>
3442
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3443
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3444
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3445
    table # will be removed at 2017/1/1
3446
    filters # will be removed at 2017/1/1
3447
    
3448
    # Methods
3449
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3450

            
3451
L<DBIx::Custom::QueryBuilder>
3452
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3453
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3454
    tags # will be removed at 2017/1/1
3455
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3456
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3457
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3458
    register_tag # will be removed at 2017/1/1
3459
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3460
    
3461
    # Others
3462
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3463
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3464

            
3465
L<DBIx::Custom::Result>
3466
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3467
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3468
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3469
    
3470
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3471
    end_filter # will be removed at 2017/1/1
3472
    remove_end_filter # will be removed at 2017/1/1
3473
    remove_filter # will be removed at 2017/1/1
3474
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3475

            
3476
L<DBIx::Custom::Tag>
3477

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

            
3480
=head1 BACKWORD COMPATIBLE POLICY
3481

            
3482
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3483
except for attribute method.
3484
You can check all DEPRECATED functionalities by document.
3485
DEPRECATED functionality is removed after five years,
3486
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
3487
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3488

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

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

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

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

            
3497
C<< <kimoto.yuki at gmail.com> >>
3498

            
3499
L<http://github.com/yuki-kimoto/DBIx-Custom>
3500

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3501
=head1 AUTHOR
3502

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

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

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

            
3509
This program is free software; you can redistribute it and/or modify it
3510
under the same terms as Perl itself.
3511

            
3512
=cut