DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
2947 lines | 74.211kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
2

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
3
our $VERSION = '0.1690';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
5

            
updatedd pod
Yuki Kimoto authored on 2011-06-12
6
use Object::Simple -base;
many change
yuki-kimoto authored on 2010-02-11
7

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
22
our @COMMON_ARGS = qw/table query filter type id primary_key type_rule_off/;
cleanup
Yuki Kimoto authored on 2011-03-21
23

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

            
added helper method
yuki-kimoto authored on 2010-10-17
61
our $AUTOLOAD;
62
sub AUTOLOAD {
63
    my $self = shift;
64

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
68
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
69
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
70
    if (my $method = $self->{_methods}->{$mname}) {
71
        return $self->$method(@_)
72
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
73
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
74
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
75
    }
76
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
77
        croak qq{Can't locate object method "$mname" via "$package" }
78
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
79
    }
added helper method
yuki-kimoto authored on 2010-10-17
80
}
81

            
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
82
sub apply_filter { shift->_apply_filter(@_) }
83

            
84
sub _apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
85
    my ($self, $table, @cinfos) = @_;
86

            
87
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
88
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
89
    $self->{filter}{out} ||= {};
90
    $self->{filter}{in} ||= {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
91
    $self->{filter}{end} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
92
    
cleanup
Yuki Kimoto authored on 2011-04-02
93
    # Usage
many changed
Yuki Kimoto authored on 2011-01-23
94
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
95
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
96
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
cleanup
Yuki Kimoto authored on 2011-04-02
97
    
98
    # Apply filter
many changed
Yuki Kimoto authored on 2011-01-23
99
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
100
        
many changed
Yuki Kimoto authored on 2011-01-23
101
        # Column
102
        my $column = $cinfos[$i];
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
103
        if (ref $column eq 'ARRAY') {
104
            foreach my $c (@$column) {
105
                push @cinfos, $c, $cinfos[$i + 1];
106
            }
107
            next;
108
        }
109
        
cleanup
Yuki Kimoto authored on 2011-04-02
110
        # Filter infomation
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
111
        my $finfo = $cinfos[$i + 1] || {};
cleanup
Yuki Kimoto authored on 2011-04-25
112
        croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
113
          unless  ref $finfo eq 'HASH';
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
114
        foreach my $ftype (keys %$finfo) {
cleanup
Yuki Kimoto authored on 2011-04-25
115
            croak "$usage (table: $table) " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
116
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
117
        }
118
        
cleanup
Yuki Kimoto authored on 2011-04-02
119
        # Set filters
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
120
        foreach my $way (qw/in out end/) {
cleanup
Yuki Kimoto authored on 2011-04-02
121
        
122
            # Filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
123
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
124
            
cleanup
Yuki Kimoto authored on 2011-04-02
125
            # Filter state
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
126
            my $state = !exists $finfo->{$way} ? 'not_exists'
127
                      : !defined $filter        ? 'not_defined'
128
                      : ref $filter eq 'CODE'   ? 'code'
129
                      : 'name';
130
            
cleanup
Yuki Kimoto authored on 2011-04-02
131
            # Filter is not exists
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
132
            next if $state eq 'not_exists';
133
            
cleanup
Yuki Kimoto authored on 2011-04-02
134
            # Check filter name
cleanup
Yuki Kimoto authored on 2011-04-25
135
            croak qq{Filter "$filter" is not registered } . _subname
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
136
              if  $state eq 'name'
137
               && ! exists $self->filters->{$filter};
138
            
cleanup
Yuki Kimoto authored on 2011-04-02
139
            # Set filter
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
140
            my $f = $state eq 'not_defined' ? undef
141
                  : $state eq 'code'        ? $filter
142
                  : $self->filters->{$filter};
143
            $self->{filter}{$way}{$table}{$column} = $f;
144
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
145
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
146
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
147
    }
148
    
many changed
Yuki Kimoto authored on 2011-01-23
149
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
150
}
151

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
152
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
153
    my ($self, $param) = @_;
154
    
155
    # Create set tag
156
    my @params;
157
    my $safety = $self->safety_character;
158
    my $q = $self->reserved_word_quote;
159
    foreach my $column (keys %$param) {
160
        croak qq{"$column" is not safety column name } . _subname
161
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
162
        my $column_quote = "$q$column$q";
163
        $column_quote =~ s/\./$q.$q/;
164
        push @params, "$column_quote = :$column";
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
165
    }
166
    my $tag = join(', ', @params);
167
    
168
    return $tag;
169
}
170

            
added EXPERIMENTAL col metho...
Yuki Kimoto authored on 2011-06-08
171
sub col {
172
    my ($self, $table, $columns) = @_;
173
    
174
    # Reserved word quote
175
    my $q = $self->reserved_word_quote;
176
    
177
    # Column clause
178
    my @column;
179
    $columns ||= [];
180
    push @column, "$q$table$q.$q$_$q as $q${table}.$_$q" for @$columns;
181
    
182
    return join (', ', @column);
183
}
184

            
cleanup
Yuki Kimoto authored on 2011-03-21
185
sub column {
186
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
187
    
cleanup
Yuki Kimoto authored on 2011-04-02
188
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
189
    my $q = $self->reserved_word_quote;
190
    
cleanup
Yuki Kimoto authored on 2011-04-02
191
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
192
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
193
    $columns ||= [];
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
194
    push @column, "$q$table$q.$q$_$q as $q${table}__$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
195
    
196
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
197
}
198

            
packaging one directory
yuki-kimoto authored on 2009-11-16
199
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
200
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
201
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
202
    # Connect
203
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
204
    
packaging one directory
yuki-kimoto authored on 2009-11-16
205
    return $self;
206
}
207

            
cleanup
yuki-kimoto authored on 2010-10-17
208
sub create_query {
209
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
210
    
cleanup
yuki-kimoto authored on 2010-10-17
211
    # Cache
212
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
213
    
cleanup
Yuki Kimoto authored on 2011-04-02
214
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
215
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
216
    
217
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
218
    if ($cache) {
219
        
220
        # Get query
221
        my $q = $self->cache_method->($self, $source);
222
        
223
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
224
        if ($q) {
225
            $query = DBIx::Custom::Query->new($q);
226
            $query->filters($self->filters);
227
        }
cleanup
yuki-kimoto authored on 2010-10-17
228
    }
229
    
cleanup
Yuki Kimoto authored on 2011-04-02
230
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
231
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
232

            
cleanup
yuki-kimoto authored on 2010-10-17
233
        # Create query
cleanup
Yuki Kimoto authored on 2011-04-02
234
        my $builder = $self->query_builder;
cleanup
yuki-kimoto authored on 2010-10-17
235
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
236

            
cleanup
Yuki Kimoto authored on 2011-04-02
237
        # Remove reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
238
        if (my $q = $self->reserved_word_quote) {
cleanup
Yuki Kimoto authored on 2011-04-02
239
            $_ =~ s/$q//g for @{$query->columns}
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
240
        }
241

            
cleanup
Yuki Kimoto authored on 2011-04-02
242
        # Save query to cache
243
        $self->cache_method->(
244
            $self, $source,
245
            {
246
                sql     => $query->sql, 
247
                columns => $query->columns,
248
                tables  => $query->tables
249
            }
250
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
251
    }
252
    
cleanup
yuki-kimoto authored on 2010-10-17
253
    # Prepare statement handle
254
    my $sth;
255
    eval { $sth = $self->dbh->prepare($query->{sql})};
improved error messages
Yuki Kimoto authored on 2011-04-18
256
    
257
    if ($@) {
258
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
259
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
260
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
261
    
cleanup
yuki-kimoto authored on 2010-10-17
262
    # Set statement handle
263
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
264
    
cleanup
Yuki Kimoto authored on 2011-02-09
265
    # Set filters
266
    $query->filters($self->filters);
267
    
cleanup
yuki-kimoto authored on 2010-10-17
268
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
269
}
270

            
update pod
Yuki Kimoto authored on 2011-03-13
271
sub dbh {
272
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
273
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
274
    # Set
275
    if (@_) {
276
        $self->{dbh} = $_[0];
277
        
278
        return $self;
279
    }
280
    
281
    # Get
282
    else {
283
        # From Connction manager
284
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
285
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
286
              unless ref $connector && $connector->can('dbh');
287
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
288
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
289
        }
290
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
291
        # Connect
292
        $self->{dbh} ||= $self->_connect;
293
        
294
        # Quote
295
        unless ($self->reserved_word_quote) {
296
            my $driver = $self->{dbh}->{Driver}->{Name};
297
            my $quote = $driver eq 'mysql' ? '`' : '"';
298
            $self->reserved_word_quote($quote);
299
        }
300

            
301
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
302
    }
303
}
304

            
cleanup
Yuki Kimoto authored on 2011-03-21
305
our %DELETE_ARGS
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
306
  = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all where_param/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
307

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
311
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
312
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
313
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
314
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
315
    }
316
    
317
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
318
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
319
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
320
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
321
    my $where            = delete $args{where} || {};
322
    my $append           = delete $args{append};
323
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
324
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
325
    my $id = delete $args{id};
326
    my $primary_key = delete $args{primary_key};
327
    croak "update method primary_key option " .
328
          "must be specified when id is specified " . _subname
329
      if defined $id && !defined $primary_key;
330
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
331
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
332
    # Where
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
333
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
334
    my $where_clause = '';
