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

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

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

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

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
82
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
83
    my ($self, $param) = @_;
84
    
85
    # Create set tag
86
    my @params;
87
    my $safety = $self->safety_character;
88
    my $q = $self->reserved_word_quote;
89
    foreach my $column (keys %$param) {
90
        croak qq{"$column" is not safety column name } . _subname
91
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
92
        my $column_quote = "$q$column$q";
93
        $column_quote =~ s/\./$q.$q/;
94
        push @params, "$column_quote = :$column";
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
95
    }
96
    my $tag = join(', ', @params);
97
    
98
    return $tag;
99
}
100

            
cleanup
Yuki Kimoto authored on 2011-03-21
101
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
102
    my $self = shift;
103
    my $option = pop if ref $_[-1] eq 'HASH';
104
    my $real_table = shift;
105
    my $columns = shift;
106
    my $table = $option->{alias} || $real_table;
107
    
108
    # Columns
109
    unless ($columns) {
110
        $columns ||= $self->model($real_table)->columns;
111
    }
added helper method
yuki-kimoto authored on 2010-10-17
112
    
cleanup
Yuki Kimoto authored on 2011-04-02
113
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
114
    my $q = $self->reserved_word_quote;
115
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
116
    # Separator
117
    my $separator = $self->separator;
118
    
cleanup
Yuki Kimoto authored on 2011-04-02
119
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
120
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
121
    $columns ||= [];
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
122
    push @column, "$q$table$q.$q$_$q as $q${table}${separator}$_$q"
123
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
124
    
125
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
126
}
127

            
packaging one directory
yuki-kimoto authored on 2009-11-16
128
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
129
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
130
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
131
    # Connect
132
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
133
    
packaging one directory
yuki-kimoto authored on 2009-11-16
134
    return $self;
135
}
136

            
cleanup
yuki-kimoto authored on 2010-10-17
137
sub create_query {
138
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
139
    
cleanup
yuki-kimoto authored on 2010-10-17
140
    # Cache
141
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
142
    
cleanup
Yuki Kimoto authored on 2011-04-02
143
    # Query
cleanup
yuki-kimoto authored on 2010-10-17
144
    my $query;
cleanup
Yuki Kimoto authored on 2011-04-02
145
    
146
    # Get cached query
cleanup
yuki-kimoto authored on 2010-10-17
147
    if ($cache) {
148
        
149
        # Get query
150
        my $q = $self->cache_method->($self, $source);
151
        
152
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
153
        if ($q) {
154
            $query = DBIx::Custom::Query->new($q);
155
            $query->filters($self->filters);
156
        }
cleanup
yuki-kimoto authored on 2010-10-17
157
    }
158
    
cleanup
Yuki Kimoto authored on 2011-04-02
159
    # Create query
cleanup
yuki-kimoto authored on 2010-10-17
160
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
161

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
171
        # Save query to cache
172
        $self->cache_method->(
173
            $self, $source,
174
            {
175
                sql     => $query->sql, 
176
                columns => $query->columns,
177
                tables  => $query->tables
178
            }
179
        ) if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
180
    }
181
    
cleanup
yuki-kimoto authored on 2010-10-17
182
    # Prepare statement handle
183
    my $sth;
184
    eval { $sth = $self->dbh->prepare($query->{sql})};
improved error messages
Yuki Kimoto authored on 2011-04-18
185
    
186
    if ($@) {
187
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
188
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
189
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
190
    
cleanup
yuki-kimoto authored on 2010-10-17
191
    # Set statement handle
192
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
193
    
cleanup
Yuki Kimoto authored on 2011-02-09
194
    # Set filters
195
    $query->filters($self->filters);
196
    
cleanup
yuki-kimoto authored on 2010-10-17
197
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
198
}
199

            
update pod
Yuki Kimoto authored on 2011-03-13
200
sub dbh {
201
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
202
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
203
    # Set
204
    if (@_) {
205
        $self->{dbh} = $_[0];
206
        
207
        return $self;
208
    }
209
    
210
    # Get
211
    else {
212
        # From Connction manager
213
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
214
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
215
              unless ref $connector && $connector->can('dbh');
216
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
217
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
218
        }
219
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
220
        # Connect
221
        $self->{dbh} ||= $self->_connect;
222
        
223
        # Quote
224
        unless ($self->reserved_word_quote) {
225
            my $driver = $self->{dbh}->{Driver}->{Name};
226
            my $quote = $driver eq 'mysql' ? '`' : '"';
227
            $self->reserved_word_quote($quote);
228
        }
229

            
230
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
231
    }
232
}
233

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
240
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
241
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
242
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
243
          unless $DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
244
    }
245
    
246
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
247
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
248
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
249
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
250
    my $where            = delete $args{where} || {};
251
    my $append           = delete $args{append};
252
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
253
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
254
    my $id = delete $args{id};
255
    my $primary_key = delete $args{primary_key};
256
    croak "update method primary_key option " .
257
          "must be specified when id is specified " . _subname
258
      if defined $id && !defined $primary_key;
259
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
260
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
261
    # Where
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
262
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
263
    my $where_clause = '';
264
    if (ref $where) {
265
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
266
        $where_param = keys %$where_param
267
                     ? $self->merge_param($where_param, $where->param)
268
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
269
        
270
        # String where
271
        $where_clause = $where->to_string;
272
    }
273
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
274
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
275
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
276

            
cleanup
Yuki Kimoto authored on 2011-04-02
277
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
278
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
279
    my $q = $self->reserved_word_quote;
280
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
281
    push @sql, $append if $append;
282
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
283
    
284
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
285
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
286
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
287
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
288
        table => $table,
289
        %args
