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

            
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
3
our $VERSION = '0.1673';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

            
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6
use strict;
7
use warnings;
8

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
9
use base 'Object::Simple';
many change
yuki-kimoto authored on 2010-02-11
10

            
packaging one directory
yuki-kimoto authored on 2009-11-16
11
use Carp 'croak';
12
use DBI;
13
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
14
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
15
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
16
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
17
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
19
use DBIx::Custom::Util;
update document
yuki-kimoto authored on 2010-05-27
20
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

            
added environment variable D...
Yuki Kimoto authored on 2011-04-02
22
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0;
23

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
24
our @COMMON_ARGS = qw/table query filter type/;
cleanup
Yuki Kimoto authored on 2011-03-21
25

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

            
added helper method
yuki-kimoto authored on 2010-10-17
65
our $AUTOLOAD;
66
sub AUTOLOAD {
67
    my $self = shift;
68

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
85
sub apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
86
    my ($self, $table, @cinfos) = @_;
87

            
88
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
89
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
90
    $self->{filter}{out} ||= {};
91
    $self->{filter}{in} ||= {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
92
    $self->{filter}{end} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
93
    
cleanup
Yuki Kimoto authored on 2011-04-02
94
    # Usage
many changed
Yuki Kimoto authored on 2011-01-23
95
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
96
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
97
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
cleanup
Yuki Kimoto authored on 2011-04-02
98
    
99
    # Apply filter
many changed
Yuki Kimoto authored on 2011-01-23
100
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
101
        
many changed
Yuki Kimoto authored on 2011-01-23
102
        # Column
103
        my $column = $cinfos[$i];
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
104
        if (ref $column eq 'ARRAY') {
105
            foreach my $c (@$column) {
106
                push @cinfos, $c, $cinfos[$i + 1];
107
            }
108
            next;
109
        }
110
        
cleanup
Yuki Kimoto authored on 2011-04-02
111
        # Filter infomation
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
112
        my $finfo = $cinfos[$i + 1] || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
113
        croak "$usage (table: $table)" unless  ref $finfo eq 'HASH';
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
114
        foreach my $ftype (keys %$finfo) {
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
115
            croak "$usage (table: $table 2)" unless $ftype eq 'in' || $ftype eq 'out'
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
116
                             || $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
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
135
            croak qq{Filter "$filter" is not registered}
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

            
cleanup
Yuki Kimoto authored on 2011-03-21
152
sub column {
153
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
154
    
cleanup
Yuki Kimoto authored on 2011-04-02
155
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
156
    my $q = $self->reserved_word_quote;
157
    
cleanup
Yuki Kimoto authored on 2011-04-02
158
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
159
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
160
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
161
    push @column, "$q$table$q.$q$_$q as $q${table}${q}__$q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
162
    
163
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
164
}
165

            
packaging one directory
yuki-kimoto authored on 2009-11-16
166
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
167
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
168
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
169
    # Connect
170
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
171
    
cleanup
Yuki Kimoto authored on 2011-04-02
172
    # Set process ID
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
173
    $self->pid($$);
174
    
packaging one directory
yuki-kimoto authored on 2009-11-16
175
    return $self;
176
}
177

            
cleanup
yuki-kimoto authored on 2010-10-17
178
sub create_query {
179
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
180
    
cleanup
yuki-kimoto authored on 2010-10-17
181
    # Cache
182
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
183
    
cleanup
Yuki Kimoto authored on 2011-04-02
184
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
185
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
186
    
187
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
188
    if ($cache) {
189
        
190
        # Get query
191
        my $q = $self->cache_method->($self, $source);
192
        
193
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
194
        if ($q) {
195
            $query = DBIx::Custom::Query->new($q);
196
            $query->filters($self->filters);
197
        }
cleanup
yuki-kimoto authored on 2010-10-17
198
    }
199
    
cleanup
Yuki Kimoto authored on 2011-04-02
200
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
201
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
202

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
212
        # Save query to cache
213
        $self->cache_method->(
214
            $self, $source,
215
            {
216
                sql     => $query->sql, 
217
                columns => $query->columns,
218
                tables  => $query->tables
219
            }
220
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
221
    }
222
    
cleanup
yuki-kimoto authored on 2010-10-17
223
    # Prepare statement handle
224
    my $sth;
225
    eval { $sth = $self->dbh->prepare($query->{sql})};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
226
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
227
    
cleanup
yuki-kimoto authored on 2010-10-17
228
    # Set statement handle
229
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
230
    
cleanup
Yuki Kimoto authored on 2011-02-09
231
    # Set filters
232
    $query->filters($self->filters);
233
    
cleanup
yuki-kimoto authored on 2010-10-17
234
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
235
}
236

            
update pod
Yuki Kimoto authored on 2011-03-13
237
sub dbh {
238
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
239
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
240
    # Set
241
    if (@_) {
242
        $self->{dbh} = $_[0];
243
        
244
        return $self;
245
    }
246
    
247
    # Get
248
    else {
249
        # From Connction manager
250
        if (my $connector = $self->connector) {
251
            croak "connector must have dbh() method"
252
              unless ref $connector && $connector->can('dbh');
253
              
254
            return $self->{dbh} = $connector->dbh;
255
        }
256
        
257
        return $self->{dbh} ||= $self->_connect;
update pod
Yuki Kimoto authored on 2011-03-13
258
    }
259
}
260

            
cleanup
Yuki Kimoto authored on 2011-03-21
261
our %DELETE_ARGS
cleanup
Yuki Kimoto authored on 2011-03-21
262
  = map { $_ => 1 } @COMMON_ARGS, qw/where append allow_delete_all/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
263

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
267
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
268
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-02
269
        croak qq{Argument "$name" is wrong name}
cleanup
Yuki Kimoto authored on 2011-03-21
270
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
271
    }
272
    
273
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
274
    my $table = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
275
    croak qq{"table" option must be specified} unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
276
    my $where            = delete $args{where} || {};
277
    my $append           = delete $args{append};
278
    my $allow_delete_all = delete $args{allow_delete_all};
cleanup
Yuki Kimoto authored on 2011-04-02
279
    my $query_return     = delete $args{query};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
280

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
281
    # Where
cleanup
Yuki Kimoto authored on 2011-04-02
282
    $where = $self->_where_to_obj($where);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
283
    
cleanup
Yuki Kimoto authored on 2011-04-02
284
    # Where clause
285
    my $where_clause = $where->to_string;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
286
    croak qq{"where" must be specified}
cleanup
Yuki Kimoto authored on 2011-04-02
287
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
288

            
cleanup
Yuki Kimoto authored on 2011-04-02
289
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
290
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
291
    my $q = $self->reserved_word_quote;
292
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
293
    push @sql, $append if $append;
294
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
295
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
296
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
297
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
298
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
299
    
packaging one directory
yuki-kimoto authored on 2009-11-16
300
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
301
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
302
        $query,
cleanup
Yuki Kimoto authored on 2011-04-02
303
        param => $where->param,
cleanup
Yuki Kimoto authored on 2011-03-21
304
        table => $table,
305
        %args
306
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
307
}
308

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
311
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
312

            
313
sub delete_at {
314
    my ($self, %args) = @_;
315
    
cleanup
Yuki Kimoto authored on 2011-04-02
316
    # Arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
317
    my $primary_keys = delete $args{primary_key};
318
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-04-02
319
    my $where = delete $args{where};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
320
    
cleanup
Yuki Kimoto authored on 2011-04-02
321
    # Check arguments
322
    foreach my $name (keys %args) {
323
        croak qq{Argument "$name" is wrong name}
324
          unless $DELETE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
325
    }
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
326
    
cleanup
Yuki Kimoto authored on 2011-04-02
327
    # Create where parameter
328
    my $where_param = $self->_create_where_param($where, $primary_keys);
329

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
330
    
cleanup
Yuki Kimoto authored on 2011-04-02
331
    return $self->delete(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
332
}
333

            
added helper method
yuki-kimoto authored on 2010-10-17
334
sub DESTROY { }
335

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
336
sub create_model {
337
    my $self = shift;
338
    
cleanup
Yuki Kimoto authored on 2011-04-02
339
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
340
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
341
    $args->{dbi} = $self;
342
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
343
    my $model_name  = delete $args->{name};
344
    my $model_table = delete $args->{table};
345
    $model_name ||= $model_table;
346
    
cleanup
Yuki Kimoto authored on 2011-04-02
347
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
348
    my $model = $model_class->new($args);
349
    $model->name($model_name) unless $model->name;
350
    $model->table($model_table) unless $model->table;
351
    
352
    # Apply filter
353
    croak "$model_class filter must be array reference"
354
      unless ref $model->filter eq 'ARRAY';
355
    $self->apply_filter($model->table, @{$model->filter});
356
    
cleanup
Yuki Kimoto authored on 2011-04-02
357
    # Associate table with model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
358
    croak "Table name is duplicated"
359
      if exists $self->{_model_from}->{$model->table};
360
    $self->{_model_from}->{$model->table} = $model->name;
361

            
362
    # Table alias
363
    $self->{_table_alias} ||= {};
364
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
365
    
366
    # Set model
367
    $self->model($model->name, $model);
368
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
369
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
370
}
371

            
372
sub each_column {
373
    my ($self, $cb) = @_;
374
    
375
    # Iterate all tables
376
    my $sth_tables = $self->dbh->table_info;
377
    while (my $table_info = $sth_tables->fetchrow_hashref) {
378
        
379
        # Table
380
        my $table = $table_info->{TABLE_NAME};
381
        
382
        # Iterate all columns
383
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
384
        while (my $column_info = $sth_columns->fetchrow_hashref) {
385
            my $column = $column_info->{COLUMN_NAME};
386
            $self->$cb($table, $column, $column_info);
387
        }
388
    }
389
}
390

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

            
393
sub execute {
cleanup
yuki-kimoto authored on 2010-10-17
394
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
395
    
cleanup
Yuki Kimoto authored on 2011-04-02
396
    # Arguments
cleanup
Yuki Kimoto authored on 2011-04-02
397
    my $param  = delete $args{param} || {};
cleanup
Yuki Kimoto authored on 2011-04-02
398
    my $tables = delete $args{table} || [];
399
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
400
    my $filter = delete $args{filter};
401
    $filter = DBIx::Custom::Util::array_to_hash($filter);
402
    my $type = delete $args{type};
403
    $type = DBIx::Custom::Util::array_to_hash($type);
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
404
    
cleanup
Yuki Kimoto authored on 2011-03-09
405
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
406
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-02
407
        croak qq{Argument "$name" is wrong name}
cleanup
Yuki Kimoto authored on 2011-03-21
408
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
409
    }
410
    
cleanup
Yuki Kimoto authored on 2011-04-02
411
    # Create query
412
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-04-02
413
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
414
    
cleanup
Yuki Kimoto authored on 2011-04-02
415
    # Tables
416
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
417
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
418
    $tables = $self->_remove_duplicate_table($tables, $main_table);
419
    if (my $q = $self->reserved_word_quote) {
420
        $_ =~ s/$q//g for @$tables;
421
    }
cleanup
Yuki Kimoto authored on 2011-04-02
422
    
423
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
424
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
425
        
cleanup
Yuki Kimoto authored on 2011-04-02
426
        # No need
427
        next unless my $alias = $self->{_table_alias}->{$table};
428
        $self->{filter} ||= {};
429
        next if $self->{filter}{out}{$table};
430
        
431
        # Filter
432
        $self->{filter}{out} ||= {};
433
        $self->{filter}{in}  ||= {};
434
        $self->{filter}{end} ||= {};
435
        
436
        # Create alias filter
437
        foreach my $type (qw/out in end/) {
438
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
439
            foreach my $filter_name (@filter_names) {
440
                my $filter_name_alias = $filter_name;
441
                $filter_name_alias =~ s/^$alias\./$table\./;
442
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
443
                $self->{filter}{$type}{$table}{$filter_name_alias}
444
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
445
            }
446
        }
447
    }