335
    if (ref $where) {
336
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
337
        $where_param = keys %$where_param
338
                     ? $self->merge_param($where_param, $where->param)
339
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
340
        
341
        # String where
342
        $where_clause = $where->to_string;
343
    }
344
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
345
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
346
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
347

            
cleanup
Yuki Kimoto authored on 2011-04-02
348
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
349
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
350
    my $q = $self->reserved_word_quote;
351
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
352
    push @sql, $append if $append;
353
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
354
    
355
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
356
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
357
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
358
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
359
        table => $table,
360
        %args
361
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
362
}
363

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

            
added helper method
yuki-kimoto authored on 2010-10-17
366
sub DESTROY { }
367

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
368
sub create_model {
369
    my $self = shift;
370
    
cleanup
Yuki Kimoto authored on 2011-04-02
371
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
372
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
373
    $args->{dbi} = $self;
374
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
375
    my $model_name  = delete $args->{name};
376
    my $model_table = delete $args->{table};
377
    $model_name ||= $model_table;
378
    
cleanup
Yuki Kimoto authored on 2011-04-02
379
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
380
    my $model = $model_class->new($args);
381
    $model->name($model_name) unless $model->name;
382
    $model->table($model_table) unless $model->table;
383
    
384
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
385
    my $filter = ref $model->filter eq 'HASH'
386
               ? [%{$model->filter}]
387
               : $model->filter;
388
    $self->apply_filter($model->table, @$filter);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
389
    my $result_filter = ref $model->result_filter eq 'HASH'
390
               ? [%{$model->result_filter}]
391
               : $model->result_filter;
392
    for (my $i = 1; $i < @$result_filter; $i += 2) {
393
        $result_filter->[$i] = {in => $result_filter->[$i]};
394
    }
395
    $self->apply_filter($model->table, @$result_filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
396
    
cleanup
Yuki Kimoto authored on 2011-04-02
397
    # Associate table with model
cleanup
Yuki Kimoto authored on 2011-04-25
398
    croak "Table name is duplicated " . _subname
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
399
      if exists $self->{_model_from}->{$model->table};
400
    $self->{_model_from}->{$model->table} = $model->name;
401

            
402
    # Table alias
403
    $self->{_table_alias} ||= {};
404
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
405
    
406
    # Set model
407
    $self->model($model->name, $model);
408
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
409
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
410
}
411

            
412
sub each_column {
413
    my ($self, $cb) = @_;
414
    
415
    # Iterate all tables
416
    my $sth_tables = $self->dbh->table_info;
417
    while (my $table_info = $sth_tables->fetchrow_hashref) {
418
        
419
        # Table
420
        my $table = $table_info->{TABLE_NAME};
421
        
422
        # Iterate all columns
423
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
424
        while (my $column_info = $sth_columns->fetchrow_hashref) {
425
            my $column = $column_info->{COLUMN_NAME};
426
            $self->$cb($table, $column, $column_info);
427
        }
428
    }
429
}
430

            
cleanup
Yuki Kimoto authored on 2011-04-02
431
our %EXECUTE_ARGS = map { $_ => 1 } @COMMON_ARGS, 'param';
432

            
433
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
434
    my $self = shift;
435
    my $query = shift;
436
    my $param;
437
    $param = shift if @_ % 2;
438
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
439
    
cleanup
Yuki Kimoto authored on 2011-04-02
440
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
441
    my $p = delete $args{param} || {};
442
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
443
    my $tables = delete $args{table} || [];
444
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
445
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
446
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
447
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
448
    $type = _array_to_hash($type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
449
    my $type_rule_off = delete $args{type_rule_off};
cleanup
Yuki Kimoto authored on 2011-06-09
450
    my $query_return = delete $args{query};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
451
    
cleanup
Yuki Kimoto authored on 2011-03-09
452
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
453
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
454
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
455
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
456
    }
457
    
cleanup
Yuki Kimoto authored on 2011-04-02
458
    # Create query
459
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
460
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
461
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
462
    
cleanup
Yuki Kimoto authored on 2011-04-02
463
    # Tables
464
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
465
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
466
    $tables = $self->_remove_duplicate_table($tables, $main_table);
467
    if (my $q = $self->reserved_word_quote) {
468
        $_ =~ s/$q//g for @$tables;
469
    }
cleanup
Yuki Kimoto authored on 2011-04-02
470
    
471
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
472
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
473
        
cleanup
Yuki Kimoto authored on 2011-04-02
474
        # No need
475
        next unless my $alias = $self->{_table_alias}->{$table};
476
        $self->{filter} ||= {};
477
        next if $self->{filter}{out}{$table};
478
        
479
        # Filter
480
        $self->{filter}{out} ||= {};
481
        $self->{filter}{in}  ||= {};
482
        $self->{filter}{end} ||= {};
483
        
484
        # Create alias filter
485
        foreach my $type (qw/out in end/) {
486
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
487
            foreach my $filter_name (@filter_names) {
488
                my $filter_name_alias = $filter_name;
489
                $filter_name_alias =~ s/^$alias\./$table\./;
490
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
491
                $self->{filter}{$type}{$table}{$filter_name_alias}
492
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
493
            }
494
        }
495
    }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
496

            
497
    # Type rule
498
    my $applied_filter = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
499
    unless ($type_rule_off) {
500
        foreach my $name (keys %$param) {
501
            my $table;
502
            my $column;
503
            if ($name =~ /(?:(.+)\.)?(.+)/) {
504
                $table = $1;
505
                $column = $2;
506
            }
507
            $table ||= $main_table;
508
            
509
            my $into = $self->{_into} || {};
510
            if (defined $table && $into->{$table} &&
511
                (my $rule = $into->{$table}->{$column}))
512
            {
513
                $applied_filter->{$column} = $rule;
514
                $applied_filter->{"$table.$column"} = $rule;
515
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
516
        }
517
    }
cleanup
Yuki Kimoto authored on 2011-04-02
518
    
519
    # Applied filter
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
520
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
521
        $applied_filter = {
522
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
523
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
524
        }
525
    }
cleanup
Yuki Kimoto authored on 2011-04-02
526
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
527
    
cleanup
Yuki Kimoto authored on 2011-04-02
528
    # Replace filter name to code
529
    foreach my $column (keys %$filter) {
530
        my $name = $filter->{$column};
531
        if (!defined $name) {
532
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
533
        }
cleanup
Yuki Kimoto authored on 2011-04-02
534
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
535
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
536
            unless exists $self->filters->{$name};
537
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
538
        }
539
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
540
    
cleanup
Yuki Kimoto authored on 2011-04-02
541
    # Create bind values
542
    my $bind = $self->_create_bind_values(
543
        $param,
544
        $query->columns,
545
        $filter,
546
        $type
547
    );
cleanup
yuki-kimoto authored on 2010-10-17
548
    
549
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
550
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
551
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
552
    eval {
553
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
554
            my $type = $bind->[$i]->{type};
555
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
556
        }
557
        $affected = $sth->execute;
558
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
559
    
560
    if ($@) {
561
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
562
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
563
    }
cleanup
yuki-kimoto authored on 2010-10-17
564
    
improved debug message
Yuki Kimoto authored on 2011-05-23
565
    # DEBUG message
566
    if (DEBUG) {
567
        print STDERR "SQL:\n" . $query->sql . "\n";
568
        my @output;
569
        foreach my $b (@$bind) {
570
            my $value = $b->{value};
571
            $value = 'undef' unless defined $value;
572
            $value = encode(DEBUG_ENCODING(), $value)
573
              if utf8::is_utf8($value);
574
            push @output, $value;
575
        }
576
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
577
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
578
    
cleanup
Yuki Kimoto authored on 2011-04-02
579
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
580
    if ($sth->{NUM_OF_FIELDS}) {
581
        
cleanup
Yuki Kimoto authored on 2011-04-02
582
        # Filter
583
        my $filter = {};
584
        $filter->{in}  = {};
585
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
586
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
587
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
588
            foreach my $way (qw/in end/) {
589
                $filter->{$way} = {
590
                    %{$filter->{$way}},
591
                    %{$self->{filter}{$way}{$table} || {}}
592
                };
593
            }
cleanup
Yuki Kimoto authored on 2011-01-12
594
        }
595
        
596
        # Result
597
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
598
            sth => $sth,
599
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
600
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
601
            filter => $filter->{in} || {},
602
            end_filter => $filter->{end} || {},
603
            type_rule => $self->type_rule,
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
604
            type_rule_off => $type_rule_off
cleanup
yuki-kimoto authored on 2010-10-17
605
        );
606

            
607
        return $result;
608
    }
cleanup
Yuki Kimoto authored on 2011-04-02
609
    
610
    # Not select statement
611
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
612
}
613

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
614
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param/;
update pod
Yuki Kimoto authored on 2011-03-13
615

            
cleanup
yuki-kimoto authored on 2010-10-17
616
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
617
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
618
    
cleanup
yuki-kimoto authored on 2010-10-17
619
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
620
    my $param;
621
    $param = shift if @_ % 2;
622
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
623
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
624
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
625
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
626
    my $p = delete $args{param} || {};
627
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
628
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
629
    my $id = delete $args{id};
630
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
631
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
632
          "must be specified when id is specified " . _subname
633
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
634
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
635

            
636
    # Check arguments
637
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
638
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
639
          unless $INSERT_ARGS{$name};
640
    }
641

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
642
    # Merge parameter
643
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
644
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
645
        $param = $self->merge_param($id_param, $param);
646
    }
647

            
cleanup
Yuki Kimoto authored on 2011-04-02
648
    # Reserved word quote