290
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
291
}
292

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

            
added helper method
yuki-kimoto authored on 2010-10-17
295
sub DESTROY { }
296

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
297
sub create_model {
298
    my $self = shift;
299
    
cleanup
Yuki Kimoto authored on 2011-04-02
300
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
301
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
302
    $args->{dbi} = $self;
303
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
304
    my $model_name  = delete $args->{name};
305
    my $model_table = delete $args->{table};
306
    $model_name ||= $model_table;
307
    
cleanup
Yuki Kimoto authored on 2011-04-02
308
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
309
    my $model = $model_class->new($args);
310
    $model->name($model_name) unless $model->name;
311
    $model->table($model_table) unless $model->table;
312
    
313
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
314
    my $filter = ref $model->filter eq 'HASH'
315
               ? [%{$model->filter}]
316
               : $model->filter;
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
317
    warn "DBIx::Custom::Model filter method is DEPRECATED!"
318
      if @$filter;
cleanup
Yuki Kimoto authored on 2011-06-13
319
    $self->_apply_filter($model->table, @$filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
320

            
321
    # Set model
322
    $self->model($model->name, $model);
323
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
324
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
325
}
326

            
327
sub each_column {
328
    my ($self, $cb) = @_;
329
    
330
    # Iterate all tables
331
    my $sth_tables = $self->dbh->table_info;
332
    while (my $table_info = $sth_tables->fetchrow_hashref) {
333
        
334
        # Table
335
        my $table = $table_info->{TABLE_NAME};
336
        
337
        # Iterate all columns
338
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
339
        while (my $column_info = $sth_columns->fetchrow_hashref) {
340
            my $column = $column_info->{COLUMN_NAME};
341
            $self->$cb($table, $column, $column_info);
342
        }
343
    }
344
}
345

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

            
348
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
349
    my $self = shift;
350
    my $query = shift;
351
    my $param;
352
    $param = shift if @_ % 2;
353
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
354
    
cleanup
Yuki Kimoto authored on 2011-04-02
355
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
356
    my $p = delete $args{param} || {};
357
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
358
    my $tables = delete $args{table} || [];
359
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
360
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
361
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
362
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
363
    $type = _array_to_hash($type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
364
    my $type_rule_off = delete $args{type_rule_off};
cleanup
Yuki Kimoto authored on 2011-06-09
365
    my $query_return = delete $args{query};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
366
    
cleanup
Yuki Kimoto authored on 2011-03-09
367
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
368
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
369
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
370
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
371
    }
372
    
cleanup
Yuki Kimoto authored on 2011-04-02
373
    # Create query
374
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
375
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
376
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
377
    
cleanup
Yuki Kimoto authored on 2011-04-02
378
    # Tables
379
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
380
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
381
    $tables = $self->_remove_duplicate_table($tables, $main_table);
382
    if (my $q = $self->reserved_word_quote) {
383
        $_ =~ s/$q//g for @$tables;
384
    }
cleanup
Yuki Kimoto authored on 2011-04-02
385
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
386
    # Type rule
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
387
    my $type_filter = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
388
    unless ($type_rule_off) {
389
        foreach my $name (keys %$param) {
390
            my $table;
391
            my $column;
392
            if ($name =~ /(?:(.+)\.)?(.+)/) {
393
                $table = $1;
394
                $column = $2;
395
            }
396
            $table ||= $main_table;
397
            
398
            my $into = $self->{_into} || {};
399
            if (defined $table && $into->{$table} &&
400
                (my $rule = $into->{$table}->{$column}))
401
            {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
402
                $type_filter->{$column} = $rule;
403
                $type_filter->{"$table.$column"} = $rule;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
404
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
405
        }
406
    }
cleanup
Yuki Kimoto authored on 2011-04-02
407
    
408
    # Applied filter
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
409
    my $applied_filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
410
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
411
        $applied_filter = {
412
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
413
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
414
        }
415
    }
cleanup
Yuki Kimoto authored on 2011-04-02
416
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
417
    
cleanup
Yuki Kimoto authored on 2011-04-02
418
    # Replace filter name to code
419
    foreach my $column (keys %$filter) {
420
        my $name = $filter->{$column};
421
        if (!defined $name) {
422
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
423
        }
cleanup
Yuki Kimoto authored on 2011-04-02
424
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
425
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
426
            unless exists $self->filters->{$name};
427
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
428
        }
429
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
430
    
cleanup
Yuki Kimoto authored on 2011-04-02
431
    # Create bind values
432
    my $bind = $self->_create_bind_values(
433
        $param,
434
        $query->columns,
435
        $filter,
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
436
        $type_filter,
cleanup
Yuki Kimoto authored on 2011-04-02
437
        $type
438
    );
cleanup
yuki-kimoto authored on 2010-10-17
439
    
440
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
441
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
442
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
443
    eval {
444
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
445
            my $type = $bind->[$i]->{type};
446
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
447
        }
448
        $affected = $sth->execute;
449
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
450
    
451
    if ($@) {
452
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
453
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
454
    }
cleanup
yuki-kimoto authored on 2010-10-17
455
    
improved debug message
Yuki Kimoto authored on 2011-05-23
456
    # DEBUG message
457
    if (DEBUG) {
458
        print STDERR "SQL:\n" . $query->sql . "\n";
459
        my @output;
460
        foreach my $b (@$bind) {
461
            my $value = $b->{value};
462
            $value = 'undef' unless defined $value;
463
            $value = encode(DEBUG_ENCODING(), $value)
464
              if utf8::is_utf8($value);
465
            push @output, $value;
466
        }
467
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
468
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
469
    
cleanup
Yuki Kimoto authored on 2011-04-02
470
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
471
    if ($sth->{NUM_OF_FIELDS}) {
472
        
cleanup
Yuki Kimoto authored on 2011-04-02
473
        # Filter
474
        my $filter = {};
475
        $filter->{in}  = {};
476
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
477
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
478
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
479
            foreach my $way (qw/in end/) {
480
                $filter->{$way} = {
481
                    %{$filter->{$way}},
482
                    %{$self->{filter}{$way}{$table} || {}}
483
                };
484
            }
cleanup
Yuki Kimoto authored on 2011-01-12
485
        }
486
        
487
        # Result
488
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
489
            sth => $sth,
490
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
491
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
492
            filter => $filter->{in} || {},
493
            end_filter => $filter->{end} || {},
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
494
            type_rule => \%{$self->type_rule->{from}},
cleanup
yuki-kimoto authored on 2010-10-17
495
        );
496

            
497
        return $result;
498
    }
cleanup
Yuki Kimoto authored on 2011-04-02
499
    
500
    # Not select statement
501
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
502
}
503

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

            
cleanup
yuki-kimoto authored on 2010-10-17
506
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
507
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
508
    
cleanup
yuki-kimoto authored on 2010-10-17
509
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
510
    my $param;
511
    $param = shift if @_ % 2;
512
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
513
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
514
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
515
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
516
    my $p = delete $args{param} || {};
517
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
518
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
519
    my $id = delete $args{id};
520
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
521
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
522
          "must be specified when id is specified " . _subname
523
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
524
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
525

            
526
    # Check arguments
527
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
528
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
529
          unless $INSERT_ARGS{$name};
530
    }
531

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
532
    # Merge parameter
533
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
534
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
535
        $param = $self->merge_param($id_param, $param);
536
    }
537

            
cleanup
Yuki Kimoto authored on 2011-04-02
538
    # Reserved word quote
539
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
540
    
cleanup
Yuki Kimoto authored on 2011-04-02
541
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
542
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
543
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
544
    push @sql, $append if $append;
545
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
546
    
547
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
548
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
549
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
550
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
551
        table => $table,
552
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
553
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
554
}
555

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
556
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
557
    my ($self, $param) = @_;
558
    
cleanup
Yuki Kimoto authored on 2011-04-02
559
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
560
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
561
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
562
    my @columns;
563
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
564
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
565
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
566
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
567
        my $column_quote = "$q$column$q";
568
        $column_quote =~ s/\./$q.$q/;
569
        push @columns, $column_quote;
570
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
571
    }
572
    
cleanup
Yuki Kimoto authored on 2011-04-02
573
    return '(' . join(', ', @columns) . ') ' . 'values ' .
574
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
575
}
576

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
577
sub include_model {
578
    my ($self, $name_space, $model_infos) = @_;
579
    
cleanup
Yuki Kimoto authored on 2011-04-02
580
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
581
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
582
    
583
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
584
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
585

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
586
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
587
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
588
          if $name_space =~ /[^\w:]/;
589
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
590
        croak qq{Name space module "$name_space.pm" is needed. $@ }
591
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
592
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
593
        
594
        # Search model modules
595
        my $path = $INC{"$name_space.pm"};
596
        $path =~ s/\.pm$//;
597
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
598
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
599
        $model_infos = [];
600
        while (my $module = readdir $dh) {
601
            push @$model_infos, $module
602
              if $module =~ s/\.pm$//;
603
        }
604
        close $dh;
605
    }