cleanup
Yuki Kimoto authored on 2011-04-02
448
    
449
    # Applied filter
450
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
451
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
452
        $applied_filter = {
453
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
454
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
455
        }
456
    }
cleanup
Yuki Kimoto authored on 2011-04-02
457
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
458
    
cleanup
Yuki Kimoto authored on 2011-04-02
459
    # Replace filter name to code
460
    foreach my $column (keys %$filter) {
461
        my $name = $filter->{$column};
462
        if (!defined $name) {
463
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
464
        }
cleanup
Yuki Kimoto authored on 2011-04-02
465
        elsif (ref $name ne 'CODE') {
466
          croak qq{Filter "$name" is not registered"}
467
            unless exists $self->filters->{$name};
468
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
469
        }
470
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
471
    
cleanup
Yuki Kimoto authored on 2011-04-02
472
    # Create bind values
473
    my $bind = $self->_create_bind_values(
474
        $param,
475
        $query->columns,
476
        $filter,
477
        $type
478
    );
cleanup
yuki-kimoto authored on 2010-10-17
479
    
480
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
481
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
482
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
483
    eval {
484
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
485
            my $type = $bind->[$i]->{type};
486
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
487
        }
488
        $affected = $sth->execute;
489
    };
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
490
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
491
    
added environment variable D...
Yuki Kimoto authored on 2011-04-02
492
    # Output SQL for debug
493
    warn $query->sql . "\n" if DEBUG;
494
    
cleanup
Yuki Kimoto authored on 2011-04-02
495
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
496
    if ($sth->{NUM_OF_FIELDS}) {
497
        
cleanup
Yuki Kimoto authored on 2011-04-02
498
        # Filter
499
        my $filter = {};
500
        $filter->{in}  = {};
501
        $filter->{end} = {};
cleanup
Yuki Kimoto authored on 2011-01-12
502
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
503
            foreach my $way (qw/in end/) {
504
                $filter->{$way} = {
505
                    %{$filter->{$way}},
506
                    %{$self->{filter}{$way}{$table} || {}}
507
                };
508
            }
cleanup
Yuki Kimoto authored on 2011-01-12
509
        }
510
        
511
        # Result
512
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
513
            sth            => $sth,
514
            filters        => $self->filters,
515
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
516
            default_filter => $self->{default_in_filter},
cleanup
Yuki Kimoto authored on 2011-04-02
517
            filter         => $filter->{in} || {},
518
            end_filter     => $filter->{end} || {}
cleanup
yuki-kimoto authored on 2010-10-17
519
        );
520

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
528
our %INSERT_ARGS = map { $_ => 1 } @COMMON_ARGS, qw/param append/;
update pod
Yuki Kimoto authored on 2011-03-13
529

            
cleanup
yuki-kimoto authored on 2010-10-17
530
sub insert {
531
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
532
    
cleanup
yuki-kimoto authored on 2010-10-17
533
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
534
    my $table  = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
535
    croak qq{"table" option must be specified} unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
536
    my $param  = delete $args{param} || {};
537
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-04-02
538
    my $query_return  = delete $args{query};
539

            
540
    # Check arguments
541
    foreach my $name (keys %args) {
542
        croak qq{Argument "$name" is wrong name}
543
          unless $INSERT_ARGS{$name};
544
    }
545

            
546
    # Reserved word quote
547
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
548
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
549
    # Columns
550
    my @columns;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
551
    my $safety = $self->safety_character;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
552
    foreach my $column (keys %$param) {
553
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
554
          unless $column =~ /^[$safety\.]+$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
555
          $column = "$q$column$q";
556
          $column =~ s/\./$q.$q/;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
557
        push @columns, $column;
558
    }
cleanup
yuki-kimoto authored on 2010-10-17
559
    
cleanup
Yuki Kimoto authored on 2011-04-02
560
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
561
    my @sql;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
562
    push @sql, "insert into $q$table$q {insert_param ". join(' ', @columns) . '}';
cleanup
Yuki Kimoto authored on 2011-01-27
563
    push @sql, $append if $append;
564
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
565
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
566
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
567
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
568
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
569
    
packaging one directory
yuki-kimoto authored on 2009-11-16
570
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
571
    return $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
572
        $query,
cleanup
Yuki Kimoto authored on 2011-04-02
573
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
574
        table => $table,
575
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
576
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
577
}
578

            
cleanup
Yuki Kimoto authored on 2011-03-21
579
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
580

            
581
sub insert_at {
582
    my ($self, %args) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
583

            
584
    # Arguments
585
    my $primary_keys = delete $args{primary_key};
586
    $primary_keys = [$primary_keys] unless ref $primary_keys;
587
    my $where = delete $args{where};
588
    my $param = delete $args{param};
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
589
    
cleanup
Yuki Kimoto authored on 2011-04-02
590
    # Check arguments
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
591
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-02
592
        croak qq{Argument "$name" is wrong name}
cleanup
Yuki Kimoto authored on 2011-03-21
593
          unless $INSERT_AT_ARGS{$name};
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
594
    }
595
    
cleanup
Yuki Kimoto authored on 2011-04-02
596
    # Create where parameter
597
    my $where_param = $self->_create_where_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-04-02
598
    $param = $self->merge_param($where_param, $param);
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
599
    
600
    return $self->insert(param => $param, %args);
