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

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
3
our $VERSION = '0.1675';
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

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

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
795
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
796
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
797
    my $tables = ref $table eq 'ARRAY' ? $table
798
               : defined $table ? [$table]
799
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
800
    my $columns   = delete $args{column};
801
    my $where     = delete $args{where} || {};
802
    my $append    = delete $args{append};
803
    my $join      = delete $args{join} || [];
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
804
    croak qq{"join" must be array reference}
805
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
806
    my $relation = delete $args{relation};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
807
    my $param = delete $args{param} || {};
cleanup
Yuki Kimoto authored on 2011-04-02
808
    my $query_return = $args{query};
809

            
810
    # Check arguments
811
    foreach my $name (keys %args) {
812
        croak qq{Argument "$name" is wrong name}
813
          unless $SELECT_ARGS{$name};
814
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
815
    
cleanup
Yuki Kimoto authored on 2011-03-09
816
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
817
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
818
    
cleanup
Yuki Kimoto authored on 2011-04-02
819
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
820
    my @sql;
821
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
822
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
823
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
824
    if ($columns) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
825
        $columns = [$columns] if ! ref $columns;
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
826
        foreach my $column (@$columns) {
cleanup
Yuki Kimoto authored on 2011-04-02
827
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
828
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
829
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
830
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
831
    }
832
    else { push @sql, '*' }
833
    
834
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
835
    push @sql, 'from';
cleanup
Yuki Kimoto authored on 2011-04-02
836
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-30
837
    if ($relation) {
838
        my $found = {};
839
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
840
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
841
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
842
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
843
    }
cleanup
Yuki Kimoto authored on 2011-03-30
844
    else {
845
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
846
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
847
    }
848
    pop @sql if ($sql[-1] || '') eq ',';
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
849
    croak "Not found table name" unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
850

            
cleanup
Yuki Kimoto authored on 2011-04-02
851
    # Add tables in parameter
852
    unshift @$tables, @{$self->_search_tables(join(' ', keys %$param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
853
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
854
    # Where
cleanup
Yuki Kimoto authored on 2011-04-02
855
    $where = $self->_where_to_obj($where);
856
    $param = keys %$param ? $self->merge_param($param, $where->param)
857
                          : $where->param;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
858
    
859
    # String where
cleanup
Yuki Kimoto authored on 2011-04-02
860
    my $where_clause = $where->to_string;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
861
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
862
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
863
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
864
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
865
    # Push join
866
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
867
    
cleanup
Yuki Kimoto authored on 2011-03-09
868
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
869
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
870
    
cleanup
Yuki Kimoto authored on 2011-03-08
871
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
872
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
873
    
cleanup
Yuki Kimoto authored on 2011-04-02
874
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
875
    push @sql, $append if $append;
876
    
877
    # SQL
878
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
879
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
880
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
881
    my $query = $self->create_query($sql);
cleanup
Yuki Kimoto authored on 2011-04-02
882
    return $query if $query_return;
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
883
    
packaging one directory
yuki-kimoto authored on 2009-11-16
884
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
885
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-03-21
886
        $query,
cleanup
Yuki Kimoto authored on 2011-04-02
887
        param => $param, 
cleanup
Yuki Kimoto authored on 2011-03-21
888
        table => $tables,
889
        %args
890
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
891
    
892
    return $result;
893
}
894

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

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

            
900
    # Arguments
901
    my $primary_keys = delete $args{primary_key};
902
    $primary_keys = [$primary_keys] unless ref $primary_keys;
903
    my $where = delete $args{where};
904
    my $param = delete $args{param};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
905
    
cleanup
Yuki Kimoto authored on 2011-04-02
906
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
907
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-02
908
        croak qq{Argument "$name" is wrong name}
cleanup
Yuki Kimoto authored on 2011-03-21
909
          unless $SELECT_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
910
    }
911
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
912
    # Table
913
    croak qq{"table" option must be specified} unless $args{table};
914
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
915
    
cleanup
Yuki Kimoto authored on 2011-04-02
916
    # Create where parameter
917
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
918
    
cleanup
Yuki Kimoto authored on 2011-04-02
919
    return $self->select(where => $where_param, %args);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
920
}
921

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
922
sub setup_model {
923
    my $self = shift;
924
    
cleanup
Yuki Kimoto authored on 2011-04-02
925
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
926
    $self->each_column(
927
        sub {
928
            my ($self, $table, $column, $column_info) = @_;
929
            if (my $model = $self->models->{$table}) {
930
                push @{$model->columns}, $column;
931
            }
932
        }
933
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
934
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
935
}
936

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
943
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
944
    my $table = delete $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
945
    croak qq{"table" option must be specified} unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
946
    my $param            = delete $args{param} || {};
947
    my $where            = delete $args{where} || {};
948
    my $append           = delete $args{append} || '';
949
    my $allow_update_all = delete $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
950
    
cleanup
Yuki Kimoto authored on 2011-04-02
951
    # Check argument names
952
    foreach my $name (keys %args) {
953
        croak qq{Argument "$name" is wrong name}
954
          unless $UPDATE_ARGS{$name};
955
    }
956
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
957
    # Columns
958
    my @columns;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
959
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
960
    my $q = $self->reserved_word_quote;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
961
    foreach my $column (keys %$param) {
962
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
963
          unless $column =~ /^[$safety\.]+$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
964
          $column = "$q$column$q";
965
          $column =~ s/\./$q.$q/;
966
        push @columns, "$column";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
967
    }
968
        
cleanup
yuki-kimoto authored on 2010-10-17
969
    # Update clause
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
970
    my $update_clause = '{update_param ' . join(' ', @columns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
971

            
972
    # Where
cleanup
Yuki Kimoto authored on 2011-04-02
973
    $where = $self->_where_to_obj($where);
974
    my $where_clause = $where->to_string;
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
975
    croak qq{"where" must be specified}
cleanup
Yuki Kimoto authored on 2011-04-02
976
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
977
    
cleanup
Yuki Kimoto authored on 2011-04-02
978
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
979
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
980
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
981
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
982
    
cleanup
Yuki Kimoto authored on 2011-04-02
983
    # Merge parameters
984
    $param = $self->merge_param($param, $where->param);
cleanup
yuki-kimoto authored on 2010-10-17
985
    
cleanup
Yuki Kimoto authored on 2011-01-27
986
    # SQL
987
    my $sql = join(' ', @sql);
988
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
989
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
990
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
991
    return $query if $args{query};
992
    
cleanup
yuki-kimoto authored on 2010-10-17
993
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
994
    my $ret_val = $self->execute(
995
        $query,
996
        param  => $param, 
997
        table => $table,
998
        %args
999
    );
cleanup
yuki-kimoto authored on 2010-10-17
1000
    
1001
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1002
}
1003

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

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

            
1008
sub update_at {
1009
    my ($self, %args) = @_;
1010
    
cleanup
Yuki Kimoto authored on 2011-04-02
1011
    # Arguments
1012
    my $primary_keys = delete $args{primary_key};
1013
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1014
    my $where = delete $args{where};
1015
    
1016

            
1017
    # Check arguments
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1018
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-02
1019
        croak qq{Argument "$name" is wrong name}
cleanup
Yuki Kimoto authored on 2011-03-21
1020
          unless $UPDATE_AT_ARGS{$name};
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1021
    }
1022
    
cleanup
Yuki Kimoto authored on 2011-04-02
1023
    # Create where parameter
1024
    my $where_param = $self->_create_where_param($where, $primary_keys);
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1025
    
cleanup
Yuki Kimoto authored on 2011-04-02
1026
    return $self->update(where => $where_param, %args);
1027
}
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1028

            
cleanup
Yuki Kimoto authored on 2011-04-02
1029
sub _create_where_param {
1030
    my ($self, $where, $primary_keys) = @_;
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-02-28
1031
    
cleanup
Yuki Kimoto authored on 2011-04-02
1032
    # Create where parameter
1033
    my $where_param = {};
1034
    if ($where) {
1035
        $where = [$where] unless ref $where;
1036
        croak qq{"where" must be constant value or array reference}
1037
          unless !ref $where || ref $where eq 'ARRAY';
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1038
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-04-02
1039
           $where_param->{$primary_keys->[$i]} = $where->[$i];
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1040
        }
1041
    }
1042
    
cleanup
Yuki Kimoto authored on 2011-04-02
1043
    return $where_param;
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1044
}
1045

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1046
sub update_param_tag {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1047
    my ($self, $param, $opt) = @_;
1048
    
cleanup
Yuki Kimoto authored on 2011-04-02
1049
    # Create update parameter tag
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1050
    my @params;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1051
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1052
    my $q = $self->reserved_word_quote;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1053
    foreach my $column (keys %$param) {
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
1054
        croak qq{"$column" is not safety column name}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1055
          unless $column =~ /^[$safety\.]+$/;
cleanup
Yuki Kimoto authored on 2011-04-02
1056
        my $column = "$q$column$q";
1057
        $column =~ s/\./$q.$q/;
1058
        push @params, "$column = {? $column}";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1059
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1060
    my $tag;
1061
    $tag .= 'set ' unless $opt->{no_set};
1062
    $tag .= join(', ', @params);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1063
    
cleanup
Yuki Kimoto authored on 2011-04-02
1064
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1065
}
1066

            
cleanup
Yuki Kimoto authored on 2011-01-25
1067
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1068
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1069
    
1070
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1071
    return DBIx::Custom::Where->new(
1072
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1073
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1074
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1075
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1076
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1077
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1078

            
cleanup
Yuki Kimoto authored on 2011-04-02
1079
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1080
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1081
    
cleanup
Yuki Kimoto authored on 2011-04-02
1082
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1083
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1084
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1085
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1086
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1087
        
1088
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1089
        my $value;
1090
        if(ref $params->{$column} eq 'ARRAY') {
1091
            my $i = $count->{$column} || 0;
1092
            $i += $not_exists->{$column} || 0;
1093
            my $found;
1094
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1095
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1096
                    $not_exists->{$column}++;
1097
                }
1098
                else  {
1099
                    $value = $params->{$column}->[$k];
1100
                    $found = 1;
1101
                    last
1102
                }
1103
            }
1104
            next unless $found;
1105
        }