606
    
cleanup
Yuki Kimoto authored on 2011-04-02
607
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
608
    foreach my $model_info (@$model_infos) {
609
        
cleanup
Yuki Kimoto authored on 2011-04-02
610
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
611
        my $model_class;
612
        my $model_name;
613
        my $model_table;
614
        if (ref $model_info eq 'HASH') {
615
            $model_class = $model_info->{class};
616
            $model_name  = $model_info->{name};
617
            $model_table = $model_info->{table};
618
            
619
            $model_name  ||= $model_class;
620
            $model_table ||= $model_name;
621
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
622
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
623
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
624
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
625
          if $mclass =~ /[^\w:]/;
626
        unless ($mclass->can('isa')) {
627
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
628
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
629
        }
630
        
cleanup
Yuki Kimoto authored on 2011-04-02
631
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
632
        my $args = {};
633
        $args->{model_class} = $mclass if $mclass;
634
        $args->{name}        = $model_name if $model_name;
635
        $args->{table}       = $model_table if $model_table;
636
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
637
    }
638
    
639
    return $self;
640
}
641

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
642
sub merge_param {
643
    my ($self, @params) = @_;
644
    
cleanup
Yuki Kimoto authored on 2011-04-02
645
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
646
    my $merge = {};
647
    foreach my $param (@params) {
648
        foreach my $column (keys %$param) {
649
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
650
            
651
            if (exists $merge->{$column}) {
652
                $merge->{$column} = [$merge->{$column}]
653
                  unless ref $merge->{$column} eq 'ARRAY';
654
                push @{$merge->{$column}},
655
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
656
            }
657
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
658
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
659
            }
660
        }
661
    }
662
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
663
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
664
}
665

            
cleanup
Yuki Kimoto authored on 2011-03-21
666
sub method {
667
    my $self = shift;
668
    
cleanup
Yuki Kimoto authored on 2011-04-02
669
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
670
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
671
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
672
    
673
    return $self;
674
}
675

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
676
sub model {
677
    my ($self, $name, $model) = @_;
678
    
cleanup
Yuki Kimoto authored on 2011-04-02
679
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
680
    if ($model) {
681
        $self->models->{$name} = $model;
682
        return $self;
683
    }
684
    
685
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
686
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
687
      unless $self->models->{$name};
688
    
cleanup
Yuki Kimoto authored on 2011-04-02
689
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
690
    return $self->models->{$name};
691
}
692

            
cleanup
Yuki Kimoto authored on 2011-03-21
693
sub mycolumn {
694
    my ($self, $table, $columns) = @_;
695
    
cleanup
Yuki Kimoto authored on 2011-04-02
696
    # Create column clause
697
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
698
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
699
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
700
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
701
    
702
    return join (', ', @column);
703
}
704

            
added dbi_options attribute
kimoto authored on 2010-12-20
705
sub new {
706
    my $self = shift->SUPER::new(@_);
707
    
cleanup
Yuki Kimoto authored on 2011-04-02
708
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
709
    my @attrs = keys %$self;
710
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
711
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
712
          unless $self->can($attr);
713
    }
cleanup
Yuki Kimoto authored on 2011-04-02
714
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
715
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
716
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
717
        '?'     => \&DBIx::Custom::Tag::placeholder,
718
        '='     => \&DBIx::Custom::Tag::equal,
719
        '<>'    => \&DBIx::Custom::Tag::not_equal,
720
        '>'     => \&DBIx::Custom::Tag::greater_than,
721
        '<'     => \&DBIx::Custom::Tag::lower_than,
722
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
723
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
724
        'like'  => \&DBIx::Custom::Tag::like,
725
        'in'    => \&DBIx::Custom::Tag::in,
726
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
727
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
728
    };
added dbi_options attribute
kimoto authored on 2010-12-20
729
    
730
    return $self;
731
}
732

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

            
cleanup
yuki-kimoto authored on 2010-10-17
735
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
736
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
737
    
738
    # Register filter
739
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
740
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
741
    
cleanup
Yuki Kimoto authored on 2011-04-02
742
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
743
}
packaging one directory
yuki-kimoto authored on 2009-11-16
744

            
cleanup
Yuki Kimoto authored on 2011-03-21
745
our %SELECT_ARGS
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
746
  = map { $_ => 1 } @COMMON_ARGS,
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
747
                    qw/column where relation join param where_param wrap
748
                       prefix/;
refactoring select
yuki-kimoto authored on 2010-04-28
749

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
753
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
754
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
755
    my $tables = ref $table eq 'ARRAY' ? $table
756
               : defined $table ? [$table]
757
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
758
    my $columns   = delete $args{column};
759
    my $where     = delete $args{where} || {};
760
    my $append    = delete $args{append};
761
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
762
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
763
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
764
    my $relation = delete $args{relation};
added warnings
Yuki Kimoto authored on 2011-06-07
765
    warn "select() relation option is DEPRECATED! use join option instead"
766
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
767
    my $param = delete $args{param} || {}; # DEPRECATED!
added warnings
Yuki Kimoto authored on 2011-06-07
768
    warn "select() param option is DEPRECATED! use where_param option instead"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
769
      if keys %$param;
770
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
771
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
772
    my $id = delete $args{id};
773
    my $primary_key = delete $args{primary_key};
774
    croak "update method primary_key option " .
775
          "must be specified when id is specified " . _subname
776
      if defined $id && !defined $primary_key;
777
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
778
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
779
    
cleanup
Yuki Kimoto authored on 2011-04-02
780
    # Check arguments
781
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
782
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
783
          unless $SELECT_ARGS{$name};
784
    }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
785
    
cleanup
Yuki Kimoto authored on 2011-03-09
786
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
787
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
788
    
cleanup
Yuki Kimoto authored on 2011-04-02
789
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
790
    my @sql;
791
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
792
    
- select() column option can...
Yuki Kimoto authored on 2011-06-08
793
    # Reserved word quote
794
    my $q = $self->reserved_word_quote;
795
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
796
    # Prefix
797
    push @sql, $prefix if defined $prefix;
798
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
799
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
800
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
801
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
802
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
803
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
804
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
805
            }
806
            elsif (ref $column eq 'ARRAY') {
807
                croak "Format must be [COLUMN, as => ALIAS] " . _subname
808
                  unless @$column == 3 && $column->[1] eq 'as';
809
                $column = join(' ', $column->[0], 'as', $q . $column->[2] . $q);
810
            }
cleanup
Yuki Kimoto authored on 2011-04-02
811
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
812
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
813
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
814
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
815
    }
816
    else { push @sql, '*' }
817
    
818
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
819
    push @sql, 'from';