649
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
650
    
cleanup
Yuki Kimoto authored on 2011-04-02
651
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
652
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
653
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
654
    push @sql, $append if $append;
655
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
656
    
657
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
658
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
659
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
660
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
661
        table => $table,
662
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
663
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
664
}
665

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
666
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
667
    my ($self, $param) = @_;
668
    
cleanup
Yuki Kimoto authored on 2011-04-02
669
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
670
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
671
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
672
    my @columns;
673
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
674
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
675
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
676
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
677
        my $column_quote = "$q$column$q";
678
        $column_quote =~ s/\./$q.$q/;
679
        push @columns, $column_quote;
680
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
681
    }
682
    
cleanup
Yuki Kimoto authored on 2011-04-02
683
    return '(' . join(', ', @columns) . ') ' . 'values ' .
684
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
685
}
686

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
687
sub include_model {
688
    my ($self, $name_space, $model_infos) = @_;
689
    
cleanup
Yuki Kimoto authored on 2011-04-02
690
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
691
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
692
    
693
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
694
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
695

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
696
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
697
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
698
          if $name_space =~ /[^\w:]/;
699
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
700
        croak qq{Name space module "$name_space.pm" is needed. $@ }
701
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
702
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
703
        
704
        # Search model modules
705
        my $path = $INC{"$name_space.pm"};
706
        $path =~ s/\.pm$//;
707
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
708
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
709
        $model_infos = [];
710
        while (my $module = readdir $dh) {
711
            push @$model_infos, $module
712
              if $module =~ s/\.pm$//;
713
        }
714
        close $dh;
715
    }
716
    
cleanup
Yuki Kimoto authored on 2011-04-02
717
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
718
    foreach my $model_info (@$model_infos) {
719
        
cleanup
Yuki Kimoto authored on 2011-04-02
720
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
721
        my $model_class;
722
        my $model_name;
723
        my $model_table;
724
        if (ref $model_info eq 'HASH') {
725
            $model_class = $model_info->{class};
726
            $model_name  = $model_info->{name};
727
            $model_table = $model_info->{table};
728
            
729
            $model_name  ||= $model_class;
730
            $model_table ||= $model_name;
731
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
732
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
733
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
734
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
735
          if $mclass =~ /[^\w:]/;
736
        unless ($mclass->can('isa')) {
737
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
738
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
739
        }
740
        
cleanup
Yuki Kimoto authored on 2011-04-02
741
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
742
        my $args = {};
743
        $args->{model_class} = $mclass if $mclass;
744
        $args->{name}        = $model_name if $model_name;
745
        $args->{table}       = $model_table if $model_table;
746
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
747
    }
748
    
749
    return $self;
750
}
751

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
776
sub method {
777
    my $self = shift;
778
    
cleanup
Yuki Kimoto authored on 2011-04-02
779
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
780
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
781
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
782
    
783
    return $self;
784
}
785

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
803
sub mycolumn {
804
    my ($self, $table, $columns) = @_;
805
    
cleanup
Yuki Kimoto authored on 2011-04-02
806
    # Create column clause
807
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
808
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
809
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
810
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
811
    
812
    return join (', ', @column);
813
}
814

            
added dbi_options attribute
kimoto authored on 2010-12-20
815
sub new {
816
    my $self = shift->SUPER::new(@_);
817
    
cleanup
Yuki Kimoto authored on 2011-04-02
818
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
819
    my @attrs = keys %$self;
820
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
821
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
822
          unless $self->can($attr);
823
    }
cleanup
Yuki Kimoto authored on 2011-04-02
824
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
825
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
826
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
827
        '?'     => \&DBIx::Custom::Tag::placeholder,
828
        '='     => \&DBIx::Custom::Tag::equal,
829
        '<>'    => \&DBIx::Custom::Tag::not_equal,
830
        '>'     => \&DBIx::Custom::Tag::greater_than,
831
        '<'     => \&DBIx::Custom::Tag::lower_than,
832
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
833
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
834
        'like'  => \&DBIx::Custom::Tag::like,
835
        'in'    => \&DBIx::Custom::Tag::in,
836
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
837
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
838
    };
added dbi_options attribute
kimoto authored on 2010-12-20
839
    
840
    return $self;
841
}
842

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
843
sub not_exists { bless {}, 'DBIx::Custom::NotExists' }
844

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
855
our %SELECT_ARGS
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
856
  = map { $_ => 1 } @COMMON_ARGS,
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
857
                    qw/column where relation join param where_param wrap/;
refactoring select
yuki-kimoto authored on 2010-04-28
858

            
packaging one directory
yuki-kimoto authored on 2009-11-16
859
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
860
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
861

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

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

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

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1010
sub available_data_type {
1011
    my $self = shift;
1012
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1013
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1014
    foreach my $i (-1000 .. 1000) {
1015
         my $type_info = $self->dbh->type_info($i);
1016
         my $data_type = $type_info->{DATA_TYPE};
1017
         my $type_name = $type_info->{TYPE_NAME};
1018
         $data_types .= "$data_type ($type_name)\n"
1019
           if defined $data_type;
1020
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1021
    return "Data Type maybe equal to Type Name" unless $data_types;
1022
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
1023
    return $data_types;
1024
}
1025

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1026
sub type_rule {
1027
    my $self = shift;
1028
    
1029
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1030
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1031
        
1032
        # Into
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1033
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1034
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1035
        $self->{_into} ||= {};
1036
        $self->each_column(sub {
1037
            my ($dbi, $table, $column, $column_info) = @_;
1038
            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1039
            my $type_name = $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1040
            if ($type_rule->{into} &&
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1041
                (my $filter = $type_rule->{into}->{$type_name}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1042
            {
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1043
                return unless exists $type_rule->{into}->{$type_name};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1044
                if  (defined $filter && ref $filter ne 'CODE') 
1045
                {
1046
                    my $fname = $filter;
1047
                    croak qq{Filter "$fname" is not registered" } . _subname
1048
                      unless exists $self->filters->{$fname};
1049
                    
1050
                    $filter = $self->filters->{$fname};
1051
                }
1052

            
1053
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1054
            }
1055
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1056
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1057

            
1058
        # From
1059
        $type_rule->{from} = _array_to_hash($type_rule->{from});
1060
        foreach my $data_type (keys %{$type_rule->{from} || {}}) {
1061
            my $fname = $type_rule->{from}{$data_type};
1062
            if (defined $fname && ref $fname ne 'CODE') {
1063
                croak qq{Filter "$fname" is not registered" } . _subname
1064
                  unless exists $self->filters->{$fname};
1065
                
1066
                $type_rule->{from}{$data_type} = $self->filters->{$fname};
1067
            }
1068
        }
1069
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1070
        return $self;
1071
    }
1072
    
1073
    return $self->{type_rule} || {};
1074
}
1075

            
cleanup
Yuki Kimoto authored on 2011-03-21
1076
our %UPDATE_ARGS
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1077
  = map { $_ => 1 } @COMMON_ARGS, qw/param where allow_update_all where_param/;
cleanup
yuki-kimoto authored on 2010-10-17
1078

            
1079
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1080
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1081

            
cleanup
yuki-kimoto authored on 2010-10-17
1082
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1083
    my $param;
1084
    $param = shift if @_ % 2;
1085
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1086
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1087
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1088
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1089
    my $p = delete $args{param} || {};
1090
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1091
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1092
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1093
    my $append           = delete $args{append} || '';
1094
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1095
    my $id = delete $args{id};
1096
    my $primary_key = delete $args{primary_key};
1097
    croak "update method primary_key option " .
1098
          "must be specified when id is specified " . _subname
1099
      if defined $id && !defined $primary_key;
1100
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1101
    
cleanup
Yuki Kimoto authored on 2011-04-02
1102
    # Check argument names
1103
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1104
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1105
          unless $UPDATE_ARGS{$name};
1106
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1107

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

            
1111
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1112
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1113
    my $where_clause = '';
1114
    if (ref $where) {
1115
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1116
        $where_param = keys %$where_param
1117
                     ? $self->merge_param($where_param, $where->param)
1118
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1119
        
1120
        # String where
1121
        $where_clause = $where->to_string;
1122
    }
1123
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1124
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1125
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1126
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1127
    # Merge param
1128
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1129
    
cleanup
Yuki Kimoto authored on 2011-04-02
1130
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1131
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1132
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1133
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1134
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1135
    
cleanup
Yuki Kimoto authored on 2011-01-27
1136
    # SQL
1137
    my $sql = join(' ', @sql);
1138
    
cleanup
yuki-kimoto authored on 2010-10-17
1139
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1140
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1141
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1142
        param  => $param, 
1143
        table => $table,
1144
        %args
1145
    );
cleanup
yuki-kimoto authored on 2010-10-17
1146
    
1147
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1148
}
1149

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1152
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1153
    my ($self, $param, $opt) = @_;
1154
    
cleanup
Yuki Kimoto authored on 2011-04-02
1155
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1156
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1157
    $tag = "set $tag" unless $opt->{no_set};
1158

            
cleanup
Yuki Kimoto authored on 2011-04-02
1159
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1160
}
1161

            
cleanup
Yuki Kimoto authored on 2011-01-25
1162
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1163
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1164
    
1165
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1166
    return DBIx::Custom::Where->new(
1167
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1168
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1169
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1170
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1171
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1172
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1173

            
cleanup
Yuki Kimoto authored on 2011-04-02
1174
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1175
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1176
    
cleanup
Yuki Kimoto authored on 2011-04-02
1177
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1178
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1179
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1180
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1181
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1182
        
1183
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1184
        my $value;
1185
        if(ref $params->{$column} eq 'ARRAY') {
1186
            my $i = $count->{$column} || 0;
1187
            $i += $not_exists->{$column} || 0;
1188
            my $found;
1189
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1190
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1191
                    $not_exists->{$column}++;
1192
                }
1193
                else  {
1194
                    $value = $params->{$column}->[$k];
1195
                    $found = 1;
1196
                    last
1197
                }
1198
            }
1199
            next unless $found;
1200
        }
1201
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1202
        
cleanup
Yuki Kimoto authored on 2011-01-12
1203
        # Filter
1204
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1205
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1206
        # Type
1207
        push @$bind, {
1208
            value => $f ? $f->($value) : $value,
1209
            type => $type->{$column}
1210
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1211
        
1212
        # Count up 
1213
        $count->{$column}++;
1214
    }
1215
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1216
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1217
}
1218

            
cleanup
Yuki Kimoto authored on 2011-06-08
1219
sub _create_param_from_id {
1220
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1221
    
cleanup
Yuki Kimoto authored on 2011-06-08
1222
    # Create parameter
1223
    my $param = {};
1224
    if ($id) {
1225
        $id = [$id] unless ref $id;
1226
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1227
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1228
          unless !ref $id || ref $id eq 'ARRAY';
1229
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1230
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1231
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1232
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1233
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1234
        }
1235
    }
1236
    
cleanup
Yuki Kimoto authored on 2011-06-08
1237
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1238
}
1239

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1240
sub _connect {
1241
    my $self = shift;
1242
    
1243
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1244
    my $dsn = $self->data_source;
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1245
    warn "data_source is DEPRECATED! use dsn instead\n"
1246
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1247
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1248
    croak qq{"dsn" must be specified } . _subname
1249
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1250
    my $user        = $self->user;
1251
    my $password    = $self->password;
1252
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1253
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1254
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1255
    
1256
    # Connect
1257
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1258
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1259
        $user,
1260
        $password,
1261
        {
1262
            %{$self->default_dbi_option},
1263
            %$dbi_option
1264
        }
1265
    )};