601
}
602

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
603
sub insert_param_tag {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
604
    my ($self, $param) = @_;
605
    
cleanup
Yuki Kimoto authored on 2011-04-02
606
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
607
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
608
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
609
    my @columns;
610
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
611
    foreach my $column (keys %$param) {
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
612
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
613
          unless $column =~ /^[$safety\.]+$/;
cleanup
Yuki Kimoto authored on 2011-04-02
614
        $column = "$q$column$q";
615
        $column =~ s/\./$q.$q/;
616
        push @columns, $column;
617
        push @placeholders, "{? $column}";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
618
    }
619
    
cleanup
Yuki Kimoto authored on 2011-04-02
620
    return '(' . join(', ', @columns) . ') ' . 'values ' .
621
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
622
}
623

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
624
sub include_model {
625
    my ($self, $name_space, $model_infos) = @_;
626
    
cleanup
Yuki Kimoto authored on 2011-04-02
627
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
628
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
629
    
630
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
631
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
632

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

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
687
sub merge_param {
688
    my ($self, @params) = @_;
689
    
cleanup
Yuki Kimoto authored on 2011-04-02
690
    # Merge parameters
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
691
    my $param = {};
692
    foreach my $p (@params) {
693
        foreach my $column (keys %$p) {
694
            if (exists $param->{$column}) {
695
                $param->{$column} = [$param->{$column}]
696
                  unless ref $param->{$column} eq 'ARRAY';
697
                push @{$param->{$column}}, $p->{$column};
698
            }
699
            else {
700
                $param->{$column} = $p->{$column};
701
            }
702
        }
703
    }
704
    
705
    return $param;
706
}
707

            
cleanup
Yuki Kimoto authored on 2011-03-21
708
sub method {
709
    my $self = shift;
710
    
cleanup
Yuki Kimoto authored on 2011-04-02
711
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
712
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
713
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
714
    
715
    return $self;
716
}
717

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
735
sub mycolumn {
736
    my ($self, $table, $columns) = @_;
737
    
cleanup
Yuki Kimoto authored on 2011-04-02
738
    # Create column clause
739
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
740
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
741
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
742
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
743
    
744
    return join (', ', @column);
745
}
746

            
added dbi_options attribute
kimoto authored on 2010-12-20
747
sub new {
748
    my $self = shift->SUPER::new(@_);
749
    
cleanup
Yuki Kimoto authored on 2011-04-02
750
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
751
    my @attrs = keys %$self;
752
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-02
753
        croak qq{"$attr" is wrong name}
added dbi_options attribute
kimoto authored on 2010-12-20
754
          unless $self->can($attr);
755
    }
cleanup
Yuki Kimoto authored on 2011-04-02
756
    
757
    # Register tag
cleanup
Yuki Kimoto authored on 2011-01-25
758
    $self->register_tag(
759
        '?'     => \&DBIx::Custom::Tag::placeholder,
760
        '='     => \&DBIx::Custom::Tag::equal,
761
        '<>'    => \&DBIx::Custom::Tag::not_equal,
762
        '>'     => \&DBIx::Custom::Tag::greater_than,
763
        '<'     => \&DBIx::Custom::Tag::lower_than,
764
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
765
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
766
        'like'  => \&DBIx::Custom::Tag::like,
767
        'in'    => \&DBIx::Custom::Tag::in,
768
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
769
        'update_param' => \&DBIx::Custom::Tag::update_param
770
    );
added dbi_options attribute
kimoto authored on 2010-12-20
771
    
772
    return $self;
773
}
774

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

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
787
sub register_tag { shift->query_builder->register_tag(@_) }
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
788

            
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
789
sub replace {
790
    my ($self, $join, $search, $replace) = @_;
791
    
cleanup
Yuki Kimoto authored on 2011-04-02
792
    # Replace
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
793
    my @replace_join;
794
    my $is_replaced;
795
    foreach my $j (@$join) {
796
        if ($search eq $j) {
797
            push @replace_join, $replace;
798
            $is_replaced = 1;
799
        }
800
        else {
801
            push @replace_join, $j;
802
        }
803
    }
804
    croak qq{Can't replace "$search" with "$replace"} unless $is_replaced;
805
    
change retern value to array...
Yuki Kimoto authored on 2011-04-04
806
    return \@replace_join;
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
807
}
808

            
cleanup
Yuki Kimoto authored on 2011-03-21
809
our %SELECT_ARGS
cleanup
Yuki Kimoto authored on 2011-04-01
810
  = map { $_ => 1 } @COMMON_ARGS, qw/column where append relation join param/;
refactoring select
yuki-kimoto authored on 2010-04-28
811

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
815
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
816
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
817
    my $tables = ref $table eq 'ARRAY' ? $table
818
               : defined $table ? [$table]
819
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
820
    my $columns   = delete $args{column};
821
    my $where     = delete $args{where} || {};
822
    my $append    = delete $args{append};
823
    my $join      = delete $args{join} || [];
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
824
    croak qq{"join" must be array reference}
825
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
826
    my $relation = delete $args{relation};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
827
    my $param = delete $args{param} || {};
cleanup
Yuki Kimoto authored on 2011-04-02
828
    my $query_return = $args{query};
829

            
830
    # Check arguments
831
    foreach my $name (keys %args) {
832
        croak qq{Argument "$name" is wrong name}
833
          unless $SELECT_ARGS{$name};
834
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
835
    
cleanup
Yuki Kimoto authored on 2011-03-09
836
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
837
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
838
    
cleanup
Yuki Kimoto authored on 2011-04-02
839
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
840
    my @sql;
841
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
842
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
843
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
844
    if ($columns) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
845
        $columns = [$columns] if ! ref $columns;
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
846
        foreach my $column (@$columns) {
cleanup
Yuki Kimoto authored on 2011-04-02
847
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
848
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
849
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
850
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
851
    }
852
    else { push @sql, '*' }
853
    
854
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
855
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
856
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
857
    if ($relation) {
858
        my $found = {};
859
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
860
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
861
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
862
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
863
    }
cleanup
Yuki Kimoto authored on 2011-03-30
864
    else {
865
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
866
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
867
    }
868
    pop @sql if ($sql[-1] || '') eq ',';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
869
    croak "Not found table name" unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
870

            
cleanup
Yuki Kimoto authored on 2011-04-02
871
    # Add tables in parameter
872
    unshift @$tables, @{$self->_search_tables(join(' ', keys %$param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
873
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
874
    # Where
cleanup
Yuki Kimoto authored on 2011-04-02
875
    $where = $self->_where_to_obj($where);
876
    $param = keys %$param ? $self->merge_param($param, $where->param)
877
                          : $where->param;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
878
    
879
    # String where
cleanup
Yuki Kimoto authored on 2011-04-02
880
    my $where_clause = $where->to_string;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
881
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
882
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
883
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
884
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
885
    # Push join
886
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
887
    
cleanup
Yuki Kimoto authored on 2011-03-09
888
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
889
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
890
    
cleanup
Yuki Kimoto authored on 2011-03-08
891
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
892
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
893
    
cleanup
Yuki Kimoto authored on 2011-04-02
894
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
895
    push @sql, $append if $append;
896
    
897
    # SQL
898
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
899
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
900
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
901
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
902
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
903
    
packaging one directory
yuki-kimoto authored on 2009-11-16
904
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
905
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
906
        $query,
cleanup
Yuki Kimoto authored on 2011-04-02
907
        param => $param, 
cleanup
Yuki Kimoto authored on 2011-03-21
908
        table => $tables,
909
        %args
910
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
911
    
912
    return $result;
913
}
914

            
cleanup
Yuki Kimoto authored on 2011-03-21
915
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
916

            
917
sub select_at {
918
    my ($self, %args) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
919

            
920
    # Arguments
921
    my $primary_keys = delete $args{primary_key};
922
    $primary_keys = [$primary_keys] unless ref $primary_keys;
923
    my $where = delete $args{where};
924
    my $param = delete $args{param};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
925
    
cleanup
Yuki Kimoto authored on 2011-04-02
926
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
927
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-02
928
        croak qq{Argument "$name" is wrong name}
cleanup
Yuki Kimoto authored on 2011-03-21
929
          unless $SELECT_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
930
    }
931
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
932
    # Table
933
    croak qq{"table" option must be specified} unless $args{table};
934
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
935
    
cleanup
Yuki Kimoto authored on 2011-04-02
936
    # Create where parameter
937
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
938
    
cleanup
Yuki Kimoto authored on 2011-04-02
939
    return $self->select(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
940
}
941

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
942
sub setup_model {
943
    my $self = shift;
944
    
cleanup
Yuki Kimoto authored on 2011-04-02
945
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
946
    $self->each_column(
947
        sub {
948
            my ($self, $table, $column, $column_info) = @_;
949
            if (my $model = $self->models->{$table}) {
950
                push @{$model->columns}, $column;
951
            }
952
        }
953
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
954
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
955
}
956

            
cleanup
Yuki Kimoto authored on 2011-03-21
957
our %UPDATE_ARGS
958
  = map { $_ => 1 } @COMMON_ARGS, qw/param where append allow_update_all/;
cleanup
yuki-kimoto authored on 2010-10-17
959

            
960
sub update {
961
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
962

            
cleanup
yuki-kimoto authored on 2010-10-17
963
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
964
    my $table = delete $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
965
    croak qq{"table" option must be specified} unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
966
    my $param            = delete $args{param} || {};
967
    my $where            = delete $args{where} || {};
968
    my $append           = delete $args{append} || '';
969
    my $allow_update_all = delete $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
970
    
cleanup
Yuki Kimoto authored on 2011-04-02
971
    # Check argument names
972
    foreach my $name (keys %args) {
973
        croak qq{Argument "$name" is wrong name}
974
          unless $UPDATE_ARGS{$name};
975
    }
976
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
977
    # Columns
978
    my @columns;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
979
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
980
    my $q = $self->reserved_word_quote;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
981
    foreach my $column (keys %$param) {
982
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
983
          unless $column =~ /^[$safety\.]+$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
984
          $column = "$q$column$q";
985
          $column =~ s/\./$q.$q/;
986
        push @columns, "$column";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
987
    }
988
        
cleanup
yuki-kimoto authored on 2010-10-17
989
    # Update clause
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
990
    my $update_clause = '{update_param ' . join(' ', @columns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
991

            
992
    # Where
cleanup
Yuki Kimoto authored on 2011-04-02
993
    $where = $self->_where_to_obj($where);
994
    my $where_clause = $where->to_string;
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
995
    croak qq{"where" must be specified}
cleanup
Yuki Kimoto authored on 2011-04-02
996
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
997
    
cleanup
Yuki Kimoto authored on 2011-04-02
998
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
999
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
1000
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1001
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1002
    
cleanup
Yuki Kimoto authored on 2011-04-02
1003
    # Merge parameters
1004
    $param = $self->merge_param($param, $where->param);
cleanup
yuki-kimoto authored on 2010-10-17
1005
    
cleanup
Yuki Kimoto authored on 2011-01-27
1006
    # SQL
1007
    my $sql = join(' ', @sql);
1008
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1009
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
1010
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1011
    return $query if $args{query};
1012
    
cleanup
yuki-kimoto authored on 2010-10-17
1013
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1014
    my $ret_val = $self->execute(
1015
        $query,
1016
        param  => $param, 
1017
        table => $table,
1018
        %args
1019
    );
cleanup
yuki-kimoto authored on 2010-10-17
1020
    
1021
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1022
}
1023

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
1026
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1027

            
1028
sub update_at {
1029
    my ($self, %args) = @_;
1030
    
cleanup
Yuki Kimoto authored on 2011-04-02
1031
    # Arguments
1032
    my $primary_keys = delete $args{primary_key};
1033
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1034
    my $where = delete $args{where};
1035
    
1036

            
1037
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1038
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-02
1039
        croak qq{Argument "$name" is wrong name}
cleanup
Yuki Kimoto authored on 2011-03-21
1040
          unless $UPDATE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1041
    }
1042
    
cleanup
Yuki Kimoto authored on 2011-04-02
1043
    # Create where parameter
1044
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1045
    
cleanup
Yuki Kimoto authored on 2011-04-02
1046
    return $self->update(where => $where_param, %args);
1047
}
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1048

            
cleanup
Yuki Kimoto authored on 2011-04-02
1049
sub _create_where_param {
1050
    my ($self, $where, $primary_keys) = @_;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1051
    
cleanup
Yuki Kimoto authored on 2011-04-02
1052
    # Create where parameter
1053
    my $where_param = {};
1054
    if ($where) {
1055
        $where = [$where] unless ref $where;
1056
        croak qq{"where" must be constant value or array reference}
1057
          unless !ref $where || ref $where eq 'ARRAY';
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1058
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-04-02
1059
           $where_param->{$primary_keys->[$i]} = $where->[$i];
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1060
        }
1061
    }
1062
    
cleanup
Yuki Kimoto authored on 2011-04-02
1063
    return $where_param;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1064
}
1065

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1066
sub update_param_tag {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1067
    my ($self, $param, $opt) = @_;
1068
    
cleanup
Yuki Kimoto authored on 2011-04-02
1069
    # Create update parameter tag
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1070
    my @params;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1071
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1072
    my $q = $self->reserved_word_quote;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1073
    foreach my $column (keys %$param) {
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1074
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1075
          unless $column =~ /^[$safety\.]+$/;
cleanup
Yuki Kimoto authored on 2011-04-02
1076
        my $column = "$q$column$q";
1077
        $column =~ s/\./$q.$q/;
1078
        push @params, "$column = {? $column}";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1079
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1080
    my $tag;
1081
    $tag .= 'set ' unless $opt->{no_set};
1082
    $tag .= join(', ', @params);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1083
    
cleanup
Yuki Kimoto authored on 2011-04-02
1084
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1085
}
1086

            
cleanup
Yuki Kimoto authored on 2011-01-25
1087
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1088
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1089
    
1090
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1091
    return DBIx::Custom::Where->new(
1092
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1093
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1094
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1095
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1096
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1097
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1098

            
cleanup
Yuki Kimoto authored on 2011-04-02
1099
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1100
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1101
    
cleanup
Yuki Kimoto authored on 2011-04-02
1102
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1103
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1104
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1105
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1106
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1107
        
1108
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1109
        my $value;
1110
        if(ref $params->{$column} eq 'ARRAY') {
1111
            my $i = $count->{$column} || 0;
1112
            $i += $not_exists->{$column} || 0;
1113
            my $found;
1114
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1115
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1116
                    $not_exists->{$column}++;
1117
                }
1118
                else  {
1119
                    $value = $params->{$column}->[$k];
1120
                    $found = 1;
1121
                    last
1122
                }
1123
            }
1124
            next unless $found;
1125
        }
1126
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1127
        
cleanup
Yuki Kimoto authored on 2011-01-12
1128
        # Filter
1129
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1130
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1131
        # Type
1132
        push @$bind, {
1133
            value => $f ? $f->($value) : $value,
1134
            type => $type->{$column}
1135
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1136
        
1137
        # Count up 
1138
        $count->{$column}++;
1139
    }
1140
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1141
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1142
}
1143

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1144
sub _connect {
1145
    my $self = shift;
1146
    
1147
    # Attributes
1148
    my $data_source = $self->data_source;
1149
    croak qq{"data_source" must be specified to connect()"}
1150
      unless $data_source;
1151
    my $user        = $self->user;
1152
    my $password    = $self->password;
1153
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
1154
    
1155
    # Connect
1156
    my $dbh = eval {DBI->connect(
1157
        $data_source,
1158
        $user,
1159
        $password,
1160
        {
1161
            %{$self->default_dbi_option},
1162
            %$dbi_option
1163
        }
1164
    )};
1165
    
1166
    # Connect error
1167
    croak $@ if $@;
1168
    
1169
    return $dbh;
1170
}
1171

            
cleanup
yuki-kimoto authored on 2010-10-17
1172
sub _croak {
1173
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1174
    
1175
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1176
    $append ||= "";
1177
    
1178
    # Verbose
1179
    if ($Carp::Verbose) { croak $error }
1180
    
1181
    # Not verbose
1182
    else {
1183
        
1184
        # Remove line and module infromation
1185
        my $at_pos = rindex($error, ' at ');
1186
        $error = substr($error, 0, $at_pos);
1187
        $error =~ s/\s+$//;
1188
        croak "$error$append";
1189
    }
1190
}
1191

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1192
sub _need_tables {
1193
    my ($self, $tree, $need_tables, $tables) = @_;
1194
    
cleanup
Yuki Kimoto authored on 2011-04-02
1195
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1196
    foreach my $table (@$tables) {
1197
        if ($tree->{$table}) {
1198
            $need_tables->{$table} = 1;
1199
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1200
        }
1201
    }
1202
}
1203

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1204
sub _push_join {
1205
    my ($self, $sql, $join, $join_tables) = @_;
1206
    
cleanup
Yuki Kimoto authored on 2011-04-02
1207
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1208
    return unless @$join;
1209
    
cleanup
Yuki Kimoto authored on 2011-04-02
1210
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1211
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1212
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1213
    for (my $i = 0; $i < @$join; $i++) {
1214
        
cleanup
Yuki Kimoto authored on 2011-04-02
1215
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1216
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1217
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1218
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1219
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1220
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1221
            my $table1 = $1;
1222
            my $table2 = $2;
1223
            croak qq{right side table of "$join_clause" must be uniq}
1224
              if exists $tree->{$table2};
1225
            $tree->{$table2}
1226
              = {position => $i, parent => $table1, join => $join_clause};
1227
        }
1228
        else {
1229
            croak qq{join "$join_clause" must be two table name};
1230
        }
1231
    }
1232
    
cleanup
Yuki Kimoto authored on 2011-04-02
1233
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1234
    my $need_tables = {};
1235
    $self->_need_tables($tree, $need_tables, $join_tables);
1236
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1237
    
1238
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1239
    foreach my $need_table (@need_tables) {
1240
        push @$sql, $tree->{$need_table}{join};
1241
    }
1242
}
cleanup
Yuki Kimoto authored on 2011-03-08
1243

            
cleanup
Yuki Kimoto authored on 2011-04-02
1244
sub _remove_duplicate_table {
1245
    my ($self, $tables, $main_table) = @_;
1246
    
1247
    # Remove duplicate table
1248
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1249
    delete $tables{$main_table} if $main_table;
1250
    
1251
    return [keys %tables, $main_table ? $main_table : ()];
1252
}
1253

            
cleanup
Yuki Kimoto authored on 2011-04-02
1254
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1255
    my ($self, $source) = @_;
1256
    
cleanup
Yuki Kimoto authored on 2011-04-02
1257
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1258
    my $tables = [];
1259
    my $safety_character = $self->safety_character;
1260
    my $q = $self->reserved_word_quote;
1261
    my $q_re = quotemeta($q);
1262
    my $table_re = $q ? qr/\b$q_re?([$safety_character]+)$q_re?\./
1263
                      : qr/\b([$safety_character]+)\./;
1264
    while ($source =~ /$table_re/g) {
1265
        push @$tables, $1;
1266
    }
1267
    
1268
    return $tables;
1269
}
1270

            
cleanup
Yuki Kimoto authored on 2011-04-02
1271
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1272
    my ($self, $where) = @_;
1273
    
cleanup
Yuki Kimoto authored on 2011-04-02
1274
    my $obj;
1275
    
1276
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1277
    if (ref $where eq 'HASH') {
1278
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1279
        my $q = $self->reserved_word_quote;
1280
        foreach my $column (keys %$where) {
1281
            $column = "$q$column$q";
1282
            $column =~ s/\./$q.$q/;
1283
            push @$clause, "{= $column}" for keys %$where;
1284
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1285
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1286
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1287
    
1288
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1289
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1290
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1291
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1292
    
1293
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1294
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1295
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1296
             "use \$dbi->select(where => \$dbi->where(clause => " .
1297
             "CLAUSE, param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1298
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1299
            clause => $where->[0],
1300
            param  => $where->[1]
1301
        );
1302
    }
1303
    
cleanup
Yuki Kimoto authored on 2011-04-02
1304
    # Check where argument
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1305
    croak qq{"where" must be hash reference or DBIx::Custom::Where object} .
1306
          qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-02
1307
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1308
    
cleanup
Yuki Kimoto authored on 2011-04-02
1309
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1310
}
1311

            
cleanup
Yuki Kimoto authored on 2011-01-25
1312
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1313
__PACKAGE__->attr(
1314
    dbi_options => sub { {} },
1315
    filter_check  => 1
1316
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1317

            
cleanup
Yuki Kimoto authored on 2011-01-25
1318
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1319
sub default_bind_filter {
1320
    my $self = shift;
1321
    
1322
    if (@_) {
1323
        my $fname = $_[0];
1324
        
1325
        if (@_ && !$fname) {
1326
            $self->{default_out_filter} = undef;
1327
        }
1328
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1329
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1330
              unless exists $self->filters->{$fname};
1331
        
1332
            $self->{default_out_filter} = $self->filters->{$fname};
1333
        }
1334
        return $self;
1335
    }
1336
    
1337
    return $self->{default_out_filter};
1338
}
1339

            
cleanup
Yuki Kimoto authored on 2011-01-25
1340
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1341
sub default_fetch_filter {
1342
    my $self = shift;
1343
    
1344
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1345
        my $fname = $_[0];
1346

            
cleanup
Yuki Kimoto authored on 2011-01-12
1347
        if (@_ && !$fname) {
1348
            $self->{default_in_filter} = undef;
1349
        }
1350
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1351
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1352
              unless exists $self->filters->{$fname};
1353
        
1354
            $self->{default_in_filter} = $self->filters->{$fname};
1355
        }
1356
        
1357
        return $self;
1358
    }