820
    if ($relation) {
821
        my $found = {};
822
        foreach my $table (@$tables) {
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
823
            push @sql, ("$q$table$q", ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
824
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
825
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
826
    }
cleanup
Yuki Kimoto authored on 2011-03-30
827
    else {
828
        my $main_table = $tables->[-1] || '';
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
829
        push @sql, "$q$main_table$q";
cleanup
Yuki Kimoto authored on 2011-03-30
830
    }
831
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
832
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
833
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
834

            
cleanup
Yuki Kimoto authored on 2011-04-02
835
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
836
    unshift @$tables,
837
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
838
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
839
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
840
    my $where_clause = '';
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
841
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
cleanup
Yuki Kimoto authored on 2011-04-25
842
    if (ref $where) {
843
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
844
        $where_param = keys %$where_param
845
                     ? $self->merge_param($where_param, $where->param)
846
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
847
        
848
        # String where
849
        $where_clause = $where->to_string;
850
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
851
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
852
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
853
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
854
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
855
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
856
    # Push join
857
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
858
    
cleanup
Yuki Kimoto authored on 2011-03-09
859
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
860
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
861
    
cleanup
Yuki Kimoto authored on 2011-03-08
862
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
863
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
864
    
cleanup
Yuki Kimoto authored on 2011-04-02
865
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
866
    push @sql, $append if $append;
867
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
868
    # Wrap
869
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
870
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
871
          unless ref $wrap eq 'ARRAY';
872
        unshift @sql, $wrap->[0];
873
        push @sql, $wrap->[1];
874
    }
875
    
cleanup
Yuki Kimoto authored on 2011-01-27
876
    # SQL
877
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
878
    
879
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
880
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
881
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
882
        param => $where_param, 
cleanup
Yuki Kimoto authored on 2011-03-21
883
        table => $tables,
884
        %args
885
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
886
    
887
    return $result;
888
}
889

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
890
sub separator {
891
    my $self = shift;
892
    
893
    if (@_) {
894
        my $separator = $_[0] || '';
895
        croak qq{Separator must be "." or "__" or "-" } . _subname
896
          unless $separator eq '.' || $separator eq '__'
897
              || $separator eq '-';
898
        
899
        $self->{separator} = $separator;
900
    
901
        return $self;
902
    }
903
    return $self->{separator} ||= '.';
904
}
905

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
906
sub setup_model {
907
    my $self = shift;
908
    
cleanup
Yuki Kimoto authored on 2011-04-02
909
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
910
    $self->each_column(
911
        sub {
912
            my ($self, $table, $column, $column_info) = @_;
913
            if (my $model = $self->models->{$table}) {
914
                push @{$model->columns}, $column;
915
            }
916
        }
917
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
918
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
919
}
920

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
921
sub available_data_type {
922
    my $self = shift;
923
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
924
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
925
    foreach my $i (-1000 .. 1000) {
926
         my $type_info = $self->dbh->type_info($i);
927
         my $data_type = $type_info->{DATA_TYPE};
928
         my $type_name = $type_info->{TYPE_NAME};
929
         $data_types .= "$data_type ($type_name)\n"
930
           if defined $data_type;
931
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
932
    return "Data Type maybe equal to Type Name" unless $data_types;
933
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
934
    return $data_types;
935
}
936

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
937
sub available_type_name {
938
    my $self = shift;
939
    
940
    # Type Names
941
    my $type_names = {};
942
    $self->each_column(sub {
943
        my ($self, $table, $column, $column_info) = @_;
944
        $type_names->{$column_info->{TYPE_NAME}} = 1
945
          if $column_info->{TYPE_NAME};
946
    });
947
    my @output = sort keys %$type_names;
948
    unshift @output, "Type Name";
949
    return join "\n", @output;
950
}
951

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
952
sub type_rule {
953
    my $self = shift;
954
    
955
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
956
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
957
        
958
        # Into
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
959
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
960
        $self->{type_rule} = $type_rule;
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
961
        $self->{_into} = {};
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
962
        foreach my $type_name (keys %{$type_rule->{into} || {}}) {
963
            croak qq{type name of into section must be lower case}
964
              if $type_name =~ /[A-Z]/;
965
        }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
966
        $self->each_column(sub {
967
            my ($dbi, $table, $column, $column_info) = @_;
968
            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
969
            my $type_name = lc $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
970
            if ($type_rule->{into} &&
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
971
                (my $filter = $type_rule->{into}->{$type_name}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
972
            {
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
973
                return unless exists $type_rule->{into}->{$type_name};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
974
                if  (defined $filter && ref $filter ne 'CODE') 
975
                {
976
                    my $fname = $filter;
977
                    croak qq{Filter "$fname" is not registered" } . _subname
978
                      unless exists $self->filters->{$fname};
979
                    
980
                    $filter = $self->filters->{$fname};
981
                }
982

            
983
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
984
            }
985
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
986
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
987

            
988
        # From
989
        $type_rule->{from} = _array_to_hash($type_rule->{from});
990
        foreach my $data_type (keys %{$type_rule->{from} || {}}) {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
991
            croak qq{data type of into section must be lower case or number}
992
              if $data_type =~ /[A-Z]/;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
993
            my $fname = $type_rule->{from}{$data_type};
994
            if (defined $fname && ref $fname ne 'CODE') {
995
                croak qq{Filter "$fname" is not registered" } . _subname
996
                  unless exists $self->filters->{$fname};
997
                
998
                $type_rule->{from}{$data_type} = $self->filters->{$fname};
999
            }
1000
        }
1001
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1002
        return $self;
1003
    }
1004
    
1005
    return $self->{type_rule} || {};
1006
}
1007

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1014
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1015
    my $param;
1016
    $param = shift if @_ % 2;
1017
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1018
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1019
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1020
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1021
    my $p = delete $args{param} || {};
1022
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1023
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1024
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1025
    my $append           = delete $args{append} || '';
1026
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1027
    my $id = delete $args{id};
1028
    my $primary_key = delete $args{primary_key};
1029
    croak "update method primary_key option " .
1030
          "must be specified when id is specified " . _subname
1031
      if defined $id && !defined $primary_key;
1032
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1033
    
cleanup
Yuki Kimoto authored on 2011-04-02
1034
    # Check argument names
1035
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1036
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1037
          unless $UPDATE_ARGS{$name};
1038
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1039

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

            
1043
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1044
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1045
    my $where_clause = '';
1046
    if (ref $where) {
1047
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1048
        $where_param = keys %$where_param
1049
                     ? $self->merge_param($where_param, $where->param)
1050
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1051
        
1052
        # String where
1053
        $where_clause = $where->to_string;
1054
    }
1055
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1056
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1057
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1058
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1059
    # Merge param
1060
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1061
    
cleanup
Yuki Kimoto authored on 2011-04-02
1062
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1063
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1064
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1065
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1066
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1067
    
cleanup
Yuki Kimoto authored on 2011-01-27
1068
    # SQL
1069
    my $sql = join(' ', @sql);
1070
    
cleanup
yuki-kimoto authored on 2010-10-17
1071
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1072
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1073
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1074
        param  => $param, 
1075
        table => $table,
1076
        %args
1077
    );
cleanup
yuki-kimoto authored on 2010-10-17
1078
    
1079
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1080
}
1081

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1084
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1085
    my ($self, $param, $opt) = @_;
1086
    
cleanup
Yuki Kimoto authored on 2011-04-02
1087
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1088
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1089
    $tag = "set $tag" unless $opt->{no_set};
1090

            
cleanup
Yuki Kimoto authored on 2011-04-02
1091
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1092
}
1093

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1106
sub _apply_filter {
1107
    my ($self, $table, @cinfos) = @_;
1108

            
1109
    # Initialize filters
1110
    $self->{filter} ||= {};
1111
    $self->{filter}{out} ||= {};
1112
    $self->{filter}{in} ||= {};
1113
    $self->{filter}{end} ||= {};
1114
    
1115
    # Usage
1116
    my $usage = "Usage: \$dbi->apply_filter(" .
1117
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1118
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1119
    
1120
    # Apply filter
1121
    for (my $i = 0; $i < @cinfos; $i += 2) {
1122
        
1123
        # Column
1124
        my $column = $cinfos[$i];
1125
        if (ref $column eq 'ARRAY') {
1126
            foreach my $c (@$column) {
1127
                push @cinfos, $c, $cinfos[$i + 1];
1128
            }
1129
            next;
1130
        }
1131
        
1132
        # Filter infomation
1133
        my $finfo = $cinfos[$i + 1] || {};
1134
        croak "$usage (table: $table) " . _subname
1135
          unless  ref $finfo eq 'HASH';
1136
        foreach my $ftype (keys %$finfo) {
1137
            croak "$usage (table: $table) " . _subname
1138
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1139
        }
1140
        
1141
        # Set filters
1142
        foreach my $way (qw/in out end/) {
1143
        
1144
            # Filter
1145
            my $filter = $finfo->{$way};
1146
            
1147
            # Filter state
1148
            my $state = !exists $finfo->{$way} ? 'not_exists'
1149
                      : !defined $filter        ? 'not_defined'
1150
                      : ref $filter eq 'CODE'   ? 'code'
1151
                      : 'name';
1152
            
1153
            # Filter is not exists
1154
            next if $state eq 'not_exists';
1155
            
1156
            # Check filter name
1157
            croak qq{Filter "$filter" is not registered } . _subname
1158
              if  $state eq 'name'
1159
               && ! exists $self->filters->{$filter};
1160
            
1161
            # Set filter
1162
            my $f = $state eq 'not_defined' ? undef
1163
                  : $state eq 'code'        ? $filter
1164
                  : $self->filters->{$filter};
1165
            $self->{filter}{$way}{$table}{$column} = $f;
1166
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1167
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1168
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1169
        }
1170
    }
1171
    
1172
    return $self;
1173
}
1174

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1419
# DEPRECATED!
1420
sub apply_filter {
1421
    my $self = shift;
1422
    
1423
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1424
         "use type_rule method and DBIx::Custom::Result filter method, " .
1425
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1426
    
1427
    return $self->_apply_filter(@_);
1428
}
1429

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1430
# DEPRECATED!
1431
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1432
sub select_at {
1433
    my ($self, %args) = @_;
1434

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1437
    # Arguments
1438
    my $primary_keys = delete $args{primary_key};
1439
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1440
    my $where = delete $args{where};
1441
    my $param = delete $args{param};
1442
    
1443
    # Check arguments
1444
    foreach my $name (keys %args) {
1445
        croak qq{"$name" is wrong option } . _subname
1446
          unless $SELECT_AT_ARGS{$name};
1447
    }
1448
    
1449
    # Table
1450
    croak qq{"table" option must be specified } . _subname
1451
      unless $args{table};
1452
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1453
    
1454
    # Create where parameter
1455
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1456
    
1457
    return $self->select(where => $where_param, %args);
1458
}
1459

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1460
# DEPRECATED!
1461
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1462
sub delete_at {
1463
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1464

            
1465
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1466
    
1467
    # Arguments
1468
    my $primary_keys = delete $args{primary_key};
1469
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1470
    my $where = delete $args{where};
1471
    
1472
    # Check arguments
1473
    foreach my $name (keys %args) {
1474
        croak qq{"$name" is wrong option } . _subname
1475
          unless $DELETE_AT_ARGS{$name};
1476
    }
1477
    
1478
    # Create where parameter
1479
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1480
    
1481
    return $self->delete(where => $where_param, %args);
1482
}
1483

            
cleanup
Yuki Kimoto authored on 2011-06-08
1484
# DEPRECATED!
1485
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1486
sub update_at {
1487
    my $self = shift;
1488

            
1489
    warn "update_at is DEPRECATED! use update and id option instead";
1490
    
1491
    # Arguments
1492
    my $param;
1493
    $param = shift if @_ % 2;
1494
    my %args = @_;
1495
    my $primary_keys = delete $args{primary_key};
1496
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1497
    my $where = delete $args{where};
1498
    my $p = delete $args{param} || {};
1499
    $param  ||= $p;
1500
    
1501
    # Check arguments
1502
    foreach my $name (keys %args) {
1503
        croak qq{"$name" is wrong option } . _subname
1504
          unless $UPDATE_AT_ARGS{$name};
1505
    }
1506
    
1507
    # Create where parameter
1508
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1509
    
1510
    return $self->update(where => $where_param, param => $param, %args);
1511
}
1512

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1513
# DEPRECATED!
1514
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1515
sub insert_at {
1516
    my $self = shift;
1517
    
1518
    warn "insert_at is DEPRECATED! use insert and id option instead";
1519
    
1520
    # Arguments
1521
    my $param;
1522
    $param = shift if @_ % 2;
1523
    my %args = @_;
1524
    my $primary_key = delete $args{primary_key};
1525
    $primary_key = [$primary_key] unless ref $primary_key;
1526
    my $where = delete $args{where};
1527
    my $p = delete $args{param} || {};
1528
    $param  ||= $p;
1529
    
1530
    # Check arguments
1531
    foreach my $name (keys %args) {
1532
        croak qq{"$name" is wrong option } . _subname
1533
          unless $INSERT_AT_ARGS{$name};
1534
    }
1535
    
1536
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1537
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1538
    $param = $self->merge_param($where_param, $param);
1539
    
1540
    return $self->insert(param => $param, %args);
1541
}
1542

            
added warnings
Yuki Kimoto authored on 2011-06-07
1543
# DEPRECATED!
1544
sub register_tag {
1545
    warn "register_tag is DEPRECATED!";
1546
    shift->query_builder->register_tag(@_)
1547
}
1548

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1549
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1550
has 'data_source';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1551

            
cleanup
Yuki Kimoto authored on 2011-01-25
1552
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1553
has dbi_options => sub { {} },
1554
    filter_check  => 1;
1555

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1556

            
cleanup
Yuki Kimoto authored on 2011-01-25
1557
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1558
sub default_bind_filter {
1559
    my $self = shift;
1560
    
cleanup
Yuki Kimoto authored on 2011-06-13
1561
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1562
    
cleanup
Yuki Kimoto authored on 2011-01-12
1563
    if (@_) {
1564
        my $fname = $_[0];
1565
        
1566
        if (@_ && !$fname) {
1567
            $self->{default_out_filter} = undef;
1568
        }
1569
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1570
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1571
              unless exists $self->filters->{$fname};
1572
        
1573
            $self->{default_out_filter} = $self->filters->{$fname};
1574
        }
1575
        return $self;
1576
    }
1577
    
1578
    return $self->{default_out_filter};
1579
}
1580

            
cleanup
Yuki Kimoto authored on 2011-01-25
1581
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1582
sub default_fetch_filter {
1583
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1584

            
cleanup
Yuki Kimoto authored on 2011-06-13
1585
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1586
    
1587
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1588
        my $fname = $_[0];
1589

            
cleanup
Yuki Kimoto authored on 2011-01-12
1590
        if (@_ && !$fname) {
1591
            $self->{default_in_filter} = undef;
1592
        }
1593
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1594
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1595
              unless exists $self->filters->{$fname};
1596
        
1597
            $self->{default_in_filter} = $self->filters->{$fname};
1598
        }
1599
        
1600
        return $self;
1601
    }
1602
    
many changed
Yuki Kimoto authored on 2011-01-23
1603
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1604
}
1605

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1606
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1607
sub insert_param_tag {
1608
    warn "insert_param_tag is DEPRECATED! " .
1609
         "use insert_param instead!";
1610
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1611
}
1612

            
cleanup
Yuki Kimoto authored on 2011-01-25
1613
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1614
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1615
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1616
    return shift->query_builder->register_tag_processor(@_);
1617
}
1618

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1619
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1620
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1621
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1622
         "use update_param instead";
1623
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1624
}
cleanup
Yuki Kimoto authored on 2011-03-08
1625
# DEPRECATED!
1626
sub _push_relation {
1627
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1628
    
1629
    if (keys %{$relation || {}}) {
1630
        push @$sql, $need_where ? 'where' : 'and';
1631
        foreach my $rcolumn (keys %$relation) {
1632
            my $table1 = (split (/\./, $rcolumn))[0];
1633
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1634
            push @$tables, ($table1, $table2);
1635
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1636
        }
1637
    }
1638
    pop @$sql if $sql->[-1] eq 'and';    
1639
}
1640

            
1641
# DEPRECATED!
1642
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1643
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1644
    