1106
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1107
        
cleanup
Yuki Kimoto authored on 2011-01-12
1108
        # Filter
1109
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1110
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1111
        # Type
1112
        push @$bind, {
1113
            value => $f ? $f->($value) : $value,
1114
            type => $type->{$column}
1115
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1116
        
1117
        # Count up 
1118
        $count->{$column}++;
1119
    }
1120
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1121
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1122
}
1123

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1124
sub _connect {
1125
    my $self = shift;
1126
    
1127
    # Attributes
1128
    my $data_source = $self->data_source;
1129
    croak qq{"data_source" must be specified to connect()"}
1130
      unless $data_source;
1131
    my $user        = $self->user;
1132
    my $password    = $self->password;
1133
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
1134
    
1135
    # Connect
1136
    my $dbh = eval {DBI->connect(
1137
        $data_source,
1138
        $user,
1139
        $password,
1140
        {
1141
            %{$self->default_dbi_option},
1142
            %$dbi_option
1143
        }
1144
    )};
1145
    
1146
    # Connect error
1147
    croak $@ if $@;
1148
    
1149
    return $dbh;
1150
}
1151

            
cleanup
yuki-kimoto authored on 2010-10-17
1152
sub _croak {
1153
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1154
    
1155
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1156
    $append ||= "";
1157
    
1158
    # Verbose
1159
    if ($Carp::Verbose) { croak $error }
1160
    
1161
    # Not verbose
1162
    else {
1163
        
1164
        # Remove line and module infromation
1165
        my $at_pos = rindex($error, ' at ');
1166
        $error = substr($error, 0, $at_pos);
1167
        $error =~ s/\s+$//;
1168
        croak "$error$append";
1169
    }
1170
}
1171

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1172
sub _need_tables {
1173
    my ($self, $tree, $need_tables, $tables) = @_;
1174
    
cleanup
Yuki Kimoto authored on 2011-04-02
1175
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1176
    foreach my $table (@$tables) {
1177
        if ($tree->{$table}) {
1178
            $need_tables->{$table} = 1;
1179
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1180
        }
1181
    }
1182
}
1183

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1184
sub _push_join {
1185
    my ($self, $sql, $join, $join_tables) = @_;
1186
    
cleanup
Yuki Kimoto authored on 2011-04-02
1187
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1188
    return unless @$join;
1189
    
cleanup
Yuki Kimoto authored on 2011-04-02
1190
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1191
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1192
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1193
    for (my $i = 0; $i < @$join; $i++) {
1194
        
cleanup
Yuki Kimoto authored on 2011-04-02
1195
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1196
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1197
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1198
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1199
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1200
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1201
            my $table1 = $1;
1202
            my $table2 = $2;
1203
            croak qq{right side table of "$join_clause" must be uniq}
1204
              if exists $tree->{$table2};
1205
            $tree->{$table2}
1206
              = {position => $i, parent => $table1, join => $join_clause};
1207
        }
1208
        else {
1209
            croak qq{join "$join_clause" must be two table name};
1210
        }
1211
    }
1212
    
cleanup
Yuki Kimoto authored on 2011-04-02
1213
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1214
    my $need_tables = {};
1215
    $self->_need_tables($tree, $need_tables, $join_tables);
1216
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1217
    
1218
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1219
    foreach my $need_table (@need_tables) {
1220
        push @$sql, $tree->{$need_table}{join};
1221
    }
1222
}
cleanup
Yuki Kimoto authored on 2011-03-08
1223

            
cleanup
Yuki Kimoto authored on 2011-04-02
1224
sub _remove_duplicate_table {
1225
    my ($self, $tables, $main_table) = @_;
1226
    
1227
    # Remove duplicate table
1228
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1229
    delete $tables{$main_table} if $main_table;
1230
    
1231
    return [keys %tables, $main_table ? $main_table : ()];
1232
}
1233

            
cleanup
Yuki Kimoto authored on 2011-04-02
1234
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1235
    my ($self, $source) = @_;