1266
    
1267
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1268
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1269
    
1270
    return $dbh;
1271
}
1272

            
cleanup
yuki-kimoto authored on 2010-10-17
1273
sub _croak {
1274
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1275
    
1276
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1277
    $append ||= "";
1278
    
1279
    # Verbose
1280
    if ($Carp::Verbose) { croak $error }
1281
    
1282
    # Not verbose
1283
    else {
1284
        
1285
        # Remove line and module infromation
1286
        my $at_pos = rindex($error, ' at ');
1287
        $error = substr($error, 0, $at_pos);
1288
        $error =~ s/\s+$//;
1289
        croak "$error$append";
1290
    }
1291
}
1292

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1293
sub _need_tables {
1294
    my ($self, $tree, $need_tables, $tables) = @_;
1295
    
cleanup
Yuki Kimoto authored on 2011-04-02
1296
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1297
    foreach my $table (@$tables) {
1298
        if ($tree->{$table}) {
1299
            $need_tables->{$table} = 1;
1300
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1301
        }
1302
    }
1303
}
1304

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1305
sub _push_join {
1306
    my ($self, $sql, $join, $join_tables) = @_;
1307
    
cleanup
Yuki Kimoto authored on 2011-04-02
1308
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1309
    return unless @$join;
1310
    
cleanup
Yuki Kimoto authored on 2011-04-02
1311
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1312
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1313
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1314
    for (my $i = 0; $i < @$join; $i++) {
1315
        
cleanup
Yuki Kimoto authored on 2011-04-02
1316
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1317
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1318
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1319
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1320
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1321
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1322
            my $table1 = $1;
1323
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1324
            croak qq{right side table of "$join_clause" must be unique }
1325
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1326
              if exists $tree->{$table2};
1327
            $tree->{$table2}
1328
              = {position => $i, parent => $table1, join => $join_clause};
1329
        }
1330
        else {
improved error message
Yuki Kimoto authored on 2011-06-13
1331
            croak qq{join clause must have two table name after "on" keyword. } .
1332
                  qq{"$join_clause" is passed }  . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1333
        }
1334
    }
1335
    
cleanup
Yuki Kimoto authored on 2011-04-02
1336
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1337
    my $need_tables = {};
1338
    $self->_need_tables($tree, $need_tables, $join_tables);
1339
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1340
    
1341
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1342
    foreach my $need_table (@need_tables) {
1343
        push @$sql, $tree->{$need_table}{join};
1344
    }
1345
}
cleanup
Yuki Kimoto authored on 2011-03-08
1346

            
cleanup
Yuki Kimoto authored on 2011-04-02
1347
sub _remove_duplicate_table {
1348
    my ($self, $tables, $main_table) = @_;
1349
    
1350
    # Remove duplicate table
1351
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1352
    delete $tables{$main_table} if $main_table;
1353
    
1354
    return [keys %tables, $main_table ? $main_table : ()];
1355
}
1356

            
cleanup
Yuki Kimoto authored on 2011-04-02
1357
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1358
    my ($self, $source) = @_;
1359
    
cleanup
Yuki Kimoto authored on 2011-04-02
1360
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1361
    my $tables = [];
1362
    my $safety_character = $self->safety_character;
1363
    my $q = $self->reserved_word_quote;
1364
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1365
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1366
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1367
    while ($source =~ /$table_re/g) {
1368
        push @$tables, $1;
1369
    }
1370
    
1371
    return $tables;
1372
}
1373

            
cleanup
Yuki Kimoto authored on 2011-04-02
1374
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1375
    my ($self, $where) = @_;
1376
    
cleanup
Yuki Kimoto authored on 2011-04-02
1377
    my $obj;
1378
    
1379
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1380
    if (ref $where eq 'HASH') {
1381
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1382
        my $q = $self->reserved_word_quote;
1383
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1384
            my $column_quote = "$q$column$q";
1385
            $column_quote =~ s/\./$q.$q/;
1386
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1387
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1388
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1389
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1390
    
1391
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1392
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1393
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1394
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1395
    
1396
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1397
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1398
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1399
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1400
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1401
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1402
            clause => $where->[0],
1403
            param  => $where->[1]
1404
        );
1405
    }
1406
    
cleanup
Yuki Kimoto authored on 2011-04-02
1407
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1408
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1409
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1410
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1411
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1412
    
cleanup
Yuki Kimoto authored on 2011-04-02
1413
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1414
}
1415

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1416
# DEPRECATED!
1417
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1418
sub select_at {
1419
    my ($self, %args) = @_;
1420

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1423
    # Arguments
1424
    my $primary_keys = delete $args{primary_key};
1425
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1426
    my $where = delete $args{where};
1427
    my $param = delete $args{param};
1428
    
1429
    # Check arguments
1430
    foreach my $name (keys %args) {
1431
        croak qq{"$name" is wrong option } . _subname
1432
          unless $SELECT_AT_ARGS{$name};
1433
    }
1434
    
1435
    # Table
1436
    croak qq{"table" option must be specified } . _subname
1437
      unless $args{table};
1438
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1439
    
1440
    # Create where parameter
1441
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1442
    
1443
    return $self->select(where => $where_param, %args);
1444
}
1445

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1446
# DEPRECATED!
1447
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1448
sub delete_at {
1449
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1450

            
1451
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1452
    
1453
    # Arguments
1454
    my $primary_keys = delete $args{primary_key};
1455
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1456
    my $where = delete $args{where};
1457
    
1458
    # Check arguments
1459
    foreach my $name (keys %args) {
1460
        croak qq{"$name" is wrong option } . _subname
1461
          unless $DELETE_AT_ARGS{$name};
1462
    }
1463
    
1464
    # Create where parameter
1465
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1466
    
1467
    return $self->delete(where => $where_param, %args);
1468
}
1469

            
cleanup
Yuki Kimoto authored on 2011-06-08
1470
# DEPRECATED!
1471
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1472
sub update_at {
1473
    my $self = shift;
1474

            
1475
    warn "update_at is DEPRECATED! use update and id option instead";
1476
    
1477
    # Arguments
1478
    my $param;
1479
    $param = shift if @_ % 2;
1480
    my %args = @_;
1481
    my $primary_keys = delete $args{primary_key};
1482
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1483
    my $where = delete $args{where};
1484
    my $p = delete $args{param} || {};
1485
    $param  ||= $p;
1486
    
1487
    # Check arguments
1488
    foreach my $name (keys %args) {
1489
        croak qq{"$name" is wrong option } . _subname
1490
          unless $UPDATE_AT_ARGS{$name};
1491
    }
1492
    
1493
    # Create where parameter
1494
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1495
    
1496
    return $self->update(where => $where_param, param => $param, %args);
1497
}
1498

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1499
# DEPRECATED!
1500
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1501
sub insert_at {
1502
    my $self = shift;
1503
    
1504
    warn "insert_at is DEPRECATED! use insert and id option instead";
1505
    
1506
    # Arguments
1507
    my $param;
1508
    $param = shift if @_ % 2;
1509
    my %args = @_;
1510
    my $primary_key = delete $args{primary_key};
1511
    $primary_key = [$primary_key] unless ref $primary_key;
1512
    my $where = delete $args{where};
1513
    my $p = delete $args{param} || {};
1514
    $param  ||= $p;
1515
    
1516
    # Check arguments
1517
    foreach my $name (keys %args) {
1518
        croak qq{"$name" is wrong option } . _subname
1519
          unless $INSERT_AT_ARGS{$name};
1520
    }
1521
    
1522
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1523
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1524
    $param = $self->merge_param($where_param, $param);
1525
    
1526
    return $self->insert(param => $param, %args);
1527
}
1528

            
added warnings
Yuki Kimoto authored on 2011-06-07
1529
# DEPRECATED!
1530
sub register_tag {
1531
    warn "register_tag is DEPRECATED!";
1532
    shift->query_builder->register_tag(@_)
1533
}
1534

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1535
# DEPRECATED!
1536
__PACKAGE__->attr('data_source');
1537

            
cleanup
Yuki Kimoto authored on 2011-01-25
1538
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1539
__PACKAGE__->attr(
1540
    dbi_options => sub { {} },
1541
    filter_check  => 1
1542
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1543

            
cleanup
Yuki Kimoto authored on 2011-01-25
1544
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1545
sub default_bind_filter {
1546
    my $self = shift;
1547
    
added warnings
Yuki Kimoto authored on 2011-06-07
1548
    warn "default_bind_filter is DEPRECATED! use apply_filter instead\n";
1549
    
cleanup
Yuki Kimoto authored on 2011-01-12
1550
    if (@_) {
1551
        my $fname = $_[0];
1552
        
1553
        if (@_ && !$fname) {
1554
            $self->{default_out_filter} = undef;
1555
        }
1556
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1557
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1558
              unless exists $self->filters->{$fname};
1559
        
1560
            $self->{default_out_filter} = $self->filters->{$fname};
1561
        }
1562
        return $self;
1563
    }
1564
    
1565
    return $self->{default_out_filter};
1566
}
1567

            
cleanup
Yuki Kimoto authored on 2011-01-25
1568
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1569
sub default_fetch_filter {
1570
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1571

            
1572
    warn "default_fetch_filter is DEPRECATED! use apply_filter instead\n";
cleanup
Yuki Kimoto authored on 2011-01-12
1573
    
1574
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1575
        my $fname = $_[0];
1576

            
cleanup
Yuki Kimoto authored on 2011-01-12
1577
        if (@_ && !$fname) {
1578
            $self->{default_in_filter} = undef;
1579
        }
1580
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1581
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1582
              unless exists $self->filters->{$fname};
1583
        
1584
            $self->{default_in_filter} = $self->filters->{$fname};
1585
        }
