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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1998
=item *
1999

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

            
2002
=item *
2003

            
2004
Connection manager support
2005

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

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

            
2012
=item *
2013

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

            
2016
=item *
2017

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2083
=head2 C<default_dbi_option>
2084

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2199
You can set the following data.
2200

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

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

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

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

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

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

            
2220
You can set the following data.
2221

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2307
Get rows count.
2308

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

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

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

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

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

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

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

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

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

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

            
2337
Execute delete statement.
2338

            
2339
The following opitons are available.
2340

            
2341
=over 4
2342

            
2343
=item C<append>
2344

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

            
2347
=item C<filter>
2348

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

            
2351
=item C<id>
2352

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

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

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

            
2365
The above is same as the followin one.
2366

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

            
2369
=item C<prefix>
2370

            
2371
    prefix => 'some'
2372

            
2373
prefix before table name section.
2374

            
2375
    delete some from book
2376

            
2377
=item C<query>
2378

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

            
2381
=item C<sqlfilter EXPERIMENTAL>
2382

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

            
2385
=item C<table>
2386

            
2387
    table => 'book'
2388

            
2389
Table name.
2390

            
2391
=item C<where>
2392

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

            
2395
=item C<primary_key>
2396

            
2397
See C<id> option.
2398

            
2399
=item C<bind_type>
2400

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

            
2403
=item C<type_rule_off> EXPERIMENTAL
2404

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

            
2407
=item C<type_rule1_off> EXPERIMENTAL
2408

            
2409
    type_rule1_off => 1
2410

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

            
2413
=item C<type_rule2_off> EXPERIMENTAL
2414

            
2415
    type_rule2_off => 1
2416

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

            
2419
=back
2420

            
2421
=head2 C<delete_all>
2422

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2505
=over 4
2506

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

            
2509
Specify database bind data type.
2510

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

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

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

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

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

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

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

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

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

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

            
2556
The above is same as the followin one.
2557

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

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

            
2565
    query => 1
2566

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

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

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

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

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

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

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

            
2602
See C<id> option.
2603

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

            
2606
SQL filter function.
2607

            
2608
    sqlfilter => $code_ref
2609

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

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

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

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

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

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

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

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

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

            
2653
    type_rule_off => 1
2654

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

            
2657
=item C<type_rule1_off> EXPERIMENTAL
2658

            
2659
    type_rule1_off => 1
2660

            
2661
Turn C<into1> type rule off.
2662

            
2663
=item C<type_rule2_off> EXPERIMENTAL
2664

            
2665
    type_rule2_off => 1
2666

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2723
=item C<id>
2724

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

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

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

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

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

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

            
2747
    prefix => 'or replace'
2748

            
2749
prefix before table name section
2750

            
2751
    insert or replace into book
2752

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

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

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

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

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

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

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

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

            
2770
    table => 'book'
2771

            
2772
Table name.
2773

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

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

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

            
2780
    type_rule1_off => 1
2781

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

            
2784
=item C<type_rule2_off> EXPERIMENTAL
2785

            
2786
    type_rule2_off => 1
2787

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

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

            
2792
=over 4
2793

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2862
=over 4
2863

            
2864
=item Key mapping
2865

            
2866
    'id' => 'book.id'
2867

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

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

            
2872
=item Key and value mapping
2873

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

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

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

            
2882
=item Condition
2883

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

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

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

            
2893
=back
2894

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3021
=item 1. column name
3022

            
3023
    issue_date
3024
    issue_datetime
3025

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

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

            
3030
    book.issue_date
3031
    book.issue_datetime
3032

            
3033
=back
3034

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

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

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

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

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

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

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

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

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

            
3065
=over 4
3066

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

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

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

            
3073
=item C<bind_type>
3074

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3117
=item C<id>
3118

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

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

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

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

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

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

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

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

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

            
3152
    prefix => 'SQL_CALC_FOUND_ROWS'
3153

            
3154
Prefix of column cluase
3155

            
3156
    select SQL_CALC_FOUND_ROWS title, author from book;
3157

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3228
    type_rule1_off => 1
3229

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

            
3232
=item C<type_rule2_off> EXPERIMENTAL
3233

            
3234
    type_rule2_off => 1
3235

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

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

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

            
3268
Wrap statement. This is array reference.
3269

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3328
    prefix => 'or replace'
3329

            
3330
prefix before table name section
3331

            
3332
    update or replace book
3333

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

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

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

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

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

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

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

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

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

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

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

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

            
3359
=item C<type_rule1_off> EXPERIMENTAL
3360

            
3361
    type_rule1_off => 1
3362

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

            
3365
=item C<type_rule2_off> EXPERIMENTAL
3366

            
3367
    type_rule2_off => 1
3368

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

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

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

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

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

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

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

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

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

            
3388
Create update parameter tag.
3389

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

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

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

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

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

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

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

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

            
3410
=head2 C<DBIX_CUSTOM_DEBUG>
3411

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

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

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

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

            
3421
    book
3422
    title: 5
3423
    issue_date: 91
3424

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

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

            
3429
    $dbi->show_tables;
3430

            
3431
Show tables.
3432

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

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

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

            
3439
    book
3440
    title: varchar
3441
    issue_date: date
3442

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

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

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

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

            
3451
L<DBIx::Custom>
3452

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3565
=cut