1236
    
cleanup
Yuki Kimoto authored on 2011-04-02
1237
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1238
    my $tables = [];
1239
    my $safety_character = $self->safety_character;
1240
    my $q = $self->reserved_word_quote;
1241
    my $q_re = quotemeta($q);
1242
    my $table_re = $q ? qr/\b$q_re?([$safety_character]+)$q_re?\./
1243
                      : qr/\b([$safety_character]+)\./;
1244
    while ($source =~ /$table_re/g) {
1245
        push @$tables, $1;
1246
    }
1247
    
1248
    return $tables;
1249
}
1250

            
cleanup
Yuki Kimoto authored on 2011-04-02
1251
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1252
    my ($self, $where) = @_;
1253
    
cleanup
Yuki Kimoto authored on 2011-04-02
1254
    my $obj;
1255
    
1256
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1257
    if (ref $where eq 'HASH') {
1258
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1259
        my $q = $self->reserved_word_quote;
1260
        foreach my $column (keys %$where) {
1261
            $column = "$q$column$q";
1262
            $column =~ s/\./$q.$q/;
1263
            push @$clause, "{= $column}" for keys %$where;
1264
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1265
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1266
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1267
    
1268
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1269
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1270
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1271
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1272
    
1273
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1274
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1275
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1276
             "use \$dbi->select(where => \$dbi->where(clause => " .
1277
             "CLAUSE, param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1278
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1279
            clause => $where->[0],
1280
            param  => $where->[1]
1281
        );
1282
    }
1283
    
cleanup
Yuki Kimoto authored on 2011-04-02
1284
    # Check where argument
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1285
    croak qq{"where" must be hash reference or DBIx::Custom::Where object} .
1286
          qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-02
1287
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1288
    
cleanup
Yuki Kimoto authored on 2011-04-02
1289
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1290
}
1291

            
cleanup
Yuki Kimoto authored on 2011-01-25
1292
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1293
__PACKAGE__->attr(
1294
    dbi_options => sub { {} },
1295
    filter_check  => 1
1296
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1297

            
cleanup
Yuki Kimoto authored on 2011-01-25
1298
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1299
sub default_bind_filter {
1300
    my $self = shift;
1301
    
1302
    if (@_) {
1303
        my $fname = $_[0];
1304
        
1305
        if (@_ && !$fname) {
1306
            $self->{default_out_filter} = undef;
1307
        }
1308
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1309
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1310
              unless exists $self->filters->{$fname};
1311
        
1312
            $self->{default_out_filter} = $self->filters->{$fname};
1313
        }
1314
        return $self;
1315
    }
1316
    
1317
    return $self->{default_out_filter};
1318
}
1319

            
cleanup
Yuki Kimoto authored on 2011-01-25
1320
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1321
sub default_fetch_filter {
1322
    my $self = shift;
1323
    
1324
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1325
        my $fname = $_[0];
1326

            
cleanup
Yuki Kimoto authored on 2011-01-12
1327
        if (@_ && !$fname) {
1328
            $self->{default_in_filter} = undef;
1329
        }
1330
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1331
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1332
              unless exists $self->filters->{$fname};
1333
        
1334
            $self->{default_in_filter} = $self->filters->{$fname};
1335
        }
1336
        
1337
        return $self;
1338
    }
1339
    
many changed
Yuki Kimoto authored on 2011-01-23
1340
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1341
}
1342

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1343
# DEPRECATED!
1344
sub insert_param {
1345
    warn "insert_param is renamed to insert_param_tag."
1346
       . " insert_param is DEPRECATED!";
1347
    return shift->insert_param_tag(@_);
1348
}
1349

            
cleanup
Yuki Kimoto authored on 2011-01-25
1350
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1351
sub register_tag_processor {
1352
    return shift->query_builder->register_tag_processor(@_);
1353
}
1354

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1355
# DEPRECATED!
1356
sub update_param {
1357
    warn "update_param is renamed to update_param_tag."
1358
       . " update_param is DEPRECATED!";
1359
    return shift->update_param_tag(@_);
1360
}
cleanup
Yuki Kimoto authored on 2011-03-08
1361
# DEPRECATED!
1362
sub _push_relation {
1363
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1364
    
1365
    if (keys %{$relation || {}}) {
1366
        push @$sql, $need_where ? 'where' : 'and';
1367
        foreach my $rcolumn (keys %$relation) {
1368
            my $table1 = (split (/\./, $rcolumn))[0];
1369
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1370
            push @$tables, ($table1, $table2);
1371
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1372
        }
1373
    }
1374
    pop @$sql if $sql->[-1] eq 'and';    
1375
}
1376

            
1377
# DEPRECATED!
1378
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1379
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1380
    