1359
    
many changed
Yuki Kimoto authored on 2011-01-23
1360
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1361
}
1362

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1363
# DEPRECATED!
1364
sub insert_param {
1365
    warn "insert_param is renamed to insert_param_tag."
1366
       . " insert_param is DEPRECATED!";
1367
    return shift->insert_param_tag(@_);
1368
}
1369

            
cleanup
Yuki Kimoto authored on 2011-01-25
1370
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1371
sub register_tag_processor {
1372
    return shift->query_builder->register_tag_processor(@_);
1373
}
1374

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1375
# DEPRECATED!
1376
sub update_param {
1377
    warn "update_param is renamed to update_param_tag."
1378
       . " update_param is DEPRECATED!";
1379
    return shift->update_param_tag(@_);
1380
}
cleanup
Yuki Kimoto authored on 2011-03-08
1381
# DEPRECATED!
1382
sub _push_relation {
1383
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1384
    
1385
    if (keys %{$relation || {}}) {
1386
        push @$sql, $need_where ? 'where' : 'and';
1387
        foreach my $rcolumn (keys %$relation) {
1388
            my $table1 = (split (/\./, $rcolumn))[0];
1389
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1390
            push @$tables, ($table1, $table2);
1391
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1392
        }
1393
    }
1394
    pop @$sql if $sql->[-1] eq 'and';    
1395
}
1396

            
1397
# DEPRECATED!
1398
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1399
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1400
    