1645
    if (keys %{$relation || {}}) {
1646
        foreach my $rcolumn (keys %$relation) {
1647
            my $table1 = (split (/\./, $rcolumn))[0];
1648
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1649
            my $table1_exists;
1650
            my $table2_exists;
1651
            foreach my $table (@$tables) {
1652
                $table1_exists = 1 if $table eq $table1;
1653
                $table2_exists = 1 if $table eq $table2;
1654
            }
1655
            unshift @$tables, $table1 unless $table1_exists;
1656
            unshift @$tables, $table2 unless $table2_exists;
1657
        }
1658
    }
1659
}
1660

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1663
=head1 NAME
1664

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

            
1667
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1668

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1669
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1670
    
1671
    # Connect
1672
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1673
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1674
        user => 'ken',
1675
        password => '!LFKD%$&',
1676
        dbi_option => {mysql_enable_utf8 => 1}
1677
    );
cleanup
yuki-kimoto authored on 2010-08-05
1678

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1679
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1680
    $dbi->insert(
1681
        table  => 'book',
1682
        param  => {title => 'Perl', author => 'Ken'}
1683
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1684
    
1685
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1686
    $dbi->update(
1687
        table  => 'book', 
1688
        param  => {title => 'Perl', author => 'Ken'}, 
1689
        where  => {id => 5},
1690
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1691
    
1692
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1693
    $dbi->delete(
1694
        table  => 'book',
1695
        where  => {author => 'Ken'},
1696
    );
cleanup
yuki-kimoto authored on 2010-08-05
1697

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1698
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1699
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1700
        table  => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
1701
        column => ['title', 'author'],
update document
yuki-kimoto authored on 2010-05-27
1702
        where  => {author => 'Ken'},
added commit method
yuki-kimoto authored on 2010-05-27
1703
    );
cleanup
yuki-kimoto authored on 2010-08-05
1704

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1705
    # Select, more complex
1706
    my $result = $dbi->select(
1707
        table  => 'book',
1708
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1709
            {book => [qw/title author/]},
1710
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1711
        ],
1712
        where  => {'book.author' => 'Ken'},
1713
        join => ['left outer join company on book.company_id = company.id'],
1714
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1715
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1716
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1717
    # Fetch
1718
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1719
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1720
    }