1586
        
1587
        return $self;
1588
    }
1589
    
many changed
Yuki Kimoto authored on 2011-01-23
1590
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1591
}
1592

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1593
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1594
sub insert_param_tag {
1595
    warn "insert_param_tag is DEPRECATED! " .
1596
         "use insert_param instead!";
1597
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1598
}
1599

            
cleanup
Yuki Kimoto authored on 2011-01-25
1600
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1601
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1602
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1603
    return shift->query_builder->register_tag_processor(@_);
1604
}
1605

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1606
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1607
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1608
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1609
         "use update_param instead";
1610
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1611
}
cleanup
Yuki Kimoto authored on 2011-03-08
1612
# DEPRECATED!
1613
sub _push_relation {
1614
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1615
    
1616
    if (keys %{$relation || {}}) {
1617
        push @$sql, $need_where ? 'where' : 'and';
1618
        foreach my $rcolumn (keys %$relation) {
1619
            my $table1 = (split (/\./, $rcolumn))[0];
1620
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1621
            push @$tables, ($table1, $table2);
1622
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1623
        }
1624
    }
1625
    pop @$sql if $sql->[-1] eq 'and';    
1626
}
1627

            
1628
# DEPRECATED!
1629
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1630
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1631
    
1632
    if (keys %{$relation || {}}) {
1633
        foreach my $rcolumn (keys %$relation) {
1634
            my $table1 = (split (/\./, $rcolumn))[0];
1635
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1636
            my $table1_exists;
1637
            my $table2_exists;
1638
            foreach my $table (@$tables) {
1639
                $table1_exists = 1 if $table eq $table1;
1640
                $table2_exists = 1 if $table eq $table2;
1641
            }
1642
            unshift @$tables, $table1 unless $table1_exists;
1643
            unshift @$tables, $table2 unless $table2_exists;
1644
        }
1645
    }
1646
}
1647

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1650
=head1 NAME
1651

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1652
DBIx::Custom - Useful database access, respecting SQL!
removed reconnect method
yuki-kimoto authored on 2010-05-28
1653

            
1654
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1655

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1656
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1657
    
1658
    # Connect
1659
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1660
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1661
        user => 'ken',
1662
        password => '!LFKD%$&',
1663
        dbi_option => {mysql_enable_utf8 => 1}
1664
    );
cleanup
yuki-kimoto authored on 2010-08-05
1665

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1666
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1667
    $dbi->insert(
1668
        table  => 'book',
1669
        param  => {title => 'Perl', author => 'Ken'}
1670
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1671
    
1672
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1673
    $dbi->update(
1674
        table  => 'book', 
1675
        param  => {title => 'Perl', author => 'Ken'}, 
1676
        where  => {id => 5},
1677
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1678
    
1679
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1680
    $dbi->delete(
1681
        table  => 'book',
1682
        where  => {author => 'Ken'},
1683
    );
cleanup
yuki-kimoto authored on 2010-08-05
1684

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1685
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1686
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1687
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
1688
        where  => {author => 'Ken'},
added commit method
yuki-kimoto authored on 2010-05-27
1689
    );
cleanup
yuki-kimoto authored on 2010-08-05
1690

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1691
    # Select, more complex
1692
    my $result = $dbi->select(
1693
        table  => 'book',
1694
        column => [
1695
            'book.author as book__author',
1696
            'company.name as company__name'
1697
        ],
1698
        where  => {'book.author' => 'Ken'},
1699
        join => ['left outer join company on book.company_id = company.id'],
1700
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1701
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1702
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1703
    # Fetch
1704
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1705
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1706
    }
1707
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1708
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1709
    while (my $row = $result->fetch_hash) {
1710
        
1711
    }
1712
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1713
    # Execute SQL with parameter.
1714
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1715
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1716
        param  => {author => 'ken', title => '%Perl%'}
1717
    );
1718
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1719
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1720

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1721
L<DBIx::Custom> is L<DBI> wrapper module.
1722

            
1723
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1724

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1725
=over 4
removed reconnect method
yuki-kimoto authored on 2010-05-28
1726

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1727
=item *
removed reconnect method
yuki-kimoto authored on 2010-05-28
1728

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1729
There are many basic methods to execute various queries.
1730
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1731
C<delete_all()>, C<select()>,
- select() column option can...
Yuki Kimoto authored on 2011-06-08
1732
C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1733

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1734
=item *
1735

            
1736
Filter when data is send or receive.
1737

            
1738
=item *
1739

            
1740
Data filtering system
1741

            
1742
=item *
1743

            
1744
Model support.
1745

            
1746
=item *
1747

            
1748
Generate where clause dinamically.
1749

            
1750
=item *
1751

            
1752
Generate join clause dinamically.
1753

            
1754
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1755

            
1756
=head1 GUIDE
1757

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1758
L<DBIx::Custom::Guide> - L<DBIx::Custom> Guide
pod fix
Yuki Kimoto authored on 2011-01-21
1759

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1760
=head1 Wiki
pod fix
Yuki Kimoto authored on 2011-01-21
1761

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1762
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
updated document
yuki-kimoto authored on 2010-08-08
1763

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

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

            
1768
    my $connector = $dbi->connector;
1769
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1770

            
1771
Connection manager object. if connector is set, you can get C<dbh()>
1772
from connection manager. conection manager object must have dbh() mehtod.
1773

            
1774
This is L<DBIx::Connector> example. Please pass
1775
C<default_dbi_option> to L<DBIx::Connector>.
1776

            
1777
    my $connector = DBIx::Connector->new(
1778
        "dbi:mysql:database=$DATABASE",
1779
        $USER,
1780
        $PASSWORD,
1781
        DBIx::Custom->new->default_dbi_option
1782
    );
1783
    
1784
    my $dbi = DBIx::Custom->new(connector => $connector);
1785

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

            
1788
    my $dsn = $dbi->dsn;
1789
    $dbi    = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
1790

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1791
Data source name, used when C<connect()> is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1792

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1793
C<data_source> is DEPRECATED! It is renamed to C<dsn>.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1794

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1797
    my $dbi_option = $dbi->dbi_option;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1798
    $dbi           = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1799

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1800
L<DBI> option, used when C<connect()> is executed.
1801
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1802

            
1803
=head2 C<default_dbi_option>
1804

            
1805
    my $default_dbi_option = $dbi->default_dbi_option;