1401
    if (keys %{$relation || {}}) {
1402
        foreach my $rcolumn (keys %$relation) {
1403
            my $table1 = (split (/\./, $rcolumn))[0];
1404
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1405
            my $table1_exists;
1406
            my $table2_exists;
1407
            foreach my $table (@$tables) {
1408
                $table1_exists = 1 if $table eq $table1;
1409
                $table2_exists = 1 if $table eq $table2;
1410
            }
1411
            unshift @$tables, $table1 unless $table1_exists;
1412
            unshift @$tables, $table2 unless $table2_exists;
1413
        }
1414
    }
1415
}
1416

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1419
=head1 NAME
1420

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

            
1423
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1424

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1425
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1426
    
1427
    # Connect
1428
    my $dbi = DBIx::Custom->connect(
1429
        data_source => "dbi:mysql:database=dbname",
1430
        user => 'ken',
1431
        password => '!LFKD%$&',
1432
        dbi_option => {mysql_enable_utf8 => 1}
1433
    );
cleanup
yuki-kimoto authored on 2010-08-05
1434

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1435
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1436
    $dbi->insert(
1437
        table  => 'book',
1438
        param  => {title => 'Perl', author => 'Ken'}
1439
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1440
    
1441
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1442
    $dbi->update(
1443
        table  => 'book', 
1444
        param  => {title => 'Perl', author => 'Ken'}, 
1445
        where  => {id => 5},
1446
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1447
    
1448
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1449
    $dbi->delete(
1450
        table  => 'book',
1451
        where  => {author => 'Ken'},
1452
    );
cleanup
yuki-kimoto authored on 2010-08-05
1453

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1460
    # Select, more complex
1461
    my $result = $dbi->select(
1462
        table  => 'book',
1463
        column => [
1464
            'book.author as book__author',
1465
            'company.name as company__name'
1466
        ],
1467
        where  => {'book.author' => 'Ken'},
1468
        join => ['left outer join company on book.company_id = company.id'],
1469
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1470
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1471
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1472
    # Fetch
1473
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1474
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1475
    }
1476
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1477
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1478
    while (my $row = $result->fetch_hash) {
1479
        
1480
    }
1481
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1482
    # Execute SQL with parameter.
1483
    $dbi->execute(
1484
        "select id from book where {= author} and {like title}",
1485
        param  => {author => 'ken', title => '%Perl%'}
1486
    );
1487
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1488
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1489

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

            
1492
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1493

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1498
There are many basic methods to execute various queries.
1499
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1500
C<delete_all()>, C<select()>,
1501
C<insert_at()>, C<update_at()>, 
1502
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1503

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1504
=item *
1505

            
1506
Filter when data is send or receive.
1507

            
1508
=item *
1509

            
1510
Data filtering system
1511

            
1512
=item *
1513

            
1514
Model support.
1515

            
1516
=item *
1517

            
1518
Generate where clause dinamically.
1519

            
1520
=item *
1521

            
1522
Generate join clause dinamically.
1523

            
1524
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1525

            
1526
=head1 GUIDE
1527

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

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

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

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

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1536
=head2 C<connector> EXPERIMENTAL
1537

            
1538
    my $connector = $dbi->connector;
1539
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1540

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

            
1544
This is L<DBIx::Connector> example. Please pass
1545
C<default_dbi_option> to L<DBIx::Connector>.
1546

            
1547
    my $connector = DBIx::Connector->new(
1548
        "dbi:mysql:database=$DATABASE",
1549
        $USER,
1550
        $PASSWORD,
1551
        DBIx::Custom->new->default_dbi_option
1552
    );
1553
    
1554
    my $dbi = DBIx::Custom->new(connector => $connector);
1555

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

            
cleanup
yuki-kimoto authored on 2010-08-03
1558
    my $data_source = $dbi->data_source;
cleanup
yuki-kimoto authored on 2010-08-05
1559
    $dbi            = $dbi->data_source("DBI:mysql:database=dbname");
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1560

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1561
Data source, used when C<connect()> is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1562

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

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

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

            
1571
=head2 C<default_dbi_option>
1572

            
1573
    my $default_dbi_option = $dbi->default_dbi_option;
1574
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1575

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1579
    {
1580
        RaiseError => 1,
1581
        PrintError => 0,
1582
        AutoCommit => 1,
1583
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1584

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1595
=head2 C<models> EXPERIMENTAL
add models() attribute
Yuki Kimoto authored on 2011-02-21
1596

            
1597
    my $models = $dbi->models;
1598
    $dbi       = $dbi->models(\%models);
1599

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1602
=head2 C<password>
1603

            
1604
    my $password = $dbi->password;
1605
    $dbi         = $dbi->password('lkj&le`@s');
1606

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

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

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

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

            
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1616
=head2 C<reserved_word_quote> EXPERIMENTAL
1617

            
1618
     my reserved_word_quote = $dbi->reserved_word_quote;
1619
     $dbi                   = $dbi->reserved_word_quote('"');
1620

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1640
    my $user = $dbi->user;
1641
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1642

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1651
=head2 C<apply_filter> EXPERIMENTAL
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1652

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1653
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1654
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1655
        'issue_date' => {
1656
            out => 'tp_to_date',
1657
            in  => 'date_to_tp',
1658
            end => 'tp_to_displaydate'
1659
        },
1660
        'write_date' => {
1661
            out => 'tp_to_date',
1662
            in  => 'date_to_tp',
1663
            end => 'tp_to_displaydate'
1664
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1665
    );
1666

            
update pod
Yuki Kimoto authored on 2011-03-13
1667
Apply filter to columns.
1668
C<out> filter is executed before data is send to database.
1669
C<in> filter is executed after a row is fetch.
1670
C<end> filter is execute after C<in> filter is executed.
1671

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1674
       PETTERN         EXAMPLE
1675
    1. Column        : author
1676
    2. Table.Column  : book.author
1677
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1678

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

            
1682
You can set multiple filters at once.
1683

            
1684
    $dbi->apply_filter(
1685
        'book',
1686
        [qw/issue_date write_date/] => {
1687
            out => 'tp_to_date',
1688
            in  => 'date_to_tp',
1689
            end => 'tp_to_displaydate'
1690
        }
1691
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1692

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1695
    my $dbi = DBIx::Custom->connect(
1696
        data_source => "dbi:mysql:database=dbname",
1697
        user => 'ken',
1698
        password => '!LFKD%$&',
1699
        dbi_option => {mysql_enable_utf8 => 1}
1700
    );
1701

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1710
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1711
        table => 'book',
1712
        primary_key => 'id',
1713
        join => [
1714
            'inner join company on book.comparny_id = company.id'
1715
        ],
1716
        filter => [
1717
            publish_date => {
1718
                out => 'tp_to_date',
1719
                in => 'date_to_tp',
1720
                end => 'tp_to_displaydate'
1721
            }
1722
        ]
1723
    );
1724

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

            
1728
   $dbi->model('book')->select(...);
1729

            
cleanup
yuki-kimoto authored on 2010-10-17
1730
=head2 C<create_query>
1731
    
1732
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1733
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1734
    );
update document
yuki-kimoto authored on 2009-11-19
1735

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

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

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

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

            
1746
    my $dbh = $dbi->dbh;
1747

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

            
1751
=head2 C<each_column>
1752

            
1753
    $dbi->each_column(
1754
        sub {
1755
            my ($dbi, $table, $column, $column_info) = @_;
1756
            
1757
            my $type = $column_info->{TYPE_NAME};
1758
            
1759
            if ($type eq 'DATE') {
1760
                # ...
1761
            }
1762
        }
1763
    );
1764

            
1765
Iterate all column informations of all table from database.
1766
Argument is callback when one column is found.
1767
Callback receive four arguments, dbi object, table name,
1768
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1769

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1772
    my $result = $dbi->execute(
1773
        "select * from book where {= title} and {like author}",
1774
        param => {title => 'Perl', author => '%Ken%'}
1775
    );
1776

            
1777
Execute SQL, containing tags.
1778
Return value is L<DBIx::Custom::Result> in select statement, or
1779
the count of affected rows in insert, update, delete statement.
1780

            
1781
Tag is turned into the statement containing place holder
1782
before SQL is executed.
1783

            
1784
    select * from where title = ? and author like ?;
1785

            
1786
See also L<Tags/Tags>.
1787

            
1788
The following opitons are currently available.
1789

            
1790
=over 4
1791

            
1792
=item C<filter>
1793

            
1794
Filter, executed before data is send to database. This is array reference.
1795
Filter value is code reference or
1796
filter name registerd by C<register_filter()>.
1797

            
1798
    # Basic
1799
    $dbi->execute(
1800
        $sql,
1801
        filter => [
1802
            title  => sub { uc $_[0] }
1803
            author => sub { uc $_[0] }
1804
        ]
1805
    );
1806
    
1807
    # At once
1808
    $dbi->execute(
1809
        $sql,
1810
        filter => [
1811
            [qw/title author/]  => sub { uc $_[0] }
1812
        ]
1813
    );
1814
    
1815
    # Filter name
1816
    $dbi->execute(
1817
        $sql,
1818
        filter => [
1819
            title  => 'upper_case',
1820
            author => 'upper_case'
1821
        ]
1822
    );
1823

            
1824
These filters are added to the C<out> filters, set by C<apply_filter()>.
update document
yuki-kimoto authored on 2009-11-19
1825

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

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

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

            
1832
Delete statement.
1833

            
1834
The following opitons are currently available.
1835

            
update pod
Yuki Kimoto authored on 2011-03-13
1836
=over 4
1837

            
update pod
Yuki Kimoto authored on 2011-03-13
1838
=item C<table>
1839

            
1840
Table name.
1841

            
1842
    $dbi->delete(table => 'book');
1843

            
1844
=item C<where>
1845

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1846
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1847
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1848
    
1849
    # Hash reference
1850
    $dbi->delete(where => {title => 'Perl'});
1851
    
1852
    # DBIx::Custom::Where object
1853
    my $where = $dbi->where(
1854
        clause => ['and', '{= author}', '{like title}'],
1855
        param  => {author => 'Ken', title => '%Perl%'}
1856
    );
1857
    $dbi->delete(where => $where);
1858

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1859
    # Array refrendce (where clause and parameter)
1860
    $dbi->delete(where =>
1861
        [
1862
            ['and', '{= author}', '{like title}'],
1863
            {author => 'Ken', title => '%Perl%'}
1864
        ]
1865
    );
1866
    
update pod
Yuki Kimoto authored on 2011-03-13
1867
=item C<append>
1868

            
1869
Append statement to last of SQL. This is string.
1870

            
1871
    $dbi->delete(append => 'order by title');
1872

            
1873
=item C<filter>
1874

            
1875
Filter, executed before data is send to database. This is array reference.
1876
Filter value is code reference or
1877
filter name registerd by C<register_filter()>.
1878

            
1879
    # Basic
1880
    $dbi->delete(
1881
        filter => [
1882
            title  => sub { uc $_[0] }
1883
            author => sub { uc $_[0] }
1884
        ]
1885
    );
1886
    
1887
    # At once
1888
    $dbi->delete(
1889
        filter => [
1890
            [qw/title author/]  => sub { uc $_[0] }
1891
        ]
1892
    );
1893
    
1894
    # Filter name
1895
    $dbi->delete(
1896
        filter => [
1897
            title  => 'upper_case',
1898
            author => 'upper_case'
1899
        ]
1900
    );
1901

            
1902
These filters are added to the C<out> filters, set by C<apply_filter()>.
1903

            
cleanup
Yuki Kimoto authored on 2011-03-21
1904
=head2 C<column> EXPERIMENTAL
1905

            
1906
    my $column = $self->column(book => ['author', 'title']);
1907

            
1908
Create column clause. The follwoing column clause is created.
1909

            
1910
    book.author as book__author,
1911
    book.title as book__title
1912

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1913
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
1914

            
1915
Get L<DBIx::Custom::Query> object instead of executing SQL.
1916
This is true or false value.
1917

            
1918
    my $query = $dbi->delete(query => 1);
1919

            
1920
You can check SQL.
1921

            
1922
    my $sql = $query->sql;
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1923

            
update pod
Yuki Kimoto authored on 2011-03-13
1924
=back
1925

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1928
    $dbi->delete_all(table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
1929

            
update pod
Yuki Kimoto authored on 2011-03-13
1930
Delete statement to delete all rows.
1931
Options is same as C<delete()>.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1932

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1933
=head2 C<delete_at()>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1934

            
update pod
Yuki Kimoto authored on 2011-03-13
1935
Delete statement, using primary key.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1936

            
1937
    $dbi->delete_at(
1938
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
1939
        primary_key => 'id',
1940
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1941
    );
1942

            
update pod
Yuki Kimoto authored on 2011-03-13
1943
This method is same as C<delete()> exept that
1944
C<primary_key> is specified and C<where> is constant value or array refrence.
1945
all option of C<delete()> is available.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1946

            
update pod
Yuki Kimoto authored on 2011-03-13
1947
=over 4
1948

            
1949
=item C<primary_key>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1950

            
update pod
Yuki Kimoto authored on 2011-03-13
1951
Primary key. This is constant value or array reference.
1952
    
1953
    # Constant value
1954
    $dbi->delete(primary_key => 'id');
1955

            
1956
    # Array reference
1957
    $dbi->delete(primary_key => ['id1', 'id2' ]);
1958

            
1959
This is used to create where clause.
1960

            
update pod
Yuki Kimoto authored on 2011-03-13
1961
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
1962

            
1963
Where clause, created from primary key information.
1964
This is constant value or array reference.
1965

            
1966
    # Constant value
1967
    $dbi->delete(where => 5);
1968

            
1969
    # Array reference
1970
    $dbi->delete(where => [3, 5]);
1971

            
1972
In first examle, the following SQL is created.
1973

            
1974
    delete from book where id = ?;
1975

            
1976
Place holder is set to 5.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1977

            
update pod
Yuki Kimoto authored on 2011-03-13
1978
=back
1979

            
cleanup
yuki-kimoto authored on 2010-10-17
1980
=head2 C<insert>
1981

            
update pod
Yuki Kimoto authored on 2011-03-13
1982
    $dbi->insert(
1983
        table  => 'book', 
1984
        param  => {title => 'Perl', author => 'Ken'}
1985
    );
1986

            
1987
Insert statement.
1988

            
1989
The following opitons are currently available.
1990

            
update pod
Yuki Kimoto authored on 2011-03-13
1991
=over 4
1992

            
update pod
Yuki Kimoto authored on 2011-03-13
1993
=item C<table>
1994

            
1995
Table name.
1996

            
1997
    $dbi->insert(table => 'book');
1998

            
1999
=item C<param>
2000

            
2001
Insert data. This is hash reference.
2002

            
2003
    $dbi->insert(param => {title => 'Perl'});
2004

            
2005
=item C<append>
2006

            
2007
Append statement to last of SQL. This is string.
2008

            
2009
    $dbi->insert(append => 'order by title');
2010

            
2011
=item C<filter>
2012

            
2013
Filter, executed before data is send to database. This is array reference.
2014
Filter value is code reference or
2015
filter name registerd by C<register_filter()>.
2016

            
2017
    # Basic
2018
    $dbi->insert(
2019
        filter => [
2020
            title  => sub { uc $_[0] }
2021
            author => sub { uc $_[0] }
2022
        ]
2023
    );
2024
    
2025
    # At once
2026
    $dbi->insert(
2027
        filter => [
2028
            [qw/title author/]  => sub { uc $_[0] }
2029
        ]
2030
    );
2031
    
2032
    # Filter name
2033
    $dbi->insert(
2034
        filter => [
2035
            title  => 'upper_case',
2036
            author => 'upper_case'
2037
        ]
2038
    );
2039

            
2040
These filters are added to the C<out> filters, set by C<apply_filter()>.
2041

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2042
=item C<query>
update pod
Yuki Kimoto authored on 2011-03-13
2043

            
2044
Get L<DBIx::Custom::Query> object instead of executing SQL.
2045
This is true or false value.
2046

            
2047
    my $query = $dbi->insert(query => 1);
cleanup
yuki-kimoto authored on 2010-10-17
2048

            
update pod
Yuki Kimoto authored on 2011-03-13
2049
You can check SQL.
cleanup
yuki-kimoto authored on 2010-10-17
2050

            
update pod
Yuki Kimoto authored on 2011-03-13
2051
    my $sql = $query->sql;
2052

            
update pod
Yuki Kimoto authored on 2011-03-13
2053
=back
2054

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2055
=head2 C<insert_at()>
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2056

            
update pod
Yuki Kimoto authored on 2011-03-13
2057
Insert statement, using primary key.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2058

            
2059
    $dbi->insert_at(
2060
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2061
        primary_key => 'id',
2062
        where => '5',
2063
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2064
    );
2065

            
update pod
Yuki Kimoto authored on 2011-03-13
2066
This method is same as C<insert()> exept that
2067
C<primary_key> is specified and C<where> is constant value or array refrence.
2068
all option of C<insert()> is available.
2069

            
update pod
Yuki Kimoto authored on 2011-03-13
2070
=over 4
2071

            
2072
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2073

            
2074
Primary key. This is constant value or array reference.
2075
    
2076
    # Constant value
2077
    $dbi->insert(primary_key => 'id');
2078

            
2079
    # Array reference
2080
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2081

            
2082
This is used to create parts of insert data.
2083

            
update pod
Yuki Kimoto authored on 2011-03-13
2084
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2085

            
2086
Parts of Insert data, create from primary key information.
2087
This is constant value or array reference.
2088

            
2089
    # Constant value
2090
    $dbi->insert(where => 5);
2091

            
2092
    # Array reference
2093
    $dbi->insert(where => [3, 5]);
2094

            
2095
In first examle, the following SQL is created.
2096

            
2097
    insert into book (id, title) values (?, ?);
2098

            
2099
Place holders are set to 5 and 'Perl'.
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2100

            
update pod
Yuki Kimoto authored on 2011-03-13
2101
=back
2102

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2103
=head2 C<insert_param_tag>
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2104

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2105
    my $insert_param_tag = $dbi->insert_param_tag({title => 'a', age => 2});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2106

            
2107
Create insert parameter tag.
2108

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2109
    (title, author) values ({? title}, {? author});
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2110

            
update pod
Yuki Kimoto authored on 2011-03-13
2111
=head2 C<include_model> EXPERIMENTAL
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2112

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2118
    lib / MyModel.pm
2119
        / MyModel / book.pm
2120
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2121

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

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

            
2126
    package MyModel;
2127
    
2128
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2129
    
2130
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2131

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2136
    package MyModel::book;
2137
    
2138
    use base 'MyModel';
2139
    
2140
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2141

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2144
    package MyModel::company;
2145
    
2146
    use base 'MyModel';
2147
    
2148
    1;
2149
    
2150
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2151

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

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

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

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2159
=head2 C<merge_param> EXPERIMENTAL
2160

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

            
2163
Merge paramters.
2164

            
2165
$param:
2166

            
2167
    {key1 => [1, 1], key2 => 2}
2168

            
update pod
Yuki Kimoto authored on 2011-03-13
2169
=head2 C<method> EXPERIMENTAL
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2170

            
2171
    $dbi->method(
2172
        update_or_insert => sub {
2173
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2174
            
2175
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2176
        },
2177
        find_or_create   => sub {
2178
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2179
            
2180
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2181
        }
2182
    );
2183

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

            
2186
    $dbi->update_or_insert;
2187
    $dbi->find_or_create;
2188

            
update pod
Yuki Kimoto authored on 2011-03-13
2189
=head2 C<model> EXPERIMENTAL
2190

            
2191
    $dbi->model('book')->method(
2192
        insert => sub { ... },
2193
        update => sub { ... }
2194
    );
2195
    
2196
    my $model = $dbi->model('book');
2197

            
2198
Set and get a L<DBIx::Custom::Model> object,
2199

            
cleanup
Yuki Kimoto authored on 2011-03-21
2200
=head2 C<mycolumn> EXPERIMENTAL
2201

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

            
2204
Create column clause for myself. The follwoing column clause is created.
2205

            
2206
    book.author as author,
2207
    book.title as title
2208

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2211
    my $dbi = DBIx::Custom->new(
2212
        data_source => "dbi:mysql:database=dbname",
2213
        user => 'ken',
2214
        password => '!LFKD%$&',
2215
        dbi_option => {mysql_enable_utf8 => 1}
2216
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2217

            
2218
Create a new L<DBIx::Custom> object.
2219

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

            
2222
    my $not_exists = $dbi->not_exists;
2223

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2227
=head2 C<register_filter>
2228

            
update pod
Yuki Kimoto authored on 2011-03-13
2229
    $dbi->register_filter(
2230
        # Time::Piece object to database DATE format
2231
        tp_to_date => sub {
2232
            my $tp = shift;
2233
            return $tp->strftime('%Y-%m-%d');
2234
        },
2235
        # database DATE format to Time::Piece object
2236
        date_to_tp => sub {
2237
           my $date = shift;
2238
           return Time::Piece->strptime($date, '%Y-%m-%d');
2239
        }
2240
    );
cleanup
yuki-kimoto authored on 2010-10-17
2241
    
update pod
Yuki Kimoto authored on 2011-03-13
2242
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2243

            
update pod
Yuki Kimoto authored on 2011-03-13
2244
=head2 C<register_tag>
cleanup
yuki-kimoto authored on 2010-10-17
2245

            
update pod
Yuki Kimoto authored on 2011-03-13
2246
    $dbi->register_tag(
2247
        update => sub {
2248
            my @columns = @_;
2249
            
2250
            # Update parameters
2251
            my $s = 'set ';
2252
            $s .= "$_ = ?, " for @columns;
2253
            $s =~ s/, $//;
2254
            
2255
            return [$s, \@columns];
2256
        }
2257
    );
cleanup
yuki-kimoto authored on 2010-10-17
2258

            
update pod
Yuki Kimoto authored on 2011-03-13
2259
Register tag, used by C<execute()>.
cleanup
yuki-kimoto authored on 2010-10-17
2260

            
update pod
Yuki Kimoto authored on 2011-03-13
2261
See also L<Tags/Tags> about tag registered by default.
cleanup
yuki-kimoto authored on 2010-10-17
2262

            
update pod
Yuki Kimoto authored on 2011-03-13
2263
Tag parser receive arguments specified in tag.
2264
In the following tag, 'title' and 'author' is parser arguments
cleanup
yuki-kimoto authored on 2010-10-17
2265

            
update pod
Yuki Kimoto authored on 2011-03-13
2266
    {update_param title author} 
cleanup
yuki-kimoto authored on 2010-10-17
2267

            
update pod
Yuki Kimoto authored on 2011-03-13
2268
Tag parser must return array refrence,
2269
first element is the result statement, 
2270
second element is column names corresponding to place holders.
cleanup
yuki-kimoto authored on 2010-10-17
2271

            
update pod
Yuki Kimoto authored on 2011-03-13
2272
In this example, result statement is 
cleanup
yuki-kimoto authored on 2010-10-17
2273

            
update pod
Yuki Kimoto authored on 2011-03-13
2274
    set title = ?, author = ?
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
2275

            
update pod
Yuki Kimoto authored on 2011-03-13
2276
Column names is
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
2277

            
update pod
Yuki Kimoto authored on 2011-03-13
2278
    ['title', 'author']
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
2279

            
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2280
=head2 C<replace> EXPERIMENTAL
2281
    
2282
    my $join = [
2283
        'left outer join table2 on table1.key1 = table2.key1',
2284
        'left outer join table3 on table2.key3 = table3.key3'
2285
    ];
2286
    $join = $dbi->replace(
2287
        $join,
2288
        'left outer join table2 on table1.key1 = table2.key1',
2289
        'left outer join (select * from table2 where {= table2.key1}) ' . 
2290
          'as table2 on table1.key1 = table2.key1'
2291
    );
2292

            
2293
Replace join clauses if match the expression.
2294

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2297
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2298
        table  => 'book',
2299
        column => ['author', 'title'],
2300
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2301
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2302
    
update pod
Yuki Kimoto authored on 2011-03-12
2303
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2304

            
2305
The following opitons are currently available.
2306

            
2307
=over 4
2308

            
2309
=item C<table>
2310

            
2311
Table name.
2312

            
update pod
Yuki Kimoto authored on 2011-03-12
2313
    $dbi->select(table => 'book');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2314

            
2315
=item C<column>
2316

            
2317
Column clause. This is array reference or constant value.
2318

            
2319
    # Hash refernce
2320
    $dbi->select(column => ['author', 'title']);
2321
    
2322
    # Constant value
2323
    $dbi->select(column => 'author');
2324

            
2325
Default is '*' unless C<column> is specified.
2326

            
2327
    # Default
2328
    $dbi->select(column => '*');
2329

            
2330
=item C<where>
2331

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2332
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2333
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2334
    
2335
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2336
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2337
    
update pod
Yuki Kimoto authored on 2011-03-12
2338
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2339
    my $where = $dbi->where(
2340
        clause => ['and', '{= author}', '{like title}'],
2341
        param  => {author => 'Ken', title => '%Perl%'}
2342
    );
update pod
Yuki Kimoto authored on 2011-03-12
2343
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2344

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2345
    # Array refrendce (where clause and parameter)
2346
    $dbi->select(where =>
2347
        [
2348
            ['and', '{= author}', '{like title}'],
2349
            {author => 'Ken', title => '%Perl%'}
2350
        ]
2351
    );
2352
    
update pod
Yuki Kimoto authored on 2011-03-13
2353
=item C<join> EXPERIMENTAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2354

            
update pod
Yuki Kimoto authored on 2011-03-12
2355
Join clause used in need. This is array reference.
2356

            
2357
    $dbi->select(join =>
2358
        [
2359
            'left outer join company on book.company_id = company_id',
2360
            'left outer join location on company.location_id = location.id'
2361
        ]
2362
    );
2363

            
2364
If column cluase or where clause contain table name like "company.name",
2365
needed join clause is used automatically.
2366

            
2367
    $dbi->select(
2368
        table => 'book',
2369
        column => ['company.location_id as company__location_id'],
2370
        where => {'company.name' => 'Orange'},
2371
        join => [
2372
            'left outer join company on book.company_id = company.id',
2373
            'left outer join location on company.location_id = location.id'
2374
        ]
2375
    );
2376

            
2377
In above select, the following SQL is created.
2378

            
2379
    select company.location_id as company__location_id
2380
    from book
2381
      left outer join company on book.company_id = company.id
2382
    where company.name = Orange
2383

            
added EXPERIMENTAL replace()...
Yuki Kimoto authored on 2011-04-01
2384
=item C<param> EXPERIMETNAL
2385

            
2386
Parameter shown before where clause.
2387
    
2388
    $dbi->select(
2389
        table => 'table1',
2390
        column => 'table1.key1 as table1_key1, key2, key3',
2391
        where   => {'table1.key2' => 3},
2392
        join  => ['inner join (select * from table2 where {= table2.key3})' . 
2393
                  ' as table2 on table1.key1 = table2.key1'],
2394
        param => {'table2.key3' => 5}
2395
    );
2396

            
2397
For example, if you want to contain tag in join clause, 
2398
you can pass parameter by C<param> option.
2399

            
update pod
Yuki Kimoto authored on 2011-03-12
2400
=item C<append>
2401

            
update pod
Yuki Kimoto authored on 2011-03-13
2402
Append statement to last of SQL. This is string.
update pod
Yuki Kimoto authored on 2011-03-12
2403

            
2404
    $dbi->select(append => 'order by title');
2405

            
2406
=item C<filter>
2407

            
update pod
Yuki Kimoto authored on 2011-03-13
2408
Filter, executed before data is send to database. This is array reference.
2409
Filter value is code reference or
update pod
Yuki Kimoto authored on 2011-03-12
2410
filter name registerd by C<register_filter()>.
2411

            
2412
    # Basic
2413
    $dbi->select(
2414
        filter => [
2415
            title  => sub { uc $_[0] }
2416
            author => sub { uc $_[0] }
2417
        ]
2418
    );
2419
    
2420
    # At once
2421
    $dbi->select(
2422
        filter => [
2423
            [qw/title author/]  => sub { uc $_[0] }
2424
        ]
2425
    );
2426
    
2427
    # Filter name
2428
    $dbi->select(
2429
        filter => [
2430
            title  => 'upper_case',
2431
            author => 'upper_case'
2432
        ]
2433
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2434

            
update pod
Yuki Kimoto authored on 2011-03-13
2435
These filters are added to the C<out> filters, set by C<apply_filter()>.
update document
yuki-kimoto authored on 2009-11-19
2436

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2437
=item C<query>
cleanup
yuki-kimoto authored on 2010-08-09
2438

            
update pod
Yuki Kimoto authored on 2011-03-12
2439
Get L<DBIx::Custom::Query> object instead of executing SQL.
2440
This is true or false value.
2441

            
update pod
Yuki Kimoto authored on 2011-03-13
2442
    my $query = $dbi->select(query => 1);
update pod
Yuki Kimoto authored on 2011-03-12
2443

            
update pod
Yuki Kimoto authored on 2011-03-13
2444
You can check SQL.
update pod
Yuki Kimoto authored on 2011-03-12
2445

            
2446
    my $sql = $query->sql;
2447

            
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2448
=item C<type> EXPERIMENTAL
2449

            
2450
Specify database data type.
2451

            
2452
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2453
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2454

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

            
2457
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2458

            
update pod
Yuki Kimoto authored on 2011-03-12
2459
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2460

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2461
=head2 C<select_at()>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2462

            
update pod
Yuki Kimoto authored on 2011-03-12
2463
Select statement, using primary key.
2464

            
2465
    $dbi->select_at(
2466
        table => 'book',
2467
        primary_key => 'id',
2468
        where => '5'
2469
    );
2470

            
update pod
Yuki Kimoto authored on 2011-03-13
2471
This method is same as C<select()> exept that
2472
C<primary_key> is specified and C<where> is constant value or array refrence.
update pod
Yuki Kimoto authored on 2011-03-12
2473
all option of C<select()> is available.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2474

            
update pod
Yuki Kimoto authored on 2011-03-13
2475
=over 4
2476

            
2477
=item C<primary_key>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2478

            
update pod
Yuki Kimoto authored on 2011-03-12
2479
Primary key. This is constant value or array reference.
2480
    
2481
    # Constant value
2482
    $dbi->select(primary_key => 'id');
2483

            
2484
    # Array reference
2485
    $dbi->select(primary_key => ['id1', 'id2' ]);
2486

            
update pod
Yuki Kimoto authored on 2011-03-13
2487
This is used to create where clause.
2488

            
update pod
Yuki Kimoto authored on 2011-03-13
2489
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-12
2490

            
update pod
Yuki Kimoto authored on 2011-03-13
2491
Where clause, created from primary key information.
update pod
Yuki Kimoto authored on 2011-03-12
2492
This is constant value or array reference.
2493

            
2494
    # Constant value
2495
    $dbi->select(where => 5);
2496

            
2497
    # Array reference
2498
    $dbi->select(where => [3, 5]);
2499

            
2500
In first examle, the following SQL is created.
2501

            
2502
    select * from book where id = ?
2503

            
2504
Place holder is set to 5.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2505

            
update pod
Yuki Kimoto authored on 2011-03-13
2506
=back
2507

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2510
    $dbi->update(
2511
        table  => 'book',
2512
        param  => {title => 'Perl'},
2513
        where  => {id => 4}
2514
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2515

            
update pod
Yuki Kimoto authored on 2011-03-13
2516
Update statement.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2517

            
update pod
Yuki Kimoto authored on 2011-03-13
2518
The following opitons are currently available.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2519

            
update pod
Yuki Kimoto authored on 2011-03-13
2520
=over 4
2521

            
update pod
Yuki Kimoto authored on 2011-03-13
2522
=item C<table>
2523

            
update pod
Yuki Kimoto authored on 2011-03-13
2524
Table name.
2525

            
2526
    $dbi->update(table => 'book');
2527

            
2528
=item C<param>
2529

            
2530
Update data. This is hash reference.
2531

            
2532
    $dbi->update(param => {title => 'Perl'});
2533

            
2534
=item C<where>
2535

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2536
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2537
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2538
    
2539
    # Hash reference
2540
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2541
    
2542
    # DBIx::Custom::Where object
2543
    my $where = $dbi->where(
2544
        clause => ['and', '{= author}', '{like title}'],
2545
        param  => {author => 'Ken', title => '%Perl%'}
2546
    );
2547
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2548
    
2549
    # Array refrendce (where clause and parameter)
2550
    $dbi->update(where =>
2551
        [
2552
            ['and', '{= author}', '{like title}'],
2553
            {author => 'Ken', title => '%Perl%'}
2554
        ]
2555
    );
update pod
Yuki Kimoto authored on 2011-03-13
2556

            
2557
=item C<append>
2558

            
2559
Append statement to last of SQL. This is string.
2560

            
2561
    $dbi->update(append => 'order by title');
2562

            
2563
=item C<filter>
2564

            
2565
Filter, executed before data is send to database. This is array reference.
2566
Filter value is code reference or
2567
filter name registerd by C<register_filter()>.
2568

            
2569
    # Basic
2570
    $dbi->update(
2571
        filter => [
2572
            title  => sub { uc $_[0] }
2573
            author => sub { uc $_[0] }
2574
        ]
2575
    );
2576
    
2577
    # At once
2578
    $dbi->update(
2579
        filter => [
2580
            [qw/title author/]  => sub { uc $_[0] }
2581
        ]
2582
    );
2583
    
2584
    # Filter name
2585
    $dbi->update(
2586
        filter => [
2587
            title  => 'upper_case',
2588
            author => 'upper_case'
2589
        ]
2590
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2591

            
update pod
Yuki Kimoto authored on 2011-03-13
2592
These filters are added to the C<out> filters, set by C<apply_filter()>.
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2593

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2594
=item C<query>
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2595

            
update pod
Yuki Kimoto authored on 2011-03-13
2596
Get L<DBIx::Custom::Query> object instead of executing SQL.
2597
This is true or false value.
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2598

            
update pod
Yuki Kimoto authored on 2011-03-13
2599
    my $query = $dbi->update(query => 1);
2600

            
2601
You can check SQL.
2602

            
2603
    my $sql = $query->sql;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
2604

            
update pod
Yuki Kimoto authored on 2011-03-13
2605
=back
2606

            
cleanup
yuki-kimoto authored on 2010-10-17
2607
=head2 C<update_all>
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2608

            
update pod
Yuki Kimoto authored on 2011-03-13
2609
    $dbi->update_all(table => 'book', param => {title => 'Perl'});
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
2610

            
update pod
Yuki Kimoto authored on 2011-03-13
2611
Update statement to update all rows.
2612
Options is same as C<update()>.
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2613

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2614
=head2 C<update_at()>
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2615

            
update pod
Yuki Kimoto authored on 2011-03-13
2616
Update statement, using primary key.
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2617

            
2618
    $dbi->update_at(
2619
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2620
        primary_key => 'id',
2621
        where => '5',
2622
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2623
    );
2624

            
update pod
Yuki Kimoto authored on 2011-03-13
2625
This method is same as C<update()> exept that
2626
C<primary_key> is specified and C<where> is constant value or array refrence.
2627
all option of C<update()> is available.
2628

            
update pod
Yuki Kimoto authored on 2011-03-13
2629
=over 4
2630

            
2631
=item C<primary_key>
update pod
Yuki Kimoto authored on 2011-03-13
2632

            
2633
Primary key. This is constant value or array reference.
2634
    
2635
    # Constant value
2636
    $dbi->update(primary_key => 'id');
2637

            
2638
    # Array reference
2639
    $dbi->update(primary_key => ['id1', 'id2' ]);
2640

            
2641
This is used to create where clause.
2642

            
update pod
Yuki Kimoto authored on 2011-03-13
2643
=item C<where>
update pod
Yuki Kimoto authored on 2011-03-13
2644

            
2645
Where clause, created from primary key information.
2646
This is constant value or array reference.
2647

            
2648
    # Constant value
2649
    $dbi->update(where => 5);
2650

            
2651
    # Array reference
2652
    $dbi->update(where => [3, 5]);
2653

            
2654
In first examle, the following SQL is created.
2655

            
2656
    update book set title = ? where id = ?
2657

            
2658
Place holders are set to 'Perl' and 5.
2659

            
update pod
Yuki Kimoto authored on 2011-03-13
2660
=back
2661

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2662
=head2 C<update_param_tag>
update pod
Yuki Kimoto authored on 2011-03-13
2663

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2664
    my $update_param_tag = $dbi->update_param_tag({title => 'a', age => 2});
update pod
Yuki Kimoto authored on 2011-03-13
2665

            
2666
Create update parameter tag.
2667

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2668
    set title = {? title}, author = {? author}
2669

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2670
You can create tag without 'set '
2671
by C<no_set> option. This option is EXPERIMENTAL.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2672

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2673
    my $update_param_tag = $dbi->update_param_tag(
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2674
        {title => 'a', age => 2}
2675
        {no_set => 1}
2676
    );
2677

            
2678
    title = {? title}, author = {? author}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2679

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

            
cleanup
Yuki Kimoto authored on 2011-03-09
2682
    my $where = $dbi->where(
2683
        clause => ['and', '{= title}', '{= author}'],
2684
        param => {title => 'Perl', author => 'Ken'}
2685
    );
fix tests
Yuki Kimoto authored on 2011-01-18
2686

            
2687
Create a new L<DBIx::Custom::Where> object.
2688

            
update pod
Yuki Kimoto authored on 2011-03-13
2689
=head2 C<setup_model> EXPERIMENTAL
cleanup
Yuki Kimoto authored on 2011-01-12
2690

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
2696
=head1 Tags
2697

            
2698
The following tags is available.
2699

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2700
=head2 C<table>
add table tag
Yuki Kimoto authored on 2011-02-09
2701

            
2702
Table tag
2703

            
2704
    {table TABLE}    ->    TABLE
2705

            
update pod
Yuki Kimoto authored on 2011-03-13
2706
This is used to tell C<execute()> what table is needed .
add table tag
Yuki Kimoto authored on 2011-02-09
2707

            
cleanup
Yuki Kimoto authored on 2011-01-25
2708
=head2 C<?>
2709

            
2710
Placeholder tag.
2711

            
2712
    {? NAME}    ->   ?
2713

            
2714
=head2 C<=>
2715

            
2716
Equal tag.
2717

            
2718
    {= NAME}    ->   NAME = ?
2719

            
2720
=head2 C<E<lt>E<gt>>
2721

            
2722
Not equal tag.
2723

            
2724
    {<> NAME}   ->   NAME <> ?
2725

            
2726
=head2 C<E<lt>>
2727

            
2728
Lower than tag
2729

            
2730
    {< NAME}    ->   NAME < ?
2731

            
2732
=head2 C<E<gt>>
2733

            
2734
Greater than tag
2735

            
2736
    {> NAME}    ->   NAME > ?
2737

            
2738
=head2 C<E<gt>=>
2739

            
2740
Greater than or equal tag
2741

            
2742
    {>= NAME}   ->   NAME >= ?
2743

            
2744
=head2 C<E<lt>=>
2745

            
2746
Lower than or equal tag
2747

            
2748
    {<= NAME}   ->   NAME <= ?
2749

            
2750
=head2 C<like>
2751

            
2752
Like tag
2753

            
2754
    {like NAME}   ->   NAME like ?
2755

            
2756
=head2 C<in>
2757

            
2758
In tag.
2759

            
2760
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2761

            
2762
=head2 C<insert_param>
2763

            
2764
Insert parameter tag.
2765

            
2766
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2767

            
2768
=head2 C<update_param>
2769

            
2770
Updata parameter tag.
2771

            
2772
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2773

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

            
2776
=head2 C<DBIX_CUSTOM_DEBUG>
2777

            
2778
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
2779
executed SQL is printed to STDERR.
2780

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

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

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

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

            
2790
C<< <kimoto.yuki at gmail.com> >>
2791

            
2792
L<http://github.com/yuki-kimoto/DBIx-Custom>
2793

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2794
=head1 AUTHOR
2795

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

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

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

            
2802
This program is free software; you can redistribute it and/or modify it
2803
under the same terms as Perl itself.
2804

            
2805
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
2806

            
2807