1721
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1722
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1723
    while (my $row = $result->fetch_hash) {
1724
        
1725
    }
1726
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1727
    # Execute SQL with parameter.
1728
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1729
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1730
        param  => {author => 'ken', title => '%Perl%'}
1731
    );
1732
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1733
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1734

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

            
1737
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1738

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1748
=item *
1749

            
1750
Filter when data is send or receive.
1751

            
1752
=item *
1753

            
1754
Data filtering system
1755

            
1756
=item *
1757

            
1758
Model support.
1759

            
1760
=item *
1761

            
1762
Generate where clause dinamically.
1763

            
1764
=item *
1765

            
1766
Generate join clause dinamically.
1767

            
1768
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1769

            
1770
=head1 GUIDE
1771

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

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

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

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

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

            
1782
    my $connector = $dbi->connector;
1783
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1784

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

            
1788
This is L<DBIx::Connector> example. Please pass
1789
C<default_dbi_option> to L<DBIx::Connector>.
1790

            
1791
    my $connector = DBIx::Connector->new(
1792
        "dbi:mysql:database=$DATABASE",
1793
        $USER,
1794
        $PASSWORD,
1795
        DBIx::Custom->new->default_dbi_option
1796
    );
1797
    
1798
    my $dbi = DBIx::Custom->new(connector => $connector);
1799

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

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

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

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

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

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

            
1815
=head2 C<default_dbi_option>
1816

            
1817
    my $default_dbi_option = $dbi->default_dbi_option;
1818
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1819

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1823
    {
1824
        RaiseError => 1,
1825
        PrintError => 0,
1826
        AutoCommit => 1,
1827
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1828

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

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

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

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

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

            
1841
    my $models = $dbi->models;
1842
    $dbi       = $dbi->models(\%models);
1843

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1846
=head2 C<password>
1847

            
1848
    my $password = $dbi->password;
1849
    $dbi         = $dbi->password('lkj&le`@s');
1850

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

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

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

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

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

            
1862
     my reserved_word_quote = $dbi->reserved_word_quote;
1863
     $dbi                   = $dbi->reserved_word_quote('"');
1864

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1884
    my $user = $dbi->user;
1885
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1886

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

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

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

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

            
1897
    print $dbi->available_data_type;
1898

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
1899
Get available data types. You can use these data types
1900
in C<type rule>'s C<from> section.
1901

            
1902
=head2 C<available_type_name> EXPERIMENTAL
1903

            
1904
    print $dbi->available_type_name;
1905

            
1906
Get available type names. You can use these type names in
1907
C<type_rule>'s C<into> section.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1908

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1919
=head2 C<column> EXPERIMETNAL
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1920

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

            
1923
Create column clause. The follwoing column clause is created.
1924

            
1925
    book.author as "book.author",
1926
    book.title as "book.title"
1927

            
cleanup
Yuki Kimoto authored on 2011-06-13
1928
You can change separator by C<separator> method.
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1929

            
cleanup
Yuki Kimoto authored on 2011-06-13
1930
    # Separator is double underbar
1931
    $dbi->separator('__');
1932
    
1933
    book.author as "book__author",
1934
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1935

            
cleanup
Yuki Kimoto authored on 2011-06-13
1936
    # Separator is hyphen
1937
    $dbi->separator('-');
1938
    
1939
    book.author as "book-author",
1940
    book.title as "book-title"
1941
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1942
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1943

            
update pod
Yuki Kimoto authored on 2011-03-13
1944
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1945
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1946
        user => 'ken',
1947
        password => '!LFKD%$&',
1948
        dbi_option => {mysql_enable_utf8 => 1}
1949
    );