1381
    if (keys %{$relation || {}}) {
1382
        foreach my $rcolumn (keys %$relation) {
1383
            my $table1 = (split (/\./, $rcolumn))[0];
1384
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1385
            my $table1_exists;
1386
            my $table2_exists;
1387
            foreach my $table (@$tables) {
1388
                $table1_exists = 1 if $table eq $table1;
1389
                $table2_exists = 1 if $table eq $table2;
1390
            }
1391
            unshift @$tables, $table1 unless $table1_exists;
1392
            unshift @$tables, $table2 unless $table2_exists;
1393
        }
1394
    }
1395
}
1396

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1399
=head1 NAME
1400

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

            
1403
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1404

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1405
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1406
    
1407
    # Connect
1408
    my $dbi = DBIx::Custom->connect(
1409
        data_source => "dbi:mysql:database=dbname",
1410
        user => 'ken',
1411
        password => '!LFKD%$&',
1412
        dbi_option => {mysql_enable_utf8 => 1}
1413
    );
cleanup
yuki-kimoto authored on 2010-08-05
1414

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1415
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1416
    $dbi->insert(
1417
        table  => 'book',
1418
        param  => {title => 'Perl', author => 'Ken'}
1419
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1420
    
1421
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1422
    $dbi->update(
1423
        table  => 'book', 
1424
        param  => {title => 'Perl', author => 'Ken'}, 
1425
        where  => {id => 5},
1426
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1427
    
1428
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1429
    $dbi->delete(
1430
        table  => 'book',
1431
        where  => {author => 'Ken'},
1432
    );
cleanup
yuki-kimoto authored on 2010-08-05
1433

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1440
    # Select, more complex
1441
    my $result = $dbi->select(
1442
        table  => 'book',
1443
        column => [
1444
            'book.author as book__author',
1445
            'company.name as company__name'
1446
        ],
1447
        where  => {'book.author' => 'Ken'},
1448
        join => ['left outer join company on book.company_id = company.id'],
1449
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1450
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1451
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1452
    # Fetch
1453
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1454
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1455
    }
1456
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1457
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1458
    while (my $row = $result->fetch_hash) {
1459
        
1460
    }
1461
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1462
    # Execute SQL with parameter.
1463
    $dbi->execute(
1464
        "select id from book where {= author} and {like title}",
1465
        param  => {author => 'ken', title => '%Perl%'}
1466
    );
1467
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1468
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1469

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

            
1472
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1473

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1478
There are many basic methods to execute various queries.
1479
C<insert()>, C<update()>, C<update_all()>,C<delete()>,
1480
C<delete_all()>, C<select()>,
1481
C<insert_at()>, C<update_at()>, 
1482
C<delete_at()>, C<select_at()>, C<execute()>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1483

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1484
=item *
1485

            
1486
Filter when data is send or receive.
1487

            
1488
=item *
1489

            
1490
Data filtering system
1491

            
1492
=item *
1493

            
1494
Model support.
1495

            
1496
=item *
1497

            
1498
Generate where clause dinamically.
1499

            
1500
=item *
1501

            
1502
Generate join clause dinamically.
1503

            
1504
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1505

            
1506
=head1 GUIDE
1507

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

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

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

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

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

            
1518
    my $connector = $dbi->connector;
1519
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1520

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

            
1524
This is L<DBIx::Connector> example. Please pass
1525
C<default_dbi_option> to L<DBIx::Connector>.
1526

            
1527
    my $connector = DBIx::Connector->new(
1528
        "dbi:mysql:database=$DATABASE",
1529
        $USER,
1530
        $PASSWORD,
1531
        DBIx::Custom->new->default_dbi_option
1532
    );
1533
    
1534
    my $dbi = DBIx::Custom->new(connector => $connector);
1535

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

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

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

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

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

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

            
1551
=head2 C<default_dbi_option>
1552

            
1553
    my $default_dbi_option = $dbi->default_dbi_option;
1554
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1555

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1559
    {
1560
        RaiseError => 1,
1561
        PrintError => 0,
1562
        AutoCommit => 1,
1563
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1564

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

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

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

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

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

            
1577
    my $models = $dbi->models;
1578
    $dbi       = $dbi->models(\%models);
1579

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1582
=head2 C<password>
1583

            
1584
    my $password = $dbi->password;
1585
    $dbi         = $dbi->password('lkj&le`@s');
1586

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

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

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

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

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

            
1598
     my reserved_word_quote = $dbi->reserved_word_quote;
1599
     $dbi                   = $dbi->reserved_word_quote('"');
1600

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1620
    my $user = $dbi->user;
1621
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1622

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1633
    $dbi->apply_filter(
cleanup
Yuki Kimoto authored on 2011-03-10
1634
        'book',
update pod
Yuki Kimoto authored on 2011-03-13
1635
        'issue_date' => {
1636
            out => 'tp_to_date',
1637
            in  => 'date_to_tp',
1638
            end => 'tp_to_displaydate'
1639
        },
1640
        'write_date' => {
1641
            out => 'tp_to_date',
1642
            in  => 'date_to_tp',
1643
            end => 'tp_to_displaydate'
1644
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1645
    );
1646

            
update pod
Yuki Kimoto authored on 2011-03-13
1647
Apply filter to columns.
1648
C<out> filter is executed before data is send to database.
1649
C<in> filter is executed after a row is fetch.
1650
C<end> filter is execute after C<in> filter is executed.
1651

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1654
       PETTERN         EXAMPLE
1655
    1. Column        : author
1656
    2. Table.Column  : book.author
1657
    3. Table__Column : book__author
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1658

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

            
1662
You can set multiple filters at once.
1663

            
1664
    $dbi->apply_filter(
1665
        'book',
1666
        [qw/issue_date write_date/] => {
1667
            out => 'tp_to_date',
1668
            in  => 'date_to_tp',
1669
            end => 'tp_to_displaydate'
1670
        }
1671
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1672

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1675
    my $dbi = DBIx::Custom->connect(
1676
        data_source => "dbi:mysql:database=dbname",
1677
        user => 'ken',
1678
        password => '!LFKD%$&',
1679
        dbi_option => {mysql_enable_utf8 => 1}
1680
    );
1681

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1690
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1691
        table => 'book',
1692
        primary_key => 'id',
1693
        join => [
1694
            'inner join company on book.comparny_id = company.id'
1695
        ],
1696
        filter => [
1697
            publish_date => {
1698
                out => 'tp_to_date',
1699
                in => 'date_to_tp',
1700
                end => 'tp_to_displaydate'
1701
            }
1702
        ]
1703
    );
1704

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

            
1708
   $dbi->model('book')->select(...);
1709

            
cleanup
yuki-kimoto authored on 2010-10-17
1710
=head2 C<create_query>
1711
    
1712
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1713
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1714
    );
update document
yuki-kimoto authored on 2009-11-19
1715

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

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

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

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

            
1726
    my $dbh = $dbi->dbh;
1727

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

            
1731
=head2 C<each_column>
1732

            
1733
    $dbi->each_column(
1734
        sub {
1735
            my ($dbi, $table, $column, $column_info) = @_;
1736
            
1737
            my $type = $column_info->{TYPE_NAME};
1738
            
1739
            if ($type eq 'DATE') {
1740
                # ...
1741
            }
1742
        }
1743
    );
1744

            
1745
Iterate all column informations of all table from database.
1746
Argument is callback when one column is found.
1747
Callback receive four arguments, dbi object, table name,
1748
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1749

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1752
    my $result = $dbi->execute(
1753
        "select * from book where {= title} and {like author}",
1754
        param => {title => 'Perl', author => '%Ken%'}
1755
    );
1756

            
1757
Execute SQL, containing tags.
1758
Return value is L<DBIx::Custom::Result> in select statement, or
1759
the count of affected rows in insert, update, delete statement.
1760

            
1761
Tag is turned into the statement containing place holder
1762
before SQL is executed.
1763

            
1764
    select * from where title = ? and author like ?;
1765

            
1766
See also L<Tags/Tags>.
1767

            
1768
The following opitons are currently available.
1769

            
1770
=over 4
1771

            
1772
=item C<filter>
1773

            
1774
Filter, executed before data is send to database. This is array reference.
1775
Filter value is code reference or
1776
filter name registerd by C<register_filter()>.
1777

            
1778
    # Basic
1779
    $dbi->execute(
1780
        $sql,
1781
        filter => [
1782
            title  => sub { uc $_[0] }
1783
            author => sub { uc $_[0] }
1784
        ]
1785
    );
1786
    
1787
    # At once
1788
    $dbi->execute(
1789
        $sql,
1790
        filter => [
1791
            [qw/title author/]  => sub { uc $_[0] }
1792
        ]
1793
    );
1794
    
1795
    # Filter name
1796
    $dbi->execute(
1797
        $sql,
1798
        filter => [
1799
            title  => 'upper_case',
1800
            author => 'upper_case'
1801
        ]
1802
    );
1803

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

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

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

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

            
1812
Delete statement.
1813

            
1814
The following opitons are currently available.
1815

            
update pod
Yuki Kimoto authored on 2011-03-13
1816
=over 4
1817

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

            
1820
Table name.
1821

            
1822
    $dbi->delete(table => 'book');
1823

            
1824
=item C<where>
1825

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1826
Where clause. This is hash reference or L<DBIx::Custom::Where> object
1827
or array refrence, which contains where clause and paramter.
update pod
Yuki Kimoto authored on 2011-03-13
1828
    
1829
    # Hash reference
1830
    $dbi->delete(where => {title => 'Perl'});
1831
    
1832
    # DBIx::Custom::Where object
1833
    my $where = $dbi->where(
1834
        clause => ['and', '{= author}', '{like title}'],
1835
        param  => {author => 'Ken', title => '%Perl%'}
1836
    );
1837
    $dbi->delete(where => $where);
1838

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1839
    # Array refrendce (where clause and parameter)
1840
    $dbi->delete(where =>
1841
        [
1842
            ['and', '{= author}', '{like title}'],
1843
            {author => 'Ken', title => '%Perl%'}
1844
        ]
1845
    );
1846
    
update pod
Yuki Kimoto authored on 2011-03-13
1847
=item C<append>
1848

            
1849
Append statement to last of SQL. This is string.
1850

            
1851
    $dbi->delete(append => 'order by title');
1852

            
1853
=item C<filter>
1854

            
1855
Filter, executed before data is send to database. This is array reference.
1856
Filter value is code reference or
1857
filter name registerd by C<register_filter()>.
1858

            
1859
    # Basic
1860
    $dbi->delete(
1861
        filter => [
1862
            title  => sub { uc $_[0] }
1863
            author => sub { uc $_[0] }
1864
        ]
1865
    );
1866
    
1867
    # At once
1868
    $dbi->delete(
1869
        filter => [
1870
            [qw/title author/]  => sub { uc $_[0] }
1871
        ]
1872
    );
1873
    
1874
    # Filter name
1875
    $dbi->delete(
1876
        filter => [
1877
            title  => 'upper_case',
1878
            author => 'upper_case'
1879
        ]
1880
    );
1881

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

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
1884
=head2 C<column>
cleanup
Yuki Kimoto authored on 2011-03-21
1885

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

            
1888
Create column clause. The follwoing column clause is created.
1889

            
1890
    book.author as book__author,
1891
    book.title as book__title
1892

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

            
1895
Get L<DBIx::Custom::Query> object instead of executing SQL.
1896
This is true or false value.
1897

            
1898
    my $query = $dbi->delete(query => 1);
1899

            
1900
You can check SQL.
1901

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1904
=back
1905

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

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

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

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

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

            
1917
    $dbi->delete_at(
1918
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
1919
        primary_key => 'id',
1920
        where => '5'
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1921
    );
1922

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1927
=over 4
1928

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1931
Primary key. This is constant value or array reference.
1932
    
1933
    # Constant value
1934
    $dbi->delete(primary_key => 'id');
1935

            
1936
    # Array reference
1937
    $dbi->delete(primary_key => ['id1', 'id2' ]);
1938

            
1939
This is used to create where clause.
1940

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

            
1943
Where clause, created from primary key information.
1944
This is constant value or array reference.
1945

            
1946
    # Constant value
1947
    $dbi->delete(where => 5);
1948

            
1949
    # Array reference
1950
    $dbi->delete(where => [3, 5]);
1951

            
1952
In first examle, the following SQL is created.
1953

            
1954
    delete from book where id = ?;
1955

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

            
update pod
Yuki Kimoto authored on 2011-03-13
1958
=back
1959

            
cleanup
yuki-kimoto authored on 2010-10-17
1960
=head2 C<insert>
1961

            
update pod
Yuki Kimoto authored on 2011-03-13
1962
    $dbi->insert(
1963
        table  => 'book', 
1964
        param  => {title => 'Perl', author => 'Ken'}
1965
    );
1966

            
1967
Insert statement.
1968

            
1969
The following opitons are currently available.
1970

            
update pod
Yuki Kimoto authored on 2011-03-13
1971
=over 4
1972

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

            
1975
Table name.
1976

            
1977
    $dbi->insert(table => 'book');
1978

            
1979
=item C<param>
1980

            
1981
Insert data. This is hash reference.
1982

            
1983
    $dbi->insert(param => {title => 'Perl'});
1984

            
1985
=item C<append>
1986

            
1987
Append statement to last of SQL. This is string.
1988

            
1989
    $dbi->insert(append => 'order by title');
1990

            
1991
=item C<filter>
1992

            
1993
Filter, executed before data is send to database. This is array reference.
1994
Filter value is code reference or
1995
filter name registerd by C<register_filter()>.
1996

            
1997
    # Basic
1998
    $dbi->insert(
1999
        filter => [
2000
            title  => sub { uc $_[0] }
2001
            author => sub { uc $_[0] }
2002
        ]
2003
    );
2004
    
2005
    # At once
2006
    $dbi->insert(
2007
        filter => [
2008
            [qw/title author/]  => sub { uc $_[0] }
2009
        ]
2010
    );
2011
    
2012
    # Filter name
2013
    $dbi->insert(
2014
        filter => [
2015
            title  => 'upper_case',
2016
            author => 'upper_case'
2017
        ]
2018
    );
2019

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

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

            
2024
Get L<DBIx::Custom::Query> object instead of executing SQL.
2025
This is true or false value.
2026

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2033
=back
2034

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

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

            
2039
    $dbi->insert_at(
2040
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2041
        primary_key => 'id',
2042
        where => '5',
2043
        param => {title => 'Perl'}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-02-28
2044
    );
2045

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2050
=over 4
2051

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

            
2054
Primary key. This is constant value or array reference.
2055
    
2056
    # Constant value
2057
    $dbi->insert(primary_key => 'id');
2058

            
2059
    # Array reference
2060
    $dbi->insert(primary_key => ['id1', 'id2' ]);
2061

            
2062
This is used to create parts of insert data.
2063

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

            
2066
Parts of Insert data, create from primary key information.
2067
This is constant value or array reference.
2068

            
2069
    # Constant value
2070
    $dbi->insert(where => 5);
2071

            
2072
    # Array reference
2073
    $dbi->insert(where => [3, 5]);
2074

            
2075
In first examle, the following SQL is created.
2076

            
2077
    insert into book (id, title) values (?, ?);
2078

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2081
=back
2082

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

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

            
2087
Create insert parameter tag.
2088

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2098
    lib / MyModel.pm
2099
        / MyModel / book.pm
2100
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2101

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

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

            
2106
    package MyModel;
2107
    
2108
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2109
    
2110
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2111

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2116
    package MyModel::book;
2117
    
2118
    use base 'MyModel';
2119
    
2120
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2121

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2124
    package MyModel::company;
2125
    
2126
    use base 'MyModel';
2127
    
2128
    1;
2129
    
2130
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2131

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

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

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

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

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

            
2143
Merge paramters.
2144

            
2145
$param:
2146

            
2147
    {key1 => [1, 1], key2 => 2}
2148

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

            
2151
    $dbi->method(
2152
        update_or_insert => sub {
2153
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2154
            
2155
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2156
        },
2157
        find_or_create   => sub {
2158
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2159
            
2160
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2161
        }
2162
    );
2163

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

            
2166
    $dbi->update_or_insert;
2167
    $dbi->find_or_create;
2168

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

            
2171
    $dbi->model('book')->method(
2172
        insert => sub { ... },
2173
        update => sub { ... }
2174
    );
2175
    
2176
    my $model = $dbi->model('book');
2177

            
2178
Set and get a L<DBIx::Custom::Model> object,
2179

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

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

            
2184
Create column clause for myself. The follwoing column clause is created.
2185

            
2186
    book.author as author,
2187
    book.title as title
2188

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2191
    my $dbi = DBIx::Custom->new(
2192
        data_source => "dbi:mysql:database=dbname",
2193
        user => 'ken',
2194
        password => '!LFKD%$&',
2195
        dbi_option => {mysql_enable_utf8 => 1}
2196
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2197

            
2198
Create a new L<DBIx::Custom> object.
2199

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

            
2202
    my $not_exists = $dbi->not_exists;
2203

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2207
=head2 C<register_filter>
2208

            
update pod
Yuki Kimoto authored on 2011-03-13
2209
    $dbi->register_filter(
2210
        # Time::Piece object to database DATE format
2211
        tp_to_date => sub {
2212
            my $tp = shift;
2213
            return $tp->strftime('%Y-%m-%d');
2214
        },
2215
        # database DATE format to Time::Piece object
2216
        date_to_tp => sub {
2217
           my $date = shift;
2218
           return Time::Piece->strptime($date, '%Y-%m-%d');
2219
        }
2220
    );
cleanup
yuki-kimoto authored on 2010-10-17
2221
    
update pod
Yuki Kimoto authored on 2011-03-13
2222
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2223

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2226
    $dbi->register_tag(
2227
        update => sub {
2228
            my @columns = @_;
2229
            
2230
            # Update parameters
2231
            my $s = 'set ';
2232
            $s .= "$_ = ?, " for @columns;
2233
            $s =~ s/, $//;
2234
            
2235
            return [$s, \@columns];
2236
        }
2237
    );
cleanup
yuki-kimoto authored on 2010-10-17
2238

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

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

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

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

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

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

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

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

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

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2262
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2263
        table  => 'book',
2264
        column => ['author', 'title'],
2265
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2266
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2267
    
update pod
Yuki Kimoto authored on 2011-03-12
2268
Select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2269

            
2270
The following opitons are currently available.
2271

            
2272
=over 4
2273

            
2274
=item C<table>
2275

            
2276
Table name.
2277

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

            
2280
=item C<column>
2281

            
2282
Column clause. This is array reference or constant value.
2283

            
2284
    # Hash refernce
2285
    $dbi->select(column => ['author', 'title']);
2286
    
2287
    # Constant value
2288
    $dbi->select(column => 'author');
2289

            
2290
Default is '*' unless C<column> is specified.
2291

            
2292
    # Default
2293
    $dbi->select(column => '*');
2294

            
2295
=item C<where>
2296

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2297
Where clause. This is hash reference or L<DBIx::Custom::Where> object,
2298
or array refrence, which contains where clause and paramter.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2299
    
2300
    # Hash reference
update pod
Yuki Kimoto authored on 2011-03-12
2301
    $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2302
    
update pod
Yuki Kimoto authored on 2011-03-12
2303
    # DBIx::Custom::Where object
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2304
    my $where = $dbi->where(
2305
        clause => ['and', '{= author}', '{like title}'],
2306
        param  => {author => 'Ken', title => '%Perl%'}
2307
    );
update pod
Yuki Kimoto authored on 2011-03-12
2308
    $dbi->select(where => $where);
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2309

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2310
    # Array refrendce (where clause and parameter)
2311
    $dbi->select(where =>
2312
        [
2313
            ['and', '{= author}', '{like title}'],
2314
            {author => 'Ken', title => '%Perl%'}
2315
        ]
2316
    );
2317
    
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2318
=item C<join>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2319

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

            
2322
    $dbi->select(join =>
2323
        [
2324
            'left outer join company on book.company_id = company_id',
2325
            'left outer join location on company.location_id = location.id'
2326
        ]
2327
    );
2328

            
2329
If column cluase or where clause contain table name like "company.name",
2330
needed join clause is used automatically.
2331

            
2332
    $dbi->select(
2333
        table => 'book',
2334
        column => ['company.location_id as company__location_id'],
2335
        where => {'company.name' => 'Orange'},
2336
        join => [
2337
            'left outer join company on book.company_id = company.id',
2338
            'left outer join location on company.location_id = location.id'
2339
        ]
2340
    );
2341

            
2342
In above select, the following SQL is created.
2343

            
2344
    select company.location_id as company__location_id
2345
    from book
2346
      left outer join company on book.company_id = company.id
2347
    where company.name = Orange
2348

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

            
2351
Parameter shown before where clause.
2352
    
2353
    $dbi->select(
2354
        table => 'table1',
2355
        column => 'table1.key1 as table1_key1, key2, key3',
2356
        where   => {'table1.key2' => 3},
2357
        join  => ['inner join (select * from table2 where {= table2.key3})' . 
2358
                  ' as table2 on table1.key1 = table2.key1'],
2359
        param => {'table2.key3' => 5}
2360
    );
2361

            
2362
For example, if you want to contain tag in join clause, 
2363
you can pass parameter by C<param> option.
2364

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

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

            
2369
    $dbi->select(append => 'order by title');
2370

            
2371
=item C<filter>
2372

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

            
2377
    # Basic
2378
    $dbi->select(
2379
        filter => [
2380
            title  => sub { uc $_[0] }
2381
            author => sub { uc $_[0] }
2382
        ]
2383
    );
2384
    
2385
    # At once
2386
    $dbi->select(
2387
        filter => [
2388
            [qw/title author/]  => sub { uc $_[0] }
2389
        ]
2390
    );
2391
    
2392
    # Filter name
2393
    $dbi->select(
2394
        filter => [
2395
            title  => 'upper_case',
2396
            author => 'upper_case'
2397
        ]
2398
    );
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
2399

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

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

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

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

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

            
2411
    my $sql = $query->sql;
2412

            
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2413
=item C<type>
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
2414

            
2415
Specify database data type.
2416

            
2417
    $dbi->select(type => [image => DBI::SQL_BLOB]);
2418
    $dbi->select(type => [[qw/image audio/] => DBI::SQL_BLOB]);
2419

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

            
2422
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2423

            
update pod
Yuki Kimoto authored on 2011-03-12
2424
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2425

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

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

            
2430
    $dbi->select_at(
2431
        table => 'book',
2432
        primary_key => 'id',
2433
        where => '5'
2434
    );
2435

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2440
=over 4
2441

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

            
update pod
Yuki Kimoto authored on 2011-03-12
2444
Primary key. This is constant value or array reference.
2445
    
2446
    # Constant value
2447
    $dbi->select(primary_key => 'id');
2448

            
2449
    # Array reference
2450
    $dbi->select(primary_key => ['id1', 'id2' ]);
2451

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

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

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

            
2459
    # Constant value
2460
    $dbi->select(where => 5);
2461

            
2462
    # Array reference
2463
    $dbi->select(where => [3, 5]);
2464

            
2465
In first examle, the following SQL is created.
2466

            
2467
    select * from book where id = ?
2468

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2471
=back
2472

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2475
    $dbi->update(
2476
        table  => 'book',
2477
        param  => {title => 'Perl'},
2478
        where  => {id => 4}
2479
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
2480

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2485
=over 4
2486

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2489
Table name.
2490

            
2491
    $dbi->update(table => 'book');
2492

            
2493
=item C<param>
2494

            
2495
Update data. This is hash reference.
2496

            
2497
    $dbi->update(param => {title => 'Perl'});
2498

            
2499
=item C<where>
2500

            
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2501
Where clause. This is hash reference or L<DBIx::Custom::Where> object
2502
or array refrence.
update pod
Yuki Kimoto authored on 2011-03-13
2503
    
2504
    # Hash reference
2505
    $dbi->update(where => {author => 'Ken', 'title' => 'Perl'});
2506
    
2507
    # DBIx::Custom::Where object
2508
    my $where = $dbi->where(
2509
        clause => ['and', '{= author}', '{like title}'],
2510
        param  => {author => 'Ken', title => '%Perl%'}
2511
    );
2512
    $dbi->update(where => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2513
    
2514
    # Array refrendce (where clause and parameter)
2515
    $dbi->update(where =>
2516
        [
2517
            ['and', '{= author}', '{like title}'],
2518
            {author => 'Ken', title => '%Perl%'}
2519
        ]
2520
    );
update pod
Yuki Kimoto authored on 2011-03-13
2521

            
2522
=item C<append>
2523

            
2524
Append statement to last of SQL. This is string.
2525

            
2526
    $dbi->update(append => 'order by title');
2527

            
2528
=item C<filter>
2529

            
2530
Filter, executed before data is send to database. This is array reference.
2531
Filter value is code reference or
2532
filter name registerd by C<register_filter()>.
2533

            
2534
    # Basic
2535
    $dbi->update(
2536
        filter => [
2537
            title  => sub { uc $_[0] }
2538
            author => sub { uc $_[0] }
2539
        ]
2540
    );
2541
    
2542
    # At once
2543
    $dbi->update(
2544
        filter => [
2545
            [qw/title author/]  => sub { uc $_[0] }
2546
        ]
2547
    );
2548
    
2549
    # Filter name
2550
    $dbi->update(
2551
        filter => [
2552
            title  => 'upper_case',
2553
            author => 'upper_case'
2554
        ]
2555
    );
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
2556

            
update pod
Yuki Kimoto authored on 2011-03-13
2557
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
2558

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

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

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

            
2566
You can check SQL.
2567

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2570
=back
2571

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

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

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

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

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

            
2583
    $dbi->update_at(
2584
        table => 'book',
update pod
Yuki Kimoto authored on 2011-03-13
2585
        primary_key => 'id',
2586
        where => '5',
2587
        param => {title => 'Perl'}
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2588
    );
2589

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2594
=over 4
2595

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

            
2598
Primary key. This is constant value or array reference.
2599
    
2600
    # Constant value
2601
    $dbi->update(primary_key => 'id');
2602

            
2603
    # Array reference
2604
    $dbi->update(primary_key => ['id1', 'id2' ]);
2605

            
2606
This is used to create where clause.
2607

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

            
2610
Where clause, created from primary key information.
2611
This is constant value or array reference.
2612

            
2613
    # Constant value
2614
    $dbi->update(where => 5);
2615

            
2616
    # Array reference
2617
    $dbi->update(where => [3, 5]);
2618

            
2619
In first examle, the following SQL is created.
2620

            
2621
    update book set title = ? where id = ?
2622

            
2623
Place holders are set to 'Perl' and 5.
2624

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

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

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

            
2631
Create update parameter tag.
2632

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

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2635
You can create tag without 'set '
- removed DEPRECATED DBIx::C...
Yuki Kimoto authored on 2011-04-11
2636
by C<no_set> option.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2637

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
2638
    my $update_param_tag = $dbi->update_param_tag(
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2639
        {title => 'a', age => 2}
2640
        {no_set => 1}
2641
    );
2642

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-09
2647
    my $where = $dbi->where(
2648
        clause => ['and', '{= title}', '{= author}'],
2649
        param => {title => 'Perl', author => 'Ken'}
2650
    );
fix tests
Yuki Kimoto authored on 2011-01-18
2651

            
2652
Create a new L<DBIx::Custom::Where> object.
2653

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
2661
=head1 Tags
2662

            
2663
The following tags is available.
2664

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

            
2667
Table tag
2668

            
2669
    {table TABLE}    ->    TABLE
2670

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
2673
=head2 C<?>
2674

            
2675
Placeholder tag.
2676

            
2677
    {? NAME}    ->   ?
2678

            
2679
=head2 C<=>
2680

            
2681
Equal tag.
2682

            
2683
    {= NAME}    ->   NAME = ?
2684

            
2685
=head2 C<E<lt>E<gt>>
2686

            
2687
Not equal tag.
2688

            
2689
    {<> NAME}   ->   NAME <> ?
2690

            
2691
=head2 C<E<lt>>
2692

            
2693
Lower than tag
2694

            
2695
    {< NAME}    ->   NAME < ?
2696

            
2697
=head2 C<E<gt>>
2698

            
2699
Greater than tag
2700

            
2701
    {> NAME}    ->   NAME > ?
2702

            
2703
=head2 C<E<gt>=>
2704

            
2705
Greater than or equal tag
2706

            
2707
    {>= NAME}   ->   NAME >= ?
2708

            
2709
=head2 C<E<lt>=>
2710

            
2711
Lower than or equal tag
2712

            
2713
    {<= NAME}   ->   NAME <= ?
2714

            
2715
=head2 C<like>
2716

            
2717
Like tag
2718

            
2719
    {like NAME}   ->   NAME like ?
2720

            
2721
=head2 C<in>
2722

            
2723
In tag.
2724

            
2725
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2726

            
2727
=head2 C<insert_param>
2728

            
2729
Insert parameter tag.
2730

            
2731
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2732

            
2733
=head2 C<update_param>
2734

            
2735
Updata parameter tag.
2736

            
2737
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2738

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

            
2741
=head2 C<DBIX_CUSTOM_DEBUG>
2742

            
2743
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
2744
executed SQL is printed to STDERR.
2745

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

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

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

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

            
2755
C<< <kimoto.yuki at gmail.com> >>
2756

            
2757
L<http://github.com/yuki-kimoto/DBIx-Custom>
2758

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2759
=head1 AUTHOR
2760

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

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

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

            
2767
This program is free software; you can redistribute it and/or modify it
2768
under the same terms as Perl itself.
2769

            
2770
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
2771

            
2772