1806
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1807

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1808
L<DBI> default option, used when C<connect()> is executed,
1809
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1810

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1811
    {
1812
        RaiseError => 1,
1813
        PrintError => 0,
1814
        AutoCommit => 1,
1815
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1816

            
update pod
Yuki Kimoto authored on 2011-03-13
1817
You should not change C<AutoCommit> value directly,
1818
the value is used to check if the process is in transaction.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1819

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1822
    my $filters = $dbi->filters;
1823
    $dbi        = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
1824

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1825
Filters, registered by C<register_filter()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1826

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

            
1829
    my $models = $dbi->models;
1830
    $dbi       = $dbi->models(\%models);
1831

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1832
Models, included by C<include_model()>.
add models() attribute
Yuki Kimoto authored on 2011-02-21
1833

            
cleanup
yuki-kimoto authored on 2010-10-17
1834
=head2 C<password>
1835

            
1836
    my $password = $dbi->password;
1837
    $dbi         = $dbi->password('lkj&le`@s');
1838

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1839
Password, used when C<connect()> is executed.
update document
yuki-kimoto authored on 2010-01-30
1840

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

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1843
    my $sql_class = $dbi->query_builder;
1844
    $dbi          = $dbi->query_builder(DBIx::Custom::QueryBuilder->new);
added commit method
yuki-kimoto authored on 2010-05-27
1845

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1846
Query builder, default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
1847

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1848
=head2 C<reserved_word_quote>
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1849

            
1850
     my reserved_word_quote = $dbi->reserved_word_quote;
1851
     $dbi                   = $dbi->reserved_word_quote('"');
1852

            
cleanup
Yuki Kimoto authored on 2011-04-02
1853
Reserved word quote, default to empty string.
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1854

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1857
    my $result_class = $dbi->result_class;
1858
    $dbi             = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
1859

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1864
    my $safety_character = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-03-10
1865
    $dbi                 = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
1866

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1872
    my $user = $dbi->user;
1873
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1874

            
cleanup
Yuki Kimoto authored on 2011-03-10
1875
User name, used when C<connect()> is executed.
update pod
Yuki Kimoto authored on 2011-01-27
1876

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

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

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1883
=head2 C<available_data_type> EXPERIMENTAL
1884

            
1885
    print $dbi->available_data_type;
1886

            
1887
Get available data type.
1888

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1889
=head2 C<apply_filter>
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1890

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1891
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1892
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1893
        'issue_date' => {
1894
            out => 'tp_to_date',
1895
            in  => 'date_to_tp',
1896
            end => 'tp_to_displaydate'
1897
        },
1898
        'write_date' => {
1899
            out => 'tp_to_date',
1900
            in  => 'date_to_tp',
1901
            end => 'tp_to_displaydate'
1902
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1903
    );
1904

            
update pod
Yuki Kimoto authored on 2011-03-13
1905
Apply filter to columns.
1906
C<out> filter is executed before data is send to database.
1907
C<in> filter is executed after a row is fetch.
1908
C<end> filter is execute after C<in> filter is executed.
1909

            
1910
Filter is applied to the follwoing tree column name pattern.
cleanup
Yuki Kimoto authored on 2010-12-21
1911

            
update pod
Yuki Kimoto authored on 2011-03-13
1912
       PETTERN         EXAMPLE
1913
    1. Column        : author
1914
    2. Table.Column  : book.author
1915
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1916

            
update pod
Yuki Kimoto authored on 2011-03-13
1917
If column name is duplicate with other table,
1918
Main filter specified by C<table> option is used.
1919

            
1920
You can set multiple filters at once.
1921

            
1922
    $dbi->apply_filter(
1923
        'book',
1924
        [qw/issue_date write_date/] => {
1925
            out => 'tp_to_date',
1926
            in  => 'date_to_tp',
1927
            end => 'tp_to_displaydate'
1928
        }
1929
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1930

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

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

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

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

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

            
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1941
=head2 C<col> EXPERIMETNAL
1942

            
1943
    my $column = $model->col(book => ['author', 'title']);
1944

            
1945
Create column clause. The follwoing column clause is created.
1946

            
1947
    book.author as "book.author",
1948
    book.title as "book.title"
1949

            
1950
=head2 C<column> EXPERIMETNAL
1951

            
1952
    my $column = $dbi->column(book => ['author', 'title']);
1953

            
1954
Create column clause. The follwoing column clause is created.
1955

            
1956
    book.author as book__author,
1957
    book.title as book__title
1958

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1959
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1960

            
update pod
Yuki Kimoto authored on 2011-03-13
1961
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1962
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1963
        user => 'ken',
1964
        password => '!LFKD%$&',
1965
        dbi_option => {mysql_enable_utf8 => 1}
1966
    );
1967

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1976
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1977
        table => 'book',
1978
        primary_key => 'id',
1979
        join => [
1980
            'inner join company on book.comparny_id = company.id'
1981
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1982
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1983
            publish_date => {
1984
                out => 'tp_to_date',
1985
                in => 'date_to_tp',
1986
                end => 'tp_to_displaydate'
1987
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1988
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1989
    );
1990

            
1991
Create L<DBIx::Custom::Model> object and initialize model.
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1992
the module is also used from model() method.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1993

            
1994
   $dbi->model('book')->select(...);
1995

            
cleanup
yuki-kimoto authored on 2010-10-17
1996
=head2 C<create_query>
1997
    
1998
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1999
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
2000
    );
update document
yuki-kimoto authored on 2009-11-19
2001

            
update pod
Yuki Kimoto authored on 2011-03-13
2002
Create L<DBIx::Custom::Query> object.
2003

            
cleanup
yuki-kimoto authored on 2010-10-17
2004
If you want to get high performance,
update pod
Yuki Kimoto authored on 2011-03-13
2005
create L<DBIx::Custom::Query> object and execute the query by C<execute()>
2006
instead of other methods, such as C<insert>, C<update>.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
2007

            
cleanup
yuki-kimoto authored on 2010-10-17
2008
    $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
version 0.0901
yuki-kimoto authored on 2009-12-17
2009

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

            
2012
    my $dbh = $dbi->dbh;
2013

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2014
Get L<DBI> database handle. if C<connector> is set, you can get
2015
database handle from C<connector>.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2016

            
2017
=head2 C<each_column>
2018

            
2019
    $dbi->each_column(
2020
        sub {
2021
            my ($dbi, $table, $column, $column_info) = @_;
2022
            
2023
            my $type = $column_info->{TYPE_NAME};
2024
            
2025
            if ($type eq 'DATE') {
2026
                # ...
2027
            }
2028
        }
2029
    );
2030

            
2031
Iterate all column informations of all table from database.
2032
Argument is callback when one column is found.
2033
Callback receive four arguments, dbi object, table name,
2034
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2035

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2038
    my $result = $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2039
        "select * from book where title = :title and author like :author",
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
2040
        {title => 'Perl', author => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2041
    );
2042

            
updated pod
Yuki Kimoto authored on 2011-06-09
2043
Execute SQL. SQL can contain parameter such as :author.
2044
Return value is L<DBIx::Custom::Result> when select statement is executed,
2045
or the count of affected rows in insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2046

            
updated pod
Yuki Kimoto authored on 2011-06-09
2047
Parameter is replaced by placeholder C<?>.
update pod
Yuki Kimoto authored on 2011-03-13
2048

            
2049
    select * from where title = ? and author like ?;
2050

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

            
2053
=over 4
2054

            
2055
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2056
    
2057
    filter => {
2058
        title  => sub { uc $_[0] }
2059
        author => sub { uc $_[0] }
2060
    }
update pod
Yuki Kimoto authored on 2011-03-13
2061

            
updated pod
Yuki Kimoto authored on 2011-06-09
2062
    # Filter name
2063
    filter => {
2064
        title  => 'upper_case',
2065
        author => 'upper_case'
2066
    }
2067
        
2068
    # At once
2069
    filter => [
2070
        [qw/title author/]  => sub { uc $_[0] }
2071
    ]
2072

            
2073
Filter, executed before data is saved into database.
update pod
Yuki Kimoto authored on 2011-03-13
2074
Filter value is code reference or
2075
filter name registerd by C<register_filter()>.
2076

            
2077
These filters are added to the C<out> filters, set by C<apply_filter()>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2078

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

            
2081
    query => 1
2082

            
2083
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
2084

            
updated pod
Yuki Kimoto authored on 2011-06-09
2085
=item C<table>
2086
    
2087
    table => 'author'
2088
    table => ['author', 'book']
2089

            
2090
Table names for filtering.
2091

            
2092
Filtering by C<apply_filter> is off in C<execute> method,
2093
because we don't know what filter is applied.
2094

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2095
=item C<type>
2096

            
2097
Specify database data type.
2098

            
2099
    type => [image => DBI::SQL_BLOB]
2100
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2101

            
2102
This is used to bind paramter by C<bind_param()> of statment handle.
2103

            
2104
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2105

            
2106
C<type> option is also available
2107
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2108

            
2109
=item C<type_rule_off> EXPERIMENTAL
2110

            
2111
    type_rule_off => 1
2112

            
2113
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2114

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

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2117
=head2 C<delete>
packaging one directory
yuki-kimoto authored on 2009-11-16
2118

            
update pod
Yuki Kimoto authored on 2011-03-13
2119
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2120

            
updated document
Yuki Kimoto authored on 2011-06-09
2121
Execute delete statement.
update pod
Yuki Kimoto authored on 2011-03-13
2122

            
updated document
Yuki Kimoto authored on 2011-06-09
2123
The following opitons are available.
update pod
Yuki Kimoto authored on 2011-03-13
2124

            
update pod
Yuki Kimoto authored on 2011-03-13
2125
=over 4
2126

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2129
Same as C<select> method's C<append> option.
update pod
Yuki Kimoto authored on 2011-03-13
2130

            
2131
=item C<filter>
2132

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2133
Same as C<execute> method's C<filter> option.
update pod
Yuki Kimoto authored on 2011-03-13
2134

            
updated document
Yuki Kimoto authored on 2011-06-09
2135
=item C<id>
update pod
Yuki Kimoto authored on 2011-03-13
2136

            
updated document
Yuki Kimoto authored on 2011-06-09
2137
    id => 4
2138
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2139

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2143
    $dbi->delete(
2144
        parimary_key => ['id1', 'id2'],
2145
        id => [4, 5],
2146
        table => 'book',
2147
    );
update pod
Yuki Kimoto authored on 2011-03-13
2148

            
updated document
Yuki Kimoto authored on 2011-06-09
2149
The above is same as the followin one.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2150

            
updated document
Yuki Kimoto authored on 2011-06-09
2151
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2152

            
updated document
Yuki Kimoto authored on 2011-06-09
2153
=item C<query>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2154

            
updated document
Yuki Kimoto authored on 2011-06-09
2155
Same as C<execute> method's C<query> option.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2156

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2161
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2162

            
updated document
Yuki Kimoto authored on 2011-06-09
2163
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2164

            
updated pod
Yuki Kimoto authored on 2011-06-08
2165
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2166

            
updated pod
Yuki Kimoto authored on 2011-06-08
2167
See C<id> option.
update pod
Yuki Kimoto authored on 2011-03-13
2168

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2169
=item C<type>
2170

            
2171
Same as C<execute> method's C<type> option.
2172

            
2173
=item C<type_rule_off> EXPERIMENTAL
2174

            
2175
Same as C<execute> method's C<type_rule_off> option.
2176

            
updated pod
Yuki Kimoto authored on 2011-06-08
2177
=back
update pod
Yuki Kimoto authored on 2011-03-13
2178

            
updated pod
Yuki Kimoto authored on 2011-06-08
2179
=head2 C<delete_all>
update pod
Yuki Kimoto authored on 2011-03-13
2180

            
updated pod
Yuki Kimoto authored on 2011-06-08
2181
    $dbi->delete_all(table => $table);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2182

            
updated document
Yuki Kimoto authored on 2011-06-09
2183
Execute delete statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2184
Options is same as C<delete()>.
update pod
Yuki Kimoto authored on 2011-03-13
2185

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-09
2190
Execute insert statement.
update pod
Yuki Kimoto authored on 2011-03-13
2191

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

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

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

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

            
2200
=item C<filter>
2201

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

            
2204
=item C<id>
2205

            
updated document
Yuki Kimoto authored on 2011-06-09
2206
    id => 4
2207
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2208

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2212
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2213
        {title => 'Perl', author => 'Ken'}
2214
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2215
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2216
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2217
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2218

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

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

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

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

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

            
2233
=item C<param>
2234

            
2235
    param => {title => 'Perl', author => 'Ken'}
2236

            
2237
Insert data.
2238

            
2239
If C<insert> method's arguments is odd numbers,
2240
first argument is received as C<param>.
2241

            
2242
    $dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book');
2243

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

            
2246
Same as C<execute> method's C<query> option.
2247

            
2248
=item C<table>
2249

            
2250
    table => 'book'
2251

            
2252
Table name.
2253

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2254
=item C<type>
cleanup
yuki-kimoto authored on 2010-10-17
2255

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2256
Same as C<execute> method's C<type> option.
cleanup
yuki-kimoto authored on 2010-10-17
2257

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2262
=back
2263

            
2264
=over 4
2265

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2281
    lib / MyModel.pm
2282
        / MyModel / book.pm
2283
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2284

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

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

            
2289
    package MyModel;
2290
    
2291
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2292
    
2293
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2294

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2299
    package MyModel::book;
2300
    
2301
    use base 'MyModel';
2302
    
2303
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2304

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2307
    package MyModel::company;
2308
    
2309
    use base 'MyModel';
2310
    
2311
    1;
2312
    
2313
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2314

            
update pod
Yuki Kimoto authored on 2011-03-13
2315
You can get model object by C<model()>.
2316

            
2317
    my $book_model    = $dbi->model('book');
2318
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2319

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

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

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

            
2326
Merge paramters.
2327

            
2328
$param:
2329

            
2330
    {key1 => [1, 1], key2 => 2}
2331

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

            
2334
    $dbi->method(
2335
        update_or_insert => sub {
2336
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2337
            
2338
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2339
        },
2340
        find_or_create   => sub {
2341
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2342
            
2343
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2344
        }
2345
    );
2346

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

            
2349
    $dbi->update_or_insert;
2350
    $dbi->find_or_create;
2351

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

            
2354
    $dbi->model('book')->method(
2355
        insert => sub { ... },
2356
        update => sub { ... }
2357
    );
2358
    
2359
    my $model = $dbi->model('book');
2360

            
2361
Set and get a L<DBIx::Custom::Model> object,
2362

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

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

            
2367
Create column clause for myself. The follwoing column clause is created.
2368

            
2369
    book.author as author,
2370
    book.title as title
2371

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2374
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2375
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2376
        user => 'ken',
2377
        password => '!LFKD%$&',
2378
        dbi_option => {mysql_enable_utf8 => 1}
2379
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2380

            
2381
Create a new L<DBIx::Custom> object.
2382

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

            
2385
    my $not_exists = $dbi->not_exists;
2386

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2390
=head2 C<register_filter>
2391

            
update pod
Yuki Kimoto authored on 2011-03-13
2392
    $dbi->register_filter(
2393
        # Time::Piece object to database DATE format
2394
        tp_to_date => sub {
2395
            my $tp = shift;
2396
            return $tp->strftime('%Y-%m-%d');
2397
        },
2398
        # database DATE format to Time::Piece object
2399
        date_to_tp => sub {
2400
           my $date = shift;
2401
           return Time::Piece->strptime($date, '%Y-%m-%d');
2402
        }
2403
    );
cleanup
yuki-kimoto authored on 2010-10-17
2404
    
update pod
Yuki Kimoto authored on 2011-03-13
2405
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2406

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

            
2409
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2410
        into => {
2411
            DATE => sub { ... },
2412
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2413
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2414
        from => {
2415
            # DATE
2416
            9 => sub { ... },
2417
            
2418
            # DATETIME or TIMESTAMP
2419
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2420
        }
2421
    );
2422

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2423
Filtering rule when data is send into and get from database.
2424
This has a little complex problem. 
2425
In C<into> you can specify type name as same as type name defined
2426
by create table, such as C<DATETIME> or C<DATE>.
2427
but in C<from> you can't specify type name defined by create table.
2428
You must specify data type, this is internal one.
2429
You get all data type by C<available_data_type>.
2430

            
2431
    print $dbi->available_data_type;
2432

            
2433
You can also specify multiple types
2434

            
2435
    $dbi->type_rule(
2436
        into => [
2437
            [qw/DATE DATETIME/] => sub { ... },
2438
        ],
2439
        from => {
2440
            # DATE
2441
            [qw/9 11/] => sub { ... },
2442
        }
2443
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2444

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2447
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2448
        table  => 'book',
2449
        column => ['author', 'title'],
2450
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2451
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2452
    
updated document
Yuki Kimoto authored on 2011-06-09
2453
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2454

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

            
2457
=over 4
2458

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2463
Append statement to last of SQL.
2464
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2465
=item C<column>
2466
    
updated document
Yuki Kimoto authored on 2011-06-09
2467
    column => 'author'
2468
    column => ['author', 'title']
2469

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2476
You can specify hash reference in array reference. This is EXPERIMENTAL.
updated pod
Yuki Kimoto authored on 2011-06-07
2477

            
updated document
Yuki Kimoto authored on 2011-06-09
2478
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2479
        {book => [qw/author title/]},
2480
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2481
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2482

            
updated document
Yuki Kimoto authored on 2011-06-09
2483
This is expanded to the following one by using C<col> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2484

            
2485
    book.author as "book.author",
2486
    book.title as "book.title",
2487
    person.name as "person.name",
2488
    person.age as "person.age"
2489

            
updated document
Yuki Kimoto authored on 2011-06-09
2490
You can specify array reference in array reference.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2491

            
updated document
Yuki Kimoto authored on 2011-06-09
2492
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2493
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2494
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2495

            
updated document
Yuki Kimoto authored on 2011-06-09
2496
Alias is quoted and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2497

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

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

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

            
2504
=item C<id>
2505

            
2506
    id => 4
2507
    id => [4, 5]
2508

            
2509
ID corresponding to C<primary_key>.
2510
You can select rows by C<id> and C<primary_key>.
2511

            
2512
    $dbi->select(
2513
        parimary_key => ['id1', 'id2'],
2514
        id => [4, 5],
2515
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2516
    );
2517

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2520
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2521
        where => {id1 => 4, id2 => 5},
2522
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2523
    );
2524
    
updated document
Yuki Kimoto authored on 2011-06-09
2525
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2526

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

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

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

            
2537
=item C<join>
2538

            
2539
    join => [
2540
        'left outer join company on book.company_id = company_id',
2541
        'left outer join location on company.location_id = location.id'
2542
    ]
2543
        
2544
Join clause. If column cluase or where clause contain table name like "company.name",
2545
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2546

            
2547
    $dbi->select(
2548
        table => 'book',
2549
        column => ['company.location_id as company__location_id'],
2550
        where => {'company.name' => 'Orange'},
2551
        join => [
2552
            'left outer join company on book.company_id = company.id',
2553
            'left outer join location on company.location_id = location.id'
2554
        ]
2555
    );
2556

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

            
2560
    select company.location_id as company__location_id
2561
    from book
2562
      left outer join company on book.company_id = company.id
2563
    where company.name = Orange
2564

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2576
=item C<type>
updated pod
Yuki Kimoto authored on 2011-06-08
2577

            
updated document
Yuki Kimoto authored on 2011-06-09
2578
Same as C<execute> method's C<type> option.
updated pod
Yuki Kimoto authored on 2011-06-08
2579

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2584
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2585

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2590
=item C<where>
2591
    
2592
    # Hash refrence
2593
    where => {author => 'Ken', 'title' => 'Perl'}
2594
    
2595
    # DBIx::Custom::Where object
2596
    where => $dbi->where(
2597
        clause => ['and', 'author = :author', 'title like :title'],
2598
        param  => {author => 'Ken', title => '%Perl%'}
2599
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2600

            
updated document
Yuki Kimoto authored on 2011-06-09
2601
    # String(with where_param option)
2602
    where => 'title like :title',
2603
    where_param => {title => '%Perl%'}
update pod
Yuki Kimoto authored on 2011-03-12
2604

            
updated document
Yuki Kimoto authored on 2011-06-09
2605
Where clause.
2606
    
improved pod
Yuki Kimoto authored on 2011-04-19
2607
=item C<wrap> EXPERIMENTAL
2608

            
2609
Wrap statement. This is array reference.
2610

            
2611
    $dbi->select(wrap => ['select * from (', ') as t where ROWNUM < 10']);
2612

            
2613
This option is for Oracle and SQL Server paging process.
2614

            
update pod
Yuki Kimoto authored on 2011-03-12
2615
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2616

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2621
Execute update statement.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2622

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2625
=over 4
2626

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2637
    id => 4
2638
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2639

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2643
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2644
        {title => 'Perl', author => 'Ken'}
2645
        parimary_key => ['id1', 'id2'],
2646
        id => [4, 5],
2647
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2648
    );
update pod
Yuki Kimoto authored on 2011-03-13
2649

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2652
    $dbi->update(
2653
        {title => 'Perl', author => 'Ken'}
2654
        where => {id1 => 4, id2 => 5},
2655
        table => 'book'
2656
    );
update pod
Yuki Kimoto authored on 2011-03-13
2657

            
updated document
Yuki Kimoto authored on 2011-06-09
2658
=item C<param>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2659

            
updated document
Yuki Kimoto authored on 2011-06-09
2660
    param => {title => 'Perl'}
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2661

            
updated document
Yuki Kimoto authored on 2011-06-09
2662
Update data.
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2663

            
updated document
Yuki Kimoto authored on 2011-06-09
2664
If C<update> method's arguments is odd numbers, first argument is received as C<param>.
update pod
Yuki Kimoto authored on 2011-03-13
2665

            
updated document
Yuki Kimoto authored on 2011-06-09
2666
    $dbi->update({title => 'Perl'}, table => 'book', where => {id => 2});
update pod
Yuki Kimoto authored on 2011-03-13
2667

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2685
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2686

            
updated document
Yuki Kimoto authored on 2011-06-09
2687
Same as C<select> method's C<where> option.
update pod
Yuki Kimoto authored on 2011-03-13
2688

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2689
=item C<type>
2690

            
2691
Same as C<execute> method's C<type> option.
2692

            
2693
=item C<type_rule_off> EXPERIMENTAL
2694

            
2695
Turn type rule off.
2696

            
updated pod
Yuki Kimoto authored on 2011-06-08
2697
=back
update pod
Yuki Kimoto authored on 2011-03-13
2698

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2703
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-08
2704
Options is same as C<update()>.
update pod
Yuki Kimoto authored on 2011-03-13
2705

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

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

            
2710
Create update parameter tag.
2711

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2714
C<no_set> option is DEPRECATED! use C<assing_param> instead.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2715

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

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

            
2723
Create a new L<DBIx::Custom::Where> object.
2724

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

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-08
2732
=head2 C<update_at()> DEPRECATED!
2733

            
2734
Update statement, using primary key.
2735

            
2736
    $dbi->update_at(
2737
        table => 'book',
2738
        primary_key => 'id',
2739
        where => '5',
2740
        param => {title => 'Perl'}
2741
    );
2742

            
2743
This method is same as C<update()> exept that
2744
C<primary_key> is specified and C<where> is constant value or array refrence.
2745
all option of C<update()> is available.
2746

            
2747
=head2 C<delete_at()> DEPRECATED!
2748

            
2749
Delete statement, using primary key.
2750

            
2751
    $dbi->delete_at(
2752
        table => 'book',
2753
        primary_key => 'id',
2754
        where => '5'
2755
    );
2756

            
2757
This method is same as C<delete()> exept that
2758
C<primary_key> is specified and C<where> is constant value or array refrence.
2759
all option of C<delete()> is available.
2760

            
2761
=head2 C<select_at()> DEPRECATED!
2762

            
2763
Select statement, using primary key.
2764

            
2765
    $dbi->select_at(
2766
        table => 'book',
2767
        primary_key => 'id',
2768
        where => '5'
2769
    );
2770

            
2771
This method is same as C<select()> exept that
2772
C<primary_key> is specified and C<where> is constant value or array refrence.
2773
all option of C<select()> is available.
2774

            
2775
=head2 C<register_tag> DEPRECATED!
2776

            
2777
    $dbi->register_tag(
2778
        update => sub {
2779
            my @columns = @_;
2780
            
2781
            # Update parameters
2782
            my $s = 'set ';
2783
            $s .= "$_ = ?, " for @columns;
2784
            $s =~ s/, $//;
2785
            
2786
            return [$s, \@columns];
2787
        }
2788
    );
2789

            
2790
Register tag, used by C<execute()>.
2791

            
2792
See also L<Tags/Tags> about tag registered by default.
2793

            
2794
Tag parser receive arguments specified in tag.
2795
In the following tag, 'title' and 'author' is parser arguments
2796

            
2797
    {update_param title author} 
2798

            
2799
Tag parser must return array refrence,
2800
first element is the result statement, 
2801
second element is column names corresponding to place holders.
2802

            
2803
In this example, result statement is 
2804

            
2805
    set title = ?, author = ?
2806

            
2807
Column names is
2808

            
2809
    ['title', 'author']
2810

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2811
=head1 Parameter
2812

            
2813
Parameter start at ':'. This is replaced to place holoder
2814

            
2815
    $dbi->execute(
2816
        "select * from book where title = :title and author = :author"
2817
        param => {title => 'Perl', author => 'Ken'}
2818
    );
2819

            
2820
    "select * from book where title = ? and author = ?"
2821

            
2822
=head1 Tags DEPRECATED!
2823

            
2824
B<Tag> system is DEPRECATED! use parameter system :name instead.
2825
Parameter is simple and readable.
2826

            
2827
Note that you can't use both tag and paramter at same time.
cleanup
Yuki Kimoto authored on 2011-01-25
2828

            
2829
The following tags is available.
2830

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2831
=head2 C<?> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2832

            
2833
Placeholder tag.
2834

            
2835
    {? NAME}    ->   ?
2836

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2837
=head2 C<=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2838

            
2839
Equal tag.
2840

            
2841
    {= NAME}    ->   NAME = ?
2842

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2843
=head2 C<E<lt>E<gt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2844

            
2845
Not equal tag.
2846

            
2847
    {<> NAME}   ->   NAME <> ?
2848

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2849
=head2 C<E<lt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2850

            
2851
Lower than tag
2852

            
2853
    {< NAME}    ->   NAME < ?
2854

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2855
=head2 C<E<gt>> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2856

            
2857
Greater than tag
2858

            
2859
    {> NAME}    ->   NAME > ?
2860

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2861
=head2 C<E<gt>=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2862

            
2863
Greater than or equal tag
2864

            
2865
    {>= NAME}   ->   NAME >= ?
2866

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2867
=head2 C<E<lt>=> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2868

            
2869
Lower than or equal tag
2870

            
2871
    {<= NAME}   ->   NAME <= ?
2872

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2873
=head2 C<like> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2874

            
2875
Like tag
2876

            
2877
    {like NAME}   ->   NAME like ?
2878

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2879
=head2 C<in> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2880

            
2881
In tag.
2882

            
2883
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2884

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2885
=head2 C<insert_param> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2886

            
2887
Insert parameter tag.
2888

            
2889
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2890

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2891
=head2 C<update_param> DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-25
2892

            
2893
Updata parameter tag.
2894

            
2895
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2896

            
updated pod
Yuki Kimoto authored on 2011-06-08
2897
=head2 C<insert_at()> DEPRECATED!
2898

            
2899
Insert statement, using primary key.
2900

            
2901
    $dbi->insert_at(
2902
        table => 'book',
2903
        primary_key => 'id',
2904
        where => '5',
2905
        param => {title => 'Perl'}
2906
    );
2907

            
2908
This method is same as C<insert()> exept that
2909
C<primary_key> is specified and C<where> is constant value or array refrence.
2910
all option of C<insert()> is available.
2911

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

            
2914
=head2 C<DBIX_CUSTOM_DEBUG>
2915

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

            
2919
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2920

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

            
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
2923
=head1 STABILITY
2924

            
cleanup
Yuki Kimoto authored on 2011-01-25
2925
L<DBIx::Custom> is stable. APIs keep backword compatible
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2926
except EXPERIMENTAL one in the feature.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
2927

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

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

            
2932
C<< <kimoto.yuki at gmail.com> >>
2933

            
2934
L<http://github.com/yuki-kimoto/DBIx-Custom>
2935

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2936
=head1 AUTHOR
2937

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

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

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

            
2944
This program is free software; you can redistribute it and/or modify it
2945
under the same terms as Perl itself.
2946

            
2947
=cut