1950

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
1959
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1960
        table => 'book',
1961
        primary_key => 'id',
1962
        join => [
1963
            'inner join company on book.comparny_id = company.id'
1964
        ],
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1965
        filter => {
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1966
            publish_date => {
1967
                out => 'tp_to_date',
1968
                in => 'date_to_tp',
1969
                end => 'tp_to_displaydate'
1970
            }
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
1971
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
1972
    );
1973

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

            
1977
   $dbi->model('book')->select(...);
1978

            
cleanup
yuki-kimoto authored on 2010-10-17
1979
=head2 C<create_query>
1980
    
1981
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
1982
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
1983
    );
update document
yuki-kimoto authored on 2009-11-19
1984

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

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

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

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

            
1995
    my $dbh = $dbi->dbh;
1996

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

            
2000
=head2 C<each_column>
2001

            
2002
    $dbi->each_column(
2003
        sub {
2004
            my ($dbi, $table, $column, $column_info) = @_;
2005
            
2006
            my $type = $column_info->{TYPE_NAME};
2007
            
2008
            if ($type eq 'DATE') {
2009
                # ...
2010
            }
2011
        }
2012
    );
2013

            
2014
Iterate all column informations of all table from database.
2015
Argument is callback when one column is found.
2016
Callback receive four arguments, dbi object, table name,
2017
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2018

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

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

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

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

            
2032
    select * from where title = ? and author like ?;
2033

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

            
2036
=over 4
2037

            
2038
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2039
    
2040
    filter => {
2041
        title  => sub { uc $_[0] }
2042
        author => sub { uc $_[0] }
2043
    }
update pod
Yuki Kimoto authored on 2011-03-13
2044

            
updated pod
Yuki Kimoto authored on 2011-06-09
2045
    # Filter name
2046
    filter => {
2047
        title  => 'upper_case',
2048
        author => 'upper_case'
2049
    }
2050
        
2051
    # At once
2052
    filter => [
2053
        [qw/title author/]  => sub { uc $_[0] }
2054
    ]
2055

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2056
Filter. You can set subroutine or filter name
2057
registered by by C<register_filter()>.
2058
This filter is executed before data is saved into database.
2059
and before type rule filter is executed.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2060

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

            
2063
    query => 1
2064

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2067
=item C<table>
2068
    
2069
    table => 'author'
2070
    table => ['author', 'book']
2071

            
2072
Table names for filtering.
2073

            
2074
Filtering by C<apply_filter> is off in C<execute> method,
2075
because we don't know what filter is applied.
2076

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

            
2079
Specify database data type.
2080

            
2081
    type => [image => DBI::SQL_BLOB]
2082
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2083

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

            
2086
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2087

            
2088
C<type> option is also available
2089
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2090

            
2091
=item C<type_rule_off> EXPERIMENTAL
2092

            
2093
    type_rule_off => 1
2094

            
2095
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2096

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2107
=over 4
2108

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

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

            
2113
=item C<filter>
2114

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2119
    id => 4
2120
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2121

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2125
    $dbi->delete(
2126
        parimary_key => ['id1', 'id2'],
2127
        id => [4, 5],
2128
        table => 'book',
2129
    );
update pod
Yuki Kimoto authored on 2011-03-13
2130

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

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

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

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

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

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

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

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

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

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

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

            
2153
Same as C<execute> method's C<type> option.
2154

            
2155
=item C<type_rule_off> EXPERIMENTAL
2156

            
2157
Same as C<execute> method's C<type_rule_off> option.
2158

            
updated pod
Yuki Kimoto authored on 2011-06-08
2159
=back
update pod
Yuki Kimoto authored on 2011-03-13
2160

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

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

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

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

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

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

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

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

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

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

            
2182
=item C<filter>
2183

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

            
2186
=item C<id>
2187

            
updated document
Yuki Kimoto authored on 2011-06-09
2188
    id => 4
2189
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2190

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2194
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2195
        {title => 'Perl', author => 'Ken'}
2196
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2197
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2198
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2199
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2200

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

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

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

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

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

            
2215
=item C<param>
2216

            
2217
    param => {title => 'Perl', author => 'Ken'}
2218

            
2219
Insert data.
2220

            
2221
If C<insert> method's arguments is odd numbers,
2222
first argument is received as C<param>.
2223

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

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

            
2228
Same as C<execute> method's C<query> option.
2229

            
2230
=item C<table>
2231

            
2232
    table => 'book'
2233

            
2234
Table name.
2235

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2244
=back
2245

            
2246
=over 4
2247

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2263
    lib / MyModel.pm
2264
        / MyModel / book.pm
2265
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2266

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

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

            
2271
    package MyModel;
2272
    
2273
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2274
    
2275
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2276

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2281
    package MyModel::book;
2282
    
2283
    use base 'MyModel';
2284
    
2285
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2286

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2289
    package MyModel::company;
2290
    
2291
    use base 'MyModel';
2292
    
2293
    1;
2294
    
2295
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2296

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

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

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

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

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

            
2308
Merge paramters.
2309

            
2310
$param:
2311

            
2312
    {key1 => [1, 1], key2 => 2}
2313

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

            
2316
    $dbi->method(
2317
        update_or_insert => sub {
2318
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2319
            
2320
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2321
        },
2322
        find_or_create   => sub {
2323
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2324
            
2325
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2326
        }
2327
    );
2328

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

            
2331
    $dbi->update_or_insert;
2332
    $dbi->find_or_create;
2333

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

            
2336
    $dbi->model('book')->method(
2337
        insert => sub { ... },
2338
        update => sub { ... }
2339
    );
2340
    
2341
    my $model = $dbi->model('book');
2342

            
2343
Set and get a L<DBIx::Custom::Model> object,
2344

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

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

            
2349
Create column clause for myself. The follwoing column clause is created.
2350

            
2351
    book.author as author,
2352
    book.title as title
2353

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2356
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2357
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2358
        user => 'ken',
2359
        password => '!LFKD%$&',
2360
        dbi_option => {mysql_enable_utf8 => 1}
2361
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2362

            
2363
Create a new L<DBIx::Custom> object.
2364

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

            
2367
    my $not_exists = $dbi->not_exists;
2368

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2372
=head2 C<register_filter>
2373

            
update pod
Yuki Kimoto authored on 2011-03-13
2374
    $dbi->register_filter(
2375
        # Time::Piece object to database DATE format
2376
        tp_to_date => sub {
2377
            my $tp = shift;
2378
            return $tp->strftime('%Y-%m-%d');
2379
        },
2380
        # database DATE format to Time::Piece object
2381
        date_to_tp => sub {
2382
           my $date = shift;
2383
           return Time::Piece->strptime($date, '%Y-%m-%d');
2384
        }
2385
    );
cleanup
yuki-kimoto authored on 2010-10-17
2386
    
update pod
Yuki Kimoto authored on 2011-03-13
2387
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2388

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

            
2391
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2392
        into => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2393
            date => sub { ... },
2394
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2395
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2396
        from => {
2397
            # DATE
2398
            9 => sub { ... },
2399
            
2400
            # DATETIME or TIMESTAMP
2401
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2402
        }
2403
    );
2404

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

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2408
In C<into> you can specify type name as same as type name defined
2409
by create table, such as C<DATETIME> or C<DATE>.
cleanup
Yuki Kimoto authored on 2011-06-13
2410
Type rule of C<into> is enabled on the following pattern.
2411

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2412
Note that type name and data type don't contain upper case.
2413
If that contain upper case charactor, you specify it lower case.
2414

            
cleanup
Yuki Kimoto authored on 2011-06-13
2415
=over 4
2416

            
2417
=item 1. column name
2418

            
2419
    issue_date
2420
    issue_datetime
2421

            
2422
=item 2. table name and column name, separator is dot
2423

            
2424
    book.issue_date
2425
    book.issue_datetime
2426

            
2427
=back
2428

            
update pod
Yuki Kimoto authored on 2011-06-15
2429
You get all type name used in database by C<available_type_name>.
2430

            
2431
    print $dbi->available_type_name;
2432

            
cleanup
Yuki Kimoto authored on 2011-06-13
2433
In C<from> you can't specify type name defined by create table.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2434
You must specify data type, this is internal one.
2435
You get all data type by C<available_data_type>.
2436

            
2437
    print $dbi->available_data_type;
2438

            
cleanup
Yuki Kimoto authored on 2011-06-13
2439
Type rule of C<from> is enabled on the following pattern.
2440

            
2441
=item 4. table name and column name, separator is hyphen
2442

            
2443
    book-issue_date
2444
    book-issue_datetime
2445

            
2446
This is useful in HTML.
2447

            
2448
=back
2449

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2450
You can also specify multiple types
2451

            
2452
    $dbi->type_rule(
2453
        into => [
2454
            [qw/DATE DATETIME/] => sub { ... },
2455
        ],
2456
        from => {
2457
            # DATE
2458
            [qw/9 11/] => sub { ... },
2459
        }
2460
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2461

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2464
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2465
        table  => 'book',
2466
        column => ['author', 'title'],
2467
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2468
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2469
    
updated document
Yuki Kimoto authored on 2011-06-09
2470
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2471

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

            
2474
=over 4
2475

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2480
Append statement to last of SQL.
2481
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2482
=item C<column>
2483
    
updated document
Yuki Kimoto authored on 2011-06-09
2484
    column => 'author'
2485
    column => ['author', 'title']
2486

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2495
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2496
        {book => [qw/author title/]},
2497
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2498
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2499

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

            
2502
    book.author as "book.author",
2503
    book.title as "book.title",
2504
    person.name as "person.name",
2505
    person.age as "person.age"
2506

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2509
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2510
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2511
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2512

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

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

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

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

            
2521
=item C<id>
2522

            
2523
    id => 4
2524
    id => [4, 5]
2525

            
2526
ID corresponding to C<primary_key>.
2527
You can select rows by C<id> and C<primary_key>.
2528

            
2529
    $dbi->select(
2530
        parimary_key => ['id1', 'id2'],
2531
        id => [4, 5],
2532
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2533
    );
2534

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2537
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2538
        where => {id1 => 4, id2 => 5},
2539
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2540
    );
2541
    
updated document
Yuki Kimoto authored on 2011-06-09
2542
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2543

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

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

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

            
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
2554
=itme C<prefix> EXPERIMENTAL
2555

            
2556
    prefix => 'SQL_CALC_FOUND_ROWS'
2557

            
2558
Prefix of column cluase
2559

            
2560
    select SQL_CALC_FOUND_ROWS title, author from book;
2561

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

            
2564
    join => [
2565
        'left outer join company on book.company_id = company_id',
2566
        'left outer join location on company.location_id = location.id'
2567
    ]
2568
        
2569
Join clause. If column cluase or where clause contain table name like "company.name",
2570
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2571

            
2572
    $dbi->select(
2573
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2574
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2575
        where => {'company.name' => 'Orange'},
2576
        join => [
2577
            'left outer join company on book.company_id = company.id',
2578
            'left outer join location on company.location_id = location.id'
2579
        ]
2580
    );
2581

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2585
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2586
    from book
2587
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2588
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2589

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2609
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2610

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2615
=item C<where>
2616
    
2617
    # Hash refrence
2618
    where => {author => 'Ken', 'title' => 'Perl'}
2619
    
2620
    # DBIx::Custom::Where object
2621
    where => $dbi->where(
2622
        clause => ['and', 'author = :author', 'title like :title'],
2623
        param  => {author => 'Ken', title => '%Perl%'}
2624
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2625

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2630
Where clause.
2631
    
improved pod
Yuki Kimoto authored on 2011-04-19
2632
=item C<wrap> EXPERIMENTAL
2633

            
2634
Wrap statement. This is array reference.
2635

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

            
2638
This option is for Oracle and SQL Server paging process.
2639

            
update pod
Yuki Kimoto authored on 2011-03-12
2640
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2641

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2650
=over 4
2651

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2662
    id => 4
2663
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2664

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2668
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2669
        {title => 'Perl', author => 'Ken'}
2670
        parimary_key => ['id1', 'id2'],
2671
        id => [4, 5],
2672
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2673
    );
update pod
Yuki Kimoto authored on 2011-03-13
2674

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2677
    $dbi->update(
2678
        {title => 'Perl', author => 'Ken'}
2679
        where => {id1 => 4, id2 => 5},
2680
        table => 'book'
2681
    );
update pod
Yuki Kimoto authored on 2011-03-13
2682

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2716
Same as C<execute> method's C<type> option.
2717

            
2718
=item C<type_rule_off> EXPERIMENTAL
2719

            
update pod
Yuki Kimoto authored on 2011-06-15
2720
Same as C<execute> method's <type_rule_off>.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2721

            
updated pod
Yuki Kimoto authored on 2011-06-08
2722
=back
update pod
Yuki Kimoto authored on 2011-03-13
2723

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

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

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

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

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

            
2735
Create update parameter tag.
2736

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

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

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

            
2746
Create a new L<DBIx::Custom::Where> object.
2747

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2755
=head1 Parameter
2756

            
2757
Parameter start at ':'. This is replaced to place holoder
2758

            
2759
    $dbi->execute(
2760
        "select * from book where title = :title and author = :author"
2761
        param => {title => 'Perl', author => 'Ken'}
2762
    );
2763

            
2764
    "select * from book where title = ? and author = ?"
2765

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

            
2768
=head2 C<DBIX_CUSTOM_DEBUG>
2769

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

            
2773
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
2774

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

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

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

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

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

            
2786
C<< <kimoto.yuki at gmail.com> >>
2787

            
2788
L<http://github.com/yuki-kimoto/DBIx-Custom>
2789

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
2790
=head1 AUTHOR
2791

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

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

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

            
2798
This program is free software; you can redistribute it and/or modify it
2799
under the same terms as Perl itself.
2800

            
2801
=cut