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

            
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
3
our $VERSION = '0.1691';
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 {
102
    my ($self, $table, $columns) = @_;
added helper method
yuki-kimoto authored on 2010-10-17
103
    
cleanup
Yuki Kimoto authored on 2011-04-02
104
    # Reserved word quote
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
105
    my $q = $self->reserved_word_quote;
106
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
107
    # Separator
108
    my $separator = $self->separator;
109
    
cleanup
Yuki Kimoto authored on 2011-04-02
110
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
111
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
112
    $columns ||= [];
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
113
    push @column, "$q$table$q.$q$_$q as $q${table}${separator}$_$q"
114
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
115
    
116
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
117
}
118

            
packaging one directory
yuki-kimoto authored on 2009-11-16
119
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
120
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
121
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
122
    # Connect
123
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
124
    
packaging one directory
yuki-kimoto authored on 2009-11-16
125
    return $self;
126
}
127

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

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

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

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

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

            
221
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
222
    }
223
}
224

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
268
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
269
    my @sql;
cleanup
Yuki Kimoto authored on 2011-04-02
270
    my $q = $self->reserved_word_quote;
271
    push @sql, "delete from $q$table$q $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
272
    push @sql, $append if $append;
273
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
274
    
275
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
276
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
277
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
278
        param => $where_param,
cleanup
Yuki Kimoto authored on 2011-03-21
279
        table => $table,
280
        %args
281
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
282
}
283

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

            
added helper method
yuki-kimoto authored on 2010-10-17
286
sub DESTROY { }
287

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
288
sub create_model {
289
    my $self = shift;
290
    
cleanup
Yuki Kimoto authored on 2011-04-02
291
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
292
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
293
    $args->{dbi} = $self;
294
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
295
    my $model_name  = delete $args->{name};
296
    my $model_table = delete $args->{table};
297
    $model_name ||= $model_table;
298
    
cleanup
Yuki Kimoto authored on 2011-04-02
299
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
300
    my $model = $model_class->new($args);
301
    $model->name($model_name) unless $model->name;
302
    $model->table($model_table) unless $model->table;
303
    
304
    # Apply filter
DBIx::Custom::Model filter a...
Yuki Kimoto authored on 2011-04-18
305
    my $filter = ref $model->filter eq 'HASH'
306
               ? [%{$model->filter}]
307
               : $model->filter;
cleanup
Yuki Kimoto authored on 2011-06-13
308
    $self->_apply_filter($model->table, @$filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
309
    
cleanup
Yuki Kimoto authored on 2011-04-02
310
    # Associate table with model
cleanup
Yuki Kimoto authored on 2011-04-25
311
    croak "Table name is duplicated " . _subname
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
312
      if exists $self->{_model_from}->{$model->table};
313
    $self->{_model_from}->{$model->table} = $model->name;
314

            
315
    # Table alias
316
    $self->{_table_alias} ||= {};
317
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
318
    
319
    # Set model
320
    $self->model($model->name, $model);
321
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
322
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
323
}
324

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

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

            
346
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
347
    my $self = shift;
348
    my $query = shift;
349
    my $param;
350
    $param = shift if @_ % 2;
351
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
352
    
cleanup
Yuki Kimoto authored on 2011-04-02
353
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
354
    my $p = delete $args{param} || {};
355
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
356
    my $tables = delete $args{table} || [];
357
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
358
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
359
    $filter = _array_to_hash($filter);
cleanup
Yuki Kimoto authored on 2011-04-02
360
    my $type = delete $args{type};
cleanup
Yuki Kimoto authored on 2011-04-25
361
    $type = _array_to_hash($type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
362
    my $type_rule_off = delete $args{type_rule_off};
cleanup
Yuki Kimoto authored on 2011-06-09
363
    my $query_return = delete $args{query};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
364
    
cleanup
Yuki Kimoto authored on 2011-03-09
365
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
366
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
367
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-03-21
368
          unless $EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
369
    }
370
    
cleanup
Yuki Kimoto authored on 2011-04-02
371
    # Create query
372
    $query = $self->create_query($query) unless ref $query;
cleanup
Yuki Kimoto authored on 2011-06-09
373
    return $query if $query_return;
cleanup
Yuki Kimoto authored on 2011-04-02
374
    $filter ||= $query->filter;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
375
    
cleanup
Yuki Kimoto authored on 2011-04-02
376
    # Tables
377
    unshift @$tables, @{$query->tables};
cleanup
Yuki Kimoto authored on 2011-03-09
378
    my $main_table = pop @$tables;
cleanup
Yuki Kimoto authored on 2011-04-02
379
    $tables = $self->_remove_duplicate_table($tables, $main_table);
380
    if (my $q = $self->reserved_word_quote) {
381
        $_ =~ s/$q//g for @$tables;
382
    }
cleanup
Yuki Kimoto authored on 2011-04-02
383
    
384
    # Table alias
cleanup
Yuki Kimoto authored on 2011-04-02
385
    foreach my $table (@$tables) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
386
        
cleanup
Yuki Kimoto authored on 2011-04-02
387
        # No need
388
        next unless my $alias = $self->{_table_alias}->{$table};
389
        $self->{filter} ||= {};
390
        next if $self->{filter}{out}{$table};
391
        
392
        # Filter
393
        $self->{filter}{out} ||= {};
394
        $self->{filter}{in}  ||= {};
395
        $self->{filter}{end} ||= {};
396
        
397
        # Create alias filter
398
        foreach my $type (qw/out in end/) {
399
            my @filter_names = keys %{$self->{filter}{$type}{$alias} || {}};
400
            foreach my $filter_name (@filter_names) {
401
                my $filter_name_alias = $filter_name;
402
                $filter_name_alias =~ s/^$alias\./$table\./;
403
                $filter_name_alias =~ s/^${alias}__/${table}__/; 
cleanup
Yuki Kimoto authored on 2011-06-13
404
                $filter_name_alias =~ s/^${alias}-/${table}-/; 
cleanup
Yuki Kimoto authored on 2011-04-02
405
                $self->{filter}{$type}{$table}{$filter_name_alias}
406
                  = $self->{filter}{$type}{$alias}{$filter_name}
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
407
            }
408
        }
409
    }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
410

            
411
    # Type rule
412
    my $applied_filter = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
413
    unless ($type_rule_off) {
414
        foreach my $name (keys %$param) {
415
            my $table;
416
            my $column;
417
            if ($name =~ /(?:(.+)\.)?(.+)/) {
418
                $table = $1;
419
                $column = $2;
420
            }
421
            $table ||= $main_table;
422
            
423
            my $into = $self->{_into} || {};
424
            if (defined $table && $into->{$table} &&
425
                (my $rule = $into->{$table}->{$column}))
426
            {
427
                $applied_filter->{$column} = $rule;
428
                $applied_filter->{"$table.$column"} = $rule;
429
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
430
        }
431
    }
cleanup
Yuki Kimoto authored on 2011-04-02
432
    
433
    # Applied filter
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
434
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
435
        $applied_filter = {
436
            %$applied_filter,
cleanup
Yuki Kimoto authored on 2011-01-12
437
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
438
        }
439
    }
cleanup
Yuki Kimoto authored on 2011-04-02
440
    $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
441
    
cleanup
Yuki Kimoto authored on 2011-04-02
442
    # Replace filter name to code
443
    foreach my $column (keys %$filter) {
444
        my $name = $filter->{$column};
445
        if (!defined $name) {
446
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
447
        }
cleanup
Yuki Kimoto authored on 2011-04-02
448
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
449
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
450
            unless exists $self->filters->{$name};
451
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
452
        }
453
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
454
    
cleanup
Yuki Kimoto authored on 2011-04-02
455
    # Create bind values
456
    my $bind = $self->_create_bind_values(
457
        $param,
458
        $query->columns,
459
        $filter,
460
        $type
461
    );
cleanup
yuki-kimoto authored on 2010-10-17
462
    
463
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
464
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
465
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
466
    eval {
467
        for (my $i = 0; $i < @$bind; $i++) {
cleanup
Yuki Kimoto authored on 2011-04-02
468
            my $type = $bind->[$i]->{type};
469
            $sth->bind_param($i + 1, $bind->[$i]->{value}, $type ? $type : ());
cleanup
Yuki Kimoto authored on 2011-03-21
470
        }
471
        $affected = $sth->execute;
472
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
473
    
474
    if ($@) {
475
        $self->_croak($@, qq{. Following SQL is executed.\n}
cleanup
Yuki Kimoto authored on 2011-04-25
476
                        . qq{$query->{sql}\n} . _subname);
improved error messages
Yuki Kimoto authored on 2011-04-18
477
    }
cleanup
yuki-kimoto authored on 2010-10-17
478
    
improved debug message
Yuki Kimoto authored on 2011-05-23
479
    # DEBUG message
480
    if (DEBUG) {
481
        print STDERR "SQL:\n" . $query->sql . "\n";
482
        my @output;
483
        foreach my $b (@$bind) {
484
            my $value = $b->{value};
485
            $value = 'undef' unless defined $value;
486
            $value = encode(DEBUG_ENCODING(), $value)
487
              if utf8::is_utf8($value);
488
            push @output, $value;
489
        }
490
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
491
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
492
    
cleanup
Yuki Kimoto authored on 2011-04-02
493
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
494
    if ($sth->{NUM_OF_FIELDS}) {
495
        
cleanup
Yuki Kimoto authored on 2011-04-02
496
        # Filter
497
        my $filter = {};
498
        $filter->{in}  = {};
499
        $filter->{end} = {};
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
500
        push @$tables, $main_table if $main_table;
cleanup
Yuki Kimoto authored on 2011-01-12
501
        foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-04-02
502
            foreach my $way (qw/in end/) {
503
                $filter->{$way} = {
504
                    %{$filter->{$way}},
505
                    %{$self->{filter}{$way}{$table} || {}}
506
                };
507
            }
cleanup
Yuki Kimoto authored on 2011-01-12
508
        }
509
        
510
        # Result
511
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
512
            sth => $sth,
513
            filters => $self->filters,
cleanup
Yuki Kimoto authored on 2011-01-12
514
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
515
            filter => $filter->{in} || {},
516
            end_filter => $filter->{end} || {},
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
517
            type_rule => \%{$self->type_rule->{from}},
cleanup
yuki-kimoto authored on 2010-10-17
518
        );
519

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
529
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
530
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
531
    
cleanup
yuki-kimoto authored on 2010-10-17
532
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
533
    my $param;
534
    $param = shift if @_ % 2;
535
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
536
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
537
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
538
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
539
    my $p = delete $args{param} || {};
540
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
541
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
542
    my $id = delete $args{id};
543
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
544
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
545
          "must be specified when id is specified " . _subname
546
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
547
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
548

            
549
    # Check arguments
550
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
551
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
552
          unless $INSERT_ARGS{$name};
553
    }
554

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
555
    # Merge parameter
556
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
557
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
558
        $param = $self->merge_param($id_param, $param);
559
    }
560

            
cleanup
Yuki Kimoto authored on 2011-04-02
561
    # Reserved word quote
562
    my $q = $self->reserved_word_quote;
cleanup
yuki-kimoto authored on 2010-10-17
563
    
cleanup
Yuki Kimoto authored on 2011-04-02
564
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
565
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
566
    push @sql, "insert into $q$table$q " . $self->insert_param($param);
cleanup
Yuki Kimoto authored on 2011-01-27
567
    push @sql, $append if $append;
568
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
569
    
570
    # Execute query
cleanup
Yuki Kimoto authored on 2011-04-02
571
    return $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
572
        $sql,
cleanup
Yuki Kimoto authored on 2011-04-02
573
        param => $param,
cleanup
Yuki Kimoto authored on 2011-03-21
574
        table => $table,
575
        %args
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
576
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
577
}
578

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
579
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
580
    my ($self, $param) = @_;
581
    
cleanup
Yuki Kimoto authored on 2011-04-02
582
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
583
    my $safety = $self->safety_character;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
584
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
585
    my @columns;
586
    my @placeholders;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
587
    foreach my $column (keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
588
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
589
          unless $column =~ /^[$safety\.]+$/;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
590
        my $column_quote = "$q$column$q";
591
        $column_quote =~ s/\./$q.$q/;
592
        push @columns, $column_quote;
593
        push @placeholders, ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
594
    }
595
    
cleanup
Yuki Kimoto authored on 2011-04-02
596
    return '(' . join(', ', @columns) . ') ' . 'values ' .
597
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
598
}
599

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
600
sub include_model {
601
    my ($self, $name_space, $model_infos) = @_;
602
    
cleanup
Yuki Kimoto authored on 2011-04-02
603
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
604
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
605
    
606
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
607
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
608

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
609
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
610
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
611
          if $name_space =~ /[^\w:]/;
612
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
613
        croak qq{Name space module "$name_space.pm" is needed. $@ }
614
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
615
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
616
        
617
        # Search model modules
618
        my $path = $INC{"$name_space.pm"};
619
        $path =~ s/\.pm$//;
620
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
621
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
622
        $model_infos = [];
623
        while (my $module = readdir $dh) {
624
            push @$model_infos, $module
625
              if $module =~ s/\.pm$//;
626
        }
627
        close $dh;
628
    }
629
    
cleanup
Yuki Kimoto authored on 2011-04-02
630
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
631
    foreach my $model_info (@$model_infos) {
632
        
cleanup
Yuki Kimoto authored on 2011-04-02
633
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
634
        my $model_class;
635
        my $model_name;
636
        my $model_table;
637
        if (ref $model_info eq 'HASH') {
638
            $model_class = $model_info->{class};
639
            $model_name  = $model_info->{name};
640
            $model_table = $model_info->{table};
641
            
642
            $model_name  ||= $model_class;
643
            $model_table ||= $model_name;
644
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
645
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
646
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
647
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
648
          if $mclass =~ /[^\w:]/;
649
        unless ($mclass->can('isa')) {
650
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
651
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
652
        }
653
        
cleanup
Yuki Kimoto authored on 2011-04-02
654
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
655
        my $args = {};
656
        $args->{model_class} = $mclass if $mclass;
657
        $args->{name}        = $model_name if $model_name;
658
        $args->{table}       = $model_table if $model_table;
659
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
660
    }
661
    
662
    return $self;
663
}
664

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
665
sub merge_param {
666
    my ($self, @params) = @_;
667
    
cleanup
Yuki Kimoto authored on 2011-04-02
668
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
669
    my $merge = {};
670
    foreach my $param (@params) {
671
        foreach my $column (keys %$param) {
672
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
673
            
674
            if (exists $merge->{$column}) {
675
                $merge->{$column} = [$merge->{$column}]
676
                  unless ref $merge->{$column} eq 'ARRAY';
677
                push @{$merge->{$column}},
678
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
679
            }
680
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
681
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
682
            }
683
        }
684
    }
685
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
686
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
687
}
688

            
cleanup
Yuki Kimoto authored on 2011-03-21
689
sub method {
690
    my $self = shift;
691
    
cleanup
Yuki Kimoto authored on 2011-04-02
692
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
693
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
694
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
695
    
696
    return $self;
697
}
698

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
699
sub model {
700
    my ($self, $name, $model) = @_;
701
    
cleanup
Yuki Kimoto authored on 2011-04-02
702
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
703
    if ($model) {
704
        $self->models->{$name} = $model;
705
        return $self;
706
    }
707
    
708
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
709
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
710
      unless $self->models->{$name};
711
    
cleanup
Yuki Kimoto authored on 2011-04-02
712
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
713
    return $self->models->{$name};
714
}
715

            
cleanup
Yuki Kimoto authored on 2011-03-21
716
sub mycolumn {
717
    my ($self, $table, $columns) = @_;
718
    
cleanup
Yuki Kimoto authored on 2011-04-02
719
    # Create column clause
720
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
721
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
722
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
723
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
724
    
725
    return join (', ', @column);
726
}
727

            
added dbi_options attribute
kimoto authored on 2010-12-20
728
sub new {
729
    my $self = shift->SUPER::new(@_);
730
    
cleanup
Yuki Kimoto authored on 2011-04-02
731
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
732
    my @attrs = keys %$self;
733
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
734
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
735
          unless $self->can($attr);
736
    }
cleanup
Yuki Kimoto authored on 2011-04-02
737
    
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
738
    # DEPRECATED!
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
739
    $self->query_builder->{tags} = {
cleanup
Yuki Kimoto authored on 2011-01-25
740
        '?'     => \&DBIx::Custom::Tag::placeholder,
741
        '='     => \&DBIx::Custom::Tag::equal,
742
        '<>'    => \&DBIx::Custom::Tag::not_equal,
743
        '>'     => \&DBIx::Custom::Tag::greater_than,
744
        '<'     => \&DBIx::Custom::Tag::lower_than,
745
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
746
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
747
        'like'  => \&DBIx::Custom::Tag::like,
748
        'in'    => \&DBIx::Custom::Tag::in,
749
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
750
        'update_param' => \&DBIx::Custom::Tag::update_param
fixed DEPRECATED messages
Yuki Kimoto authored on 2011-06-08
751
    };
added dbi_options attribute
kimoto authored on 2010-12-20
752
    
753
    return $self;
754
}
755

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

            
cleanup
yuki-kimoto authored on 2010-10-17
758
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
759
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
760
    
761
    # Register filter
762
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
763
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
764
    
cleanup
Yuki Kimoto authored on 2011-04-02
765
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
766
}
packaging one directory
yuki-kimoto authored on 2009-11-16
767

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
858
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
859
    unshift @$tables,
860
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
861
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
862
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
863
    my $where_clause = '';
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
864
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
cleanup
Yuki Kimoto authored on 2011-04-25
865
    if (ref $where) {
866
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
867
        $where_param = keys %$where_param
868
                     ? $self->merge_param($where_param, $where->param)
869
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
870
        
871
        # String where
872
        $where_clause = $where->to_string;
873
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
874
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
875
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
876
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
877
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
878
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
879
    # Push join
880
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
881
    
cleanup
Yuki Kimoto authored on 2011-03-09
882
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
883
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
884
    
cleanup
Yuki Kimoto authored on 2011-03-08
885
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
886
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
887
    
cleanup
Yuki Kimoto authored on 2011-04-02
888
    # Append
cleanup
Yuki Kimoto authored on 2011-01-27
889
    push @sql, $append if $append;
890
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
891
    # Wrap
892
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
893
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
894
          unless ref $wrap eq 'ARRAY';
895
        unshift @sql, $wrap->[0];
896
        push @sql, $wrap->[1];
897
    }
898
    
cleanup
Yuki Kimoto authored on 2011-01-27
899
    # SQL
900
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
901
    
902
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
903
    my $result = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
904
        $sql,
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
905
        param => $where_param, 
cleanup
Yuki Kimoto authored on 2011-03-21
906
        table => $tables,
907
        %args
908
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
909
    
910
    return $result;
911
}
912

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
913
sub separator {
914
    my $self = shift;
915
    
916
    if (@_) {
917
        my $separator = $_[0] || '';
918
        croak qq{Separator must be "." or "__" or "-" } . _subname
919
          unless $separator eq '.' || $separator eq '__'
920
              || $separator eq '-';
921
        
922
        $self->{separator} = $separator;
923
    
924
        return $self;
925
    }
926
    return $self->{separator} ||= '.';
927
}
928

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
929
sub setup_model {
930
    my $self = shift;
931
    
cleanup
Yuki Kimoto authored on 2011-04-02
932
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
933
    $self->each_column(
934
        sub {
935
            my ($self, $table, $column, $column_info) = @_;
936
            if (my $model = $self->models->{$table}) {
937
                push @{$model->columns}, $column;
938
            }
939
        }
940
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
941
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
942
}
943

            
simplify type_rule
Yuki Kimoto authored on 2011-06-10
944
sub available_data_type {
945
    my $self = shift;
946
    
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
947
    my $data_types = '';
simplify type_rule
Yuki Kimoto authored on 2011-06-10
948
    foreach my $i (-1000 .. 1000) {
949
         my $type_info = $self->dbh->type_info($i);
950
         my $data_type = $type_info->{DATA_TYPE};
951
         my $type_name = $type_info->{TYPE_NAME};
952
         $data_types .= "$data_type ($type_name)\n"
953
           if defined $data_type;
954
    }
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
955
    return "Data Type maybe equal to Type Name" unless $data_types;
956
    $data_types = "Data Type (Type name)\n" . $data_types;
simplify type_rule
Yuki Kimoto authored on 2011-06-10
957
    return $data_types;
958
}
959

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
960
sub available_type_name {
961
    my $self = shift;
962
    
963
    # Type Names
964
    my $type_names = {};
965
    $self->each_column(sub {
966
        my ($self, $table, $column, $column_info) = @_;
967
        $type_names->{$column_info->{TYPE_NAME}} = 1
968
          if $column_info->{TYPE_NAME};
969
    });
970
    my @output = sort keys %$type_names;
971
    unshift @output, "Type Name";
972
    return join "\n", @output;
973
}
974

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
975
sub type_rule {
976
    my $self = shift;
977
    
978
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
979
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
980
        
981
        # Into
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
982
        $type_rule->{into} = _array_to_hash($type_rule->{into});
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
983
        $self->{type_rule} = $type_rule;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
984
        $self->{_into} ||= {};
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
985
        foreach my $type_name (keys %{$type_rule->{into} || {}}) {
986
            croak qq{type name of into section must be lower case}
987
              if $type_name =~ /[A-Z]/;
988
        }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
989
        $self->each_column(sub {
990
            my ($dbi, $table, $column, $column_info) = @_;
991
            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
992
            my $type_name = lc $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
993
            if ($type_rule->{into} &&
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
994
                (my $filter = $type_rule->{into}->{$type_name}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
995
            {
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
996
                return unless exists $type_rule->{into}->{$type_name};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
997
                if  (defined $filter && ref $filter ne 'CODE') 
998
                {
999
                    my $fname = $filter;
1000
                    croak qq{Filter "$fname" is not registered" } . _subname
1001
                      unless exists $self->filters->{$fname};
1002
                    
1003
                    $filter = $self->filters->{$fname};
1004
                }
1005

            
1006
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1007
            }
1008
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1009
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1010

            
1011
        # From
1012
        $type_rule->{from} = _array_to_hash($type_rule->{from});
1013
        foreach my $data_type (keys %{$type_rule->{from} || {}}) {
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-06-14
1014
            croak qq{data type of into section must be lower case or number}
1015
              if $data_type =~ /[A-Z]/;
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1016
            my $fname = $type_rule->{from}{$data_type};
1017
            if (defined $fname && ref $fname ne 'CODE') {
1018
                croak qq{Filter "$fname" is not registered" } . _subname
1019
                  unless exists $self->filters->{$fname};
1020
                
1021
                $type_rule->{from}{$data_type} = $self->filters->{$fname};
1022
            }
1023
        }
1024
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1025
        return $self;
1026
    }
1027
    
1028
    return $self->{type_rule} || {};
1029
}
1030

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1037
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1038
    my $param;
1039
    $param = shift if @_ % 2;
1040
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1041
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1042
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1043
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1044
    my $p = delete $args{param} || {};
1045
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
1046
    my $where            = delete $args{where} || {};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1047
    my $where_param      = delete $args{where_param} || {};
cleanup
Yuki Kimoto authored on 2011-03-21
1048
    my $append           = delete $args{append} || '';
1049
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1050
    my $id = delete $args{id};
1051
    my $primary_key = delete $args{primary_key};
1052
    croak "update method primary_key option " .
1053
          "must be specified when id is specified " . _subname
1054
      if defined $id && !defined $primary_key;
1055
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
version 0.0901
yuki-kimoto authored on 2009-12-17
1056
    
cleanup
Yuki Kimoto authored on 2011-04-02
1057
    # Check argument names
1058
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
1059
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1060
          unless $UPDATE_ARGS{$name};
1061
    }
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1062

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

            
1066
    # Where
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1067
    $where = $self->_create_param_from_id($id, $primary_key) if $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1068
    my $where_clause = '';
1069
    if (ref $where) {
1070
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1071
        $where_param = keys %$where_param
1072
                     ? $self->merge_param($where_param, $where->param)
1073
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1074
        
1075
        # String where
1076
        $where_clause = $where->to_string;
1077
    }
1078
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1079
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1080
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1081
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1082
    # Merge param
1083
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1084
    
cleanup
Yuki Kimoto authored on 2011-04-02
1085
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1086
    my @sql;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1087
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-04-02
1088
    push @sql, "update $q$table$q $update_clause $where_clause";
cleanup
Yuki Kimoto authored on 2011-01-27
1089
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1090
    
cleanup
Yuki Kimoto authored on 2011-01-27
1091
    # SQL
1092
    my $sql = join(' ', @sql);
1093
    
cleanup
yuki-kimoto authored on 2010-10-17
1094
    # Execute query
cleanup
Yuki Kimoto authored on 2011-03-21
1095
    my $ret_val = $self->execute(
cleanup
Yuki Kimoto authored on 2011-06-09
1096
        $sql,
cleanup
Yuki Kimoto authored on 2011-03-21
1097
        param  => $param, 
1098
        table => $table,
1099
        %args
1100
    );
cleanup
yuki-kimoto authored on 2010-10-17
1101
    
1102
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1103
}
1104

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1107
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1108
    my ($self, $param, $opt) = @_;
1109
    
cleanup
Yuki Kimoto authored on 2011-04-02
1110
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1111
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1112
    $tag = "set $tag" unless $opt->{no_set};
1113

            
cleanup
Yuki Kimoto authored on 2011-04-02
1114
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1115
}
1116

            
cleanup
Yuki Kimoto authored on 2011-01-25
1117
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1118
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
1119
    
1120
    # Create where
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1121
    return DBIx::Custom::Where->new(
1122
        query_builder => $self->query_builder,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1123
        safety_character => $self->safety_character,
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1124
        reserved_word_quote => $self->reserved_word_quote,
cleanup
Yuki Kimoto authored on 2011-03-09
1125
        @_
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
1126
    );
cleanup
Yuki Kimoto authored on 2011-01-25
1127
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1128

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

            
1132
    # Initialize filters
1133
    $self->{filter} ||= {};
1134
    $self->{filter}{out} ||= {};
1135
    $self->{filter}{in} ||= {};
1136
    $self->{filter}{end} ||= {};
1137
    
1138
    # Usage
1139
    my $usage = "Usage: \$dbi->apply_filter(" .
1140
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1141
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1142
    
1143
    # Apply filter
1144
    for (my $i = 0; $i < @cinfos; $i += 2) {
1145
        
1146
        # Column
1147
        my $column = $cinfos[$i];
1148
        if (ref $column eq 'ARRAY') {
1149
            foreach my $c (@$column) {
1150
                push @cinfos, $c, $cinfos[$i + 1];
1151
            }
1152
            next;
1153
        }
1154
        
1155
        # Filter infomation
1156
        my $finfo = $cinfos[$i + 1] || {};
1157
        croak "$usage (table: $table) " . _subname
1158
          unless  ref $finfo eq 'HASH';
1159
        foreach my $ftype (keys %$finfo) {
1160
            croak "$usage (table: $table) " . _subname
1161
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1162
        }
1163
        
1164
        # Set filters
1165
        foreach my $way (qw/in out end/) {
1166
        
1167
            # Filter
1168
            my $filter = $finfo->{$way};
1169
            
1170
            # Filter state
1171
            my $state = !exists $finfo->{$way} ? 'not_exists'
1172
                      : !defined $filter        ? 'not_defined'
1173
                      : ref $filter eq 'CODE'   ? 'code'
1174
                      : 'name';
1175
            
1176
            # Filter is not exists
1177
            next if $state eq 'not_exists';
1178
            
1179
            # Check filter name
1180
            croak qq{Filter "$filter" is not registered } . _subname
1181
              if  $state eq 'name'
1182
               && ! exists $self->filters->{$filter};
1183
            
1184
            # Set filter
1185
            my $f = $state eq 'not_defined' ? undef
1186
                  : $state eq 'code'        ? $filter
1187
                  : $self->filters->{$filter};
1188
            $self->{filter}{$way}{$table}{$column} = $f;
1189
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1190
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1191
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1192
        }
1193
    }
1194
    
1195
    return $self;
1196
}
1197

            
cleanup
Yuki Kimoto authored on 2011-04-02
1198
sub _create_bind_values {
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1199
    my ($self, $params, $columns, $filter, $type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1200
    
cleanup
Yuki Kimoto authored on 2011-04-02
1201
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1202
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1203
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1204
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1205
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1206
        
1207
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1208
        my $value;
1209
        if(ref $params->{$column} eq 'ARRAY') {
1210
            my $i = $count->{$column} || 0;
1211
            $i += $not_exists->{$column} || 0;
1212
            my $found;
1213
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1214
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1215
                    $not_exists->{$column}++;
1216
                }
1217
                else  {
1218
                    $value = $params->{$column}->[$k];
1219
                    $found = 1;
1220
                    last
1221
                }
1222
            }
1223
            next unless $found;
1224
        }
1225
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1226
        
cleanup
Yuki Kimoto authored on 2011-01-12
1227
        # Filter
1228
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1229
        
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1230
        # Type
1231
        push @$bind, {
1232
            value => $f ? $f->($value) : $value,
1233
            type => $type->{$column}
1234
        };
removed reconnect method
yuki-kimoto authored on 2010-05-28
1235
        
1236
        # Count up 
1237
        $count->{$column}++;
1238
    }
1239
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1240
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1241
}
1242

            
cleanup
Yuki Kimoto authored on 2011-06-08
1243
sub _create_param_from_id {
1244
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1245
    
cleanup
Yuki Kimoto authored on 2011-06-08
1246
    # Create parameter
1247
    my $param = {};
1248
    if ($id) {
1249
        $id = [$id] unless ref $id;
1250
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1251
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1252
          unless !ref $id || ref $id eq 'ARRAY';
1253
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1254
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1255
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1256
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1257
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1258
        }
1259
    }
1260
    
cleanup
Yuki Kimoto authored on 2011-06-08
1261
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1262
}
1263

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1264
sub _connect {
1265
    my $self = shift;
1266
    
1267
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1268
    my $dsn = $self->data_source;
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1269
    warn "data_source is DEPRECATED! use dsn instead\n"
1270
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1271
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1272
    croak qq{"dsn" must be specified } . _subname
1273
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1274
    my $user        = $self->user;
1275
    my $password    = $self->password;
1276
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1277
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1278
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1279
    
1280
    # Connect
1281
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1282
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1283
        $user,
1284
        $password,
1285
        {
1286
            %{$self->default_dbi_option},
1287
            %$dbi_option
1288
        }
1289
    )};
1290
    
1291
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1292
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1293
    
1294
    return $dbh;
1295
}
1296

            
cleanup
yuki-kimoto authored on 2010-10-17
1297
sub _croak {
1298
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1299
    
1300
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1301
    $append ||= "";
1302
    
1303
    # Verbose
1304
    if ($Carp::Verbose) { croak $error }
1305
    
1306
    # Not verbose
1307
    else {
1308
        
1309
        # Remove line and module infromation
1310
        my $at_pos = rindex($error, ' at ');
1311
        $error = substr($error, 0, $at_pos);
1312
        $error =~ s/\s+$//;
1313
        croak "$error$append";
1314
    }
1315
}
1316

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1317
sub _need_tables {
1318
    my ($self, $tree, $need_tables, $tables) = @_;
1319
    
cleanup
Yuki Kimoto authored on 2011-04-02
1320
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1321
    foreach my $table (@$tables) {
1322
        if ($tree->{$table}) {
1323
            $need_tables->{$table} = 1;
1324
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1325
        }
1326
    }
1327
}
1328

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1329
sub _push_join {
1330
    my ($self, $sql, $join, $join_tables) = @_;
1331
    
cleanup
Yuki Kimoto authored on 2011-04-02
1332
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1333
    return unless @$join;
1334
    
cleanup
Yuki Kimoto authored on 2011-04-02
1335
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1336
    my $tree = {};
cleanup
Yuki Kimoto authored on 2011-04-02
1337
    my $q = $self->reserved_word_quote;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1338
    for (my $i = 0; $i < @$join; $i++) {
1339
        
cleanup
Yuki Kimoto authored on 2011-04-02
1340
        # Search table in join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1341
        my $join_clause = $join->[$i];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1342
        my $q_re = quotemeta($q);
cleanup
Yuki Kimoto authored on 2011-04-01
1343
        my $join_re = $q ? qr/\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?\s$q_re?([^\.\s$q_re]+?)$q_re?\..+?$/
1344
                         : qr/\s([^\.\s]+?)\..+?\s([^\.\s]+?)\..+?$/;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1345
        if ($join_clause =~ $join_re) {
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1346
            my $table1 = $1;
1347
            my $table2 = $2;
cleanup
Yuki Kimoto authored on 2011-04-25
1348
            croak qq{right side table of "$join_clause" must be unique }
1349
                . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1350
              if exists $tree->{$table2};
1351
            $tree->{$table2}
1352
              = {position => $i, parent => $table1, join => $join_clause};
1353
        }
1354
        else {
improved error message
Yuki Kimoto authored on 2011-06-13
1355
            croak qq{join clause must have two table name after "on" keyword. } .
1356
                  qq{"$join_clause" is passed }  . _subname
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1357
        }
1358
    }
1359
    
cleanup
Yuki Kimoto authored on 2011-04-02
1360
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1361
    my $need_tables = {};
1362
    $self->_need_tables($tree, $need_tables, $join_tables);
1363
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1364
    
1365
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1366
    foreach my $need_table (@need_tables) {
1367
        push @$sql, $tree->{$need_table}{join};
1368
    }
1369
}
cleanup
Yuki Kimoto authored on 2011-03-08
1370

            
cleanup
Yuki Kimoto authored on 2011-04-02
1371
sub _remove_duplicate_table {
1372
    my ($self, $tables, $main_table) = @_;
1373
    
1374
    # Remove duplicate table
1375
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1376
    delete $tables{$main_table} if $main_table;
1377
    
1378
    return [keys %tables, $main_table ? $main_table : ()];
1379
}
1380

            
cleanup
Yuki Kimoto authored on 2011-04-02
1381
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1382
    my ($self, $source) = @_;
1383
    
cleanup
Yuki Kimoto authored on 2011-04-02
1384
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1385
    my $tables = [];
1386
    my $safety_character = $self->safety_character;
1387
    my $q = $self->reserved_word_quote;
1388
    my $q_re = quotemeta($q);
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1389
    my $table_re = $q ? qr/(?:^|[^$safety_character])$q_re?([$safety_character]+)$q_re?\./
1390
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1391
    while ($source =~ /$table_re/g) {
1392
        push @$tables, $1;
1393
    }
1394
    
1395
    return $tables;
1396
}
1397

            
cleanup
Yuki Kimoto authored on 2011-04-02
1398
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1399
    my ($self, $where) = @_;
1400
    
cleanup
Yuki Kimoto authored on 2011-04-02
1401
    my $obj;
1402
    
1403
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1404
    if (ref $where eq 'HASH') {
1405
        my $clause = ['and'];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1406
        my $q = $self->reserved_word_quote;
1407
        foreach my $column (keys %$where) {
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1408
            my $column_quote = "$q$column$q";
1409
            $column_quote =~ s/\./$q.$q/;
1410
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1411
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1412
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1413
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1414
    
1415
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1416
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1417
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1418
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1419
    
1420
    # Array(DEPRECATED!)
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1421
    elsif (ref $where eq 'ARRAY') {
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
1422
        warn "\$dbi->select(where => [CLAUSE, PARAMETER]) is DEPRECATED." .
1423
             "use \$dbi->select(where => \$dbi->where(clause => " .
added warnings
Yuki Kimoto authored on 2011-06-07
1424
             "CLAUSE, where_param => PARAMETER));";
cleanup
Yuki Kimoto authored on 2011-04-02
1425
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1426
            clause => $where->[0],
1427
            param  => $where->[1]
1428
        );
1429
    }
1430
    
cleanup
Yuki Kimoto authored on 2011-04-02
1431
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1432
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1433
        . qq{or array reference, which contains where clause and paramter}
cleanup
Yuki Kimoto authored on 2011-04-25
1434
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1435
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1436
    
cleanup
Yuki Kimoto authored on 2011-04-02
1437
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1438
}
1439

            
cleanup
Yuki Kimoto authored on 2011-06-13
1440
# DEPRECATED!
1441
sub apply_filter {
1442
    my $self = shift;
1443
    
1444
    warn "apply_filter is DEPRECATED! " . 
removed EXPERIMENTAL DBIx::M...
Yuki Kimoto authored on 2011-06-14
1445
         "use type_rule method and DBIx::Custom::Result filter method, " .
1446
         "instead";
cleanup
Yuki Kimoto authored on 2011-06-13
1447
    
1448
    return $self->_apply_filter(@_);
1449
}
1450

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1451
# DEPRECATED!
1452
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1453
sub select_at {
1454
    my ($self, %args) = @_;
1455

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1458
    # Arguments
1459
    my $primary_keys = delete $args{primary_key};
1460
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1461
    my $where = delete $args{where};
1462
    my $param = delete $args{param};
1463
    
1464
    # Check arguments
1465
    foreach my $name (keys %args) {
1466
        croak qq{"$name" is wrong option } . _subname
1467
          unless $SELECT_AT_ARGS{$name};
1468
    }
1469
    
1470
    # Table
1471
    croak qq{"table" option must be specified } . _subname
1472
      unless $args{table};
1473
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1474
    
1475
    # Create where parameter
1476
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1477
    
1478
    return $self->select(where => $where_param, %args);
1479
}
1480

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1481
# DEPRECATED!
1482
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1483
sub delete_at {
1484
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1485

            
1486
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1487
    
1488
    # Arguments
1489
    my $primary_keys = delete $args{primary_key};
1490
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1491
    my $where = delete $args{where};
1492
    
1493
    # Check arguments
1494
    foreach my $name (keys %args) {
1495
        croak qq{"$name" is wrong option } . _subname
1496
          unless $DELETE_AT_ARGS{$name};
1497
    }
1498
    
1499
    # Create where parameter
1500
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1501
    
1502
    return $self->delete(where => $where_param, %args);
1503
}
1504

            
cleanup
Yuki Kimoto authored on 2011-06-08
1505
# DEPRECATED!
1506
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1507
sub update_at {
1508
    my $self = shift;
1509

            
1510
    warn "update_at is DEPRECATED! use update and id option instead";
1511
    
1512
    # Arguments
1513
    my $param;
1514
    $param = shift if @_ % 2;
1515
    my %args = @_;
1516
    my $primary_keys = delete $args{primary_key};
1517
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1518
    my $where = delete $args{where};
1519
    my $p = delete $args{param} || {};
1520
    $param  ||= $p;
1521
    
1522
    # Check arguments
1523
    foreach my $name (keys %args) {
1524
        croak qq{"$name" is wrong option } . _subname
1525
          unless $UPDATE_AT_ARGS{$name};
1526
    }
1527
    
1528
    # Create where parameter
1529
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1530
    
1531
    return $self->update(where => $where_param, param => $param, %args);
1532
}
1533

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1534
# DEPRECATED!
1535
our %INSERT_AT_ARGS = (%INSERT_ARGS, where => 1, primary_key => 1);
1536
sub insert_at {
1537
    my $self = shift;
1538
    
1539
    warn "insert_at is DEPRECATED! use insert and id option instead";
1540
    
1541
    # Arguments
1542
    my $param;
1543
    $param = shift if @_ % 2;
1544
    my %args = @_;
1545
    my $primary_key = delete $args{primary_key};
1546
    $primary_key = [$primary_key] unless ref $primary_key;
1547
    my $where = delete $args{where};
1548
    my $p = delete $args{param} || {};
1549
    $param  ||= $p;
1550
    
1551
    # Check arguments
1552
    foreach my $name (keys %args) {
1553
        croak qq{"$name" is wrong option } . _subname
1554
          unless $INSERT_AT_ARGS{$name};
1555
    }
1556
    
1557
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1558
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1559
    $param = $self->merge_param($where_param, $param);
1560
    
1561
    return $self->insert(param => $param, %args);
1562
}
1563

            
added warnings
Yuki Kimoto authored on 2011-06-07
1564
# DEPRECATED!
1565
sub register_tag {
1566
    warn "register_tag is DEPRECATED!";
1567
    shift->query_builder->register_tag(@_)
1568
}
1569

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1570
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1571
has 'data_source';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1572

            
cleanup
Yuki Kimoto authored on 2011-01-25
1573
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1574
has dbi_options => sub { {} },
1575
    filter_check  => 1;
1576

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1578
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1579
sub default_bind_filter {
1580
    my $self = shift;
1581
    
cleanup
Yuki Kimoto authored on 2011-06-13
1582
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1583
    
cleanup
Yuki Kimoto authored on 2011-01-12
1584
    if (@_) {
1585
        my $fname = $_[0];
1586
        
1587
        if (@_ && !$fname) {
1588
            $self->{default_out_filter} = undef;
1589
        }
1590
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1591
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1592
              unless exists $self->filters->{$fname};
1593
        
1594
            $self->{default_out_filter} = $self->filters->{$fname};
1595
        }
1596
        return $self;
1597
    }
1598
    
1599
    return $self->{default_out_filter};
1600
}
1601

            
cleanup
Yuki Kimoto authored on 2011-01-25
1602
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1603
sub default_fetch_filter {
1604
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1605

            
cleanup
Yuki Kimoto authored on 2011-06-13
1606
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1607
    
1608
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1609
        my $fname = $_[0];
1610

            
cleanup
Yuki Kimoto authored on 2011-01-12
1611
        if (@_ && !$fname) {
1612
            $self->{default_in_filter} = undef;
1613
        }
1614
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1615
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1616
              unless exists $self->filters->{$fname};
1617
        
1618
            $self->{default_in_filter} = $self->filters->{$fname};
1619
        }
1620
        
1621
        return $self;
1622
    }
1623
    
many changed
Yuki Kimoto authored on 2011-01-23
1624
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1625
}
1626

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1627
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1628
sub insert_param_tag {
1629
    warn "insert_param_tag is DEPRECATED! " .
1630
         "use insert_param instead!";
1631
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1632
}
1633

            
cleanup
Yuki Kimoto authored on 2011-01-25
1634
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1635
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1636
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1637
    return shift->query_builder->register_tag_processor(@_);
1638
}
1639

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1640
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1641
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1642
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1643
         "use update_param instead";
1644
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1645
}
cleanup
Yuki Kimoto authored on 2011-03-08
1646
# DEPRECATED!
1647
sub _push_relation {
1648
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1649
    
1650
    if (keys %{$relation || {}}) {
1651
        push @$sql, $need_where ? 'where' : 'and';
1652
        foreach my $rcolumn (keys %$relation) {
1653
            my $table1 = (split (/\./, $rcolumn))[0];
1654
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1655
            push @$tables, ($table1, $table2);
1656
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1657
        }
1658
    }
1659
    pop @$sql if $sql->[-1] eq 'and';    
1660
}
1661

            
1662
# DEPRECATED!
1663
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1664
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1665
    
1666
    if (keys %{$relation || {}}) {
1667
        foreach my $rcolumn (keys %$relation) {
1668
            my $table1 = (split (/\./, $rcolumn))[0];
1669
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1670
            my $table1_exists;
1671
            my $table2_exists;
1672
            foreach my $table (@$tables) {
1673
                $table1_exists = 1 if $table eq $table1;
1674
                $table2_exists = 1 if $table eq $table2;
1675
            }
1676
            unshift @$tables, $table1 unless $table1_exists;
1677
            unshift @$tables, $table2 unless $table2_exists;
1678
        }
1679
    }
1680
}
1681

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1684
=head1 NAME
1685

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

            
1688
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1689

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1690
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1691
    
1692
    # Connect
1693
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1694
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1695
        user => 'ken',
1696
        password => '!LFKD%$&',
1697
        dbi_option => {mysql_enable_utf8 => 1}
1698
    );
cleanup
yuki-kimoto authored on 2010-08-05
1699

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1700
    # Insert 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1701
    $dbi->insert(
1702
        table  => 'book',
1703
        param  => {title => 'Perl', author => 'Ken'}
1704
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1705
    
1706
    # Update 
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1707
    $dbi->update(
1708
        table  => 'book', 
1709
        param  => {title => 'Perl', author => 'Ken'}, 
1710
        where  => {id => 5},
1711
    );
removed reconnect method
yuki-kimoto authored on 2010-05-28
1712
    
1713
    # Delete
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1714
    $dbi->delete(
1715
        table  => 'book',
1716
        where  => {author => 'Ken'},
1717
    );
cleanup
yuki-kimoto authored on 2010-08-05
1718

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1726
    # Select, more complex
1727
    my $result = $dbi->select(
1728
        table  => 'book',
1729
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1730
            {book => [qw/title author/]},
1731
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1732
        ],
1733
        where  => {'book.author' => 'Ken'},
1734
        join => ['left outer join company on book.company_id = company.id'],
1735
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1736
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1737
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1738
    # Fetch
1739
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1740
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1741
    }
1742
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1743
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1744
    while (my $row = $result->fetch_hash) {
1745
        
1746
    }
1747
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1748
    # Execute SQL with parameter.
1749
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1750
        "select id from book where author = :author and title like :title",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1751
        param  => {author => 'ken', title => '%Perl%'}
1752
    );
1753
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1754
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1755

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

            
1758
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1759

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1769
=item *
1770

            
1771
Filter when data is send or receive.
1772

            
1773
=item *
1774

            
1775
Data filtering system
1776

            
1777
=item *
1778

            
1779
Model support.
1780

            
1781
=item *
1782

            
1783
Generate where clause dinamically.
1784

            
1785
=item *
1786

            
1787
Generate join clause dinamically.
1788

            
1789
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1790

            
1791
=head1 GUIDE
1792

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

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

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

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

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

            
1803
    my $connector = $dbi->connector;
1804
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1805

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

            
1809
This is L<DBIx::Connector> example. Please pass
1810
C<default_dbi_option> to L<DBIx::Connector>.
1811

            
1812
    my $connector = DBIx::Connector->new(
1813
        "dbi:mysql:database=$DATABASE",
1814
        $USER,
1815
        $PASSWORD,
1816
        DBIx::Custom->new->default_dbi_option
1817
    );
1818
    
1819
    my $dbi = DBIx::Custom->new(connector => $connector);
1820

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

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

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

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

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

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

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

            
1838
=head2 C<default_dbi_option>
1839

            
1840
    my $default_dbi_option = $dbi->default_dbi_option;
1841
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1842

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1846
    {
1847
        RaiseError => 1,
1848
        PrintError => 0,
1849
        AutoCommit => 1,
1850
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1851

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

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

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

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

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

            
1864
    my $models = $dbi->models;
1865
    $dbi       = $dbi->models(\%models);
1866

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1869
=head2 C<password>
1870

            
1871
    my $password = $dbi->password;
1872
    $dbi         = $dbi->password('lkj&le`@s');
1873

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

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

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

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

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

            
1885
     my reserved_word_quote = $dbi->reserved_word_quote;
1886
     $dbi                   = $dbi->reserved_word_quote('"');
1887

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1907
    my $user = $dbi->user;
1908
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1909

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

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

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

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

            
1920
    print $dbi->available_data_type;
1921

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

            
1925
=head2 C<available_type_name> EXPERIMENTAL
1926

            
1927
    print $dbi->available_type_name;
1928

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1953
    # Separator is double underbar
1954
    $dbi->separator('__');
1955
    
1956
    book.author as "book__author",
1957
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1958

            
cleanup
Yuki Kimoto authored on 2011-06-13
1959
    # Separator is hyphen
1960
    $dbi->separator('-');
1961
    
1962
    book.author as "book-author",
1963
    book.title as "book-title"
1964
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1965
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1966

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

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

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

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

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

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

            
2000
   $dbi->model('book')->select(...);
2001

            
cleanup
yuki-kimoto authored on 2010-10-17
2002
=head2 C<create_query>
2003
    
2004
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-03-13
2005
        "insert into book {insert_param title author};";
cleanup
yuki-kimoto authored on 2010-10-17
2006
    );
update document
yuki-kimoto authored on 2009-11-19
2007

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

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

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

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

            
2018
    my $dbh = $dbi->dbh;
2019

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

            
2023
=head2 C<each_column>
2024

            
2025
    $dbi->each_column(
2026
        sub {
2027
            my ($dbi, $table, $column, $column_info) = @_;
2028
            
2029
            my $type = $column_info->{TYPE_NAME};
2030
            
2031
            if ($type eq 'DATE') {
2032
                # ...
2033
            }
2034
        }
2035
    );
2036

            
2037
Iterate all column informations of all table from database.
2038
Argument is callback when one column is found.
2039
Callback receive four arguments, dbi object, table name,
2040
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2041

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

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

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

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

            
2055
    select * from where title = ? and author like ?;
2056

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

            
2059
=over 4
2060

            
2061
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2062
    
2063
    filter => {
2064
        title  => sub { uc $_[0] }
2065
        author => sub { uc $_[0] }
2066
    }
update pod
Yuki Kimoto authored on 2011-03-13
2067

            
updated pod
Yuki Kimoto authored on 2011-06-09
2068
    # Filter name
2069
    filter => {
2070
        title  => 'upper_case',
2071
        author => 'upper_case'
2072
    }
2073
        
2074
    # At once
2075
    filter => [
2076
        [qw/title author/]  => sub { uc $_[0] }
2077
    ]
2078

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

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

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

            
2087
    query => 1
2088

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2091
=item C<table>
2092
    
2093
    table => 'author'
2094
    table => ['author', 'book']
2095

            
2096
Table names for filtering.
2097

            
2098
Filtering by C<apply_filter> is off in C<execute> method,
2099
because we don't know what filter is applied.
2100

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

            
2103
Specify database data type.
2104

            
2105
    type => [image => DBI::SQL_BLOB]
2106
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2107

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

            
2110
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2111

            
2112
C<type> option is also available
2113
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2114

            
2115
=item C<type_rule_off> EXPERIMENTAL
2116

            
2117
    type_rule_off => 1
2118

            
2119
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2120

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2131
=over 4
2132

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

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

            
2137
=item C<filter>
2138

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2143
    id => 4
2144
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2145

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2149
    $dbi->delete(
2150
        parimary_key => ['id1', 'id2'],
2151
        id => [4, 5],
2152
        table => 'book',
2153
    );
update pod
Yuki Kimoto authored on 2011-03-13
2154

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

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

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

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

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

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

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

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

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

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

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

            
2177
Same as C<execute> method's C<type> option.
2178

            
2179
=item C<type_rule_off> EXPERIMENTAL
2180

            
2181
Same as C<execute> method's C<type_rule_off> option.
2182

            
updated pod
Yuki Kimoto authored on 2011-06-08
2183
=back
update pod
Yuki Kimoto authored on 2011-03-13
2184

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2192
=head2 C<insert>
2193

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

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

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

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

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

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

            
2206
=item C<filter>
2207

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

            
2210
=item C<id>
2211

            
updated document
Yuki Kimoto authored on 2011-06-09
2212
    id => 4
2213
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2214

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

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

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

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

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

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

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

            
2239
=item C<param>
2240

            
2241
    param => {title => 'Perl', author => 'Ken'}
2242

            
2243
Insert data.
2244

            
2245
If C<insert> method's arguments is odd numbers,
2246
first argument is received as C<param>.
2247

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

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

            
2252
Same as C<execute> method's C<query> option.
2253

            
2254
=item C<table>
2255

            
2256
    table => 'book'
2257

            
2258
Table name.
2259

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2268
=back
2269

            
2270
=over 4
2271

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2287
    lib / MyModel.pm
2288
        / MyModel / book.pm
2289
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2290

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

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

            
2295
    package MyModel;
2296
    
2297
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2298
    
2299
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2300

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2305
    package MyModel::book;
2306
    
2307
    use base 'MyModel';
2308
    
2309
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2310

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2313
    package MyModel::company;
2314
    
2315
    use base 'MyModel';
2316
    
2317
    1;
2318
    
2319
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2320

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

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

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

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

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

            
2332
Merge paramters.
2333

            
2334
$param:
2335

            
2336
    {key1 => [1, 1], key2 => 2}
2337

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

            
2340
    $dbi->method(
2341
        update_or_insert => sub {
2342
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2343
            
2344
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2345
        },
2346
        find_or_create   => sub {
2347
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2348
            
2349
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2350
        }
2351
    );
2352

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

            
2355
    $dbi->update_or_insert;
2356
    $dbi->find_or_create;
2357

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

            
2360
    $dbi->model('book')->method(
2361
        insert => sub { ... },
2362
        update => sub { ... }
2363
    );
2364
    
2365
    my $model = $dbi->model('book');
2366

            
2367
Set and get a L<DBIx::Custom::Model> object,
2368

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

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

            
2373
Create column clause for myself. The follwoing column clause is created.
2374

            
2375
    book.author as author,
2376
    book.title as title
2377

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

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

            
2387
Create a new L<DBIx::Custom> object.
2388

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

            
2391
    my $not_exists = $dbi->not_exists;
2392

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2396
=head2 C<register_filter>
2397

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

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

            
2415
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2416
        into => {
2417
            DATE => sub { ... },
2418
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2419
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2420
        from => {
2421
            # DATE
2422
            9 => sub { ... },
2423
            
2424
            # DATETIME or TIMESTAMP
2425
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2426
        }
2427
    );
2428

            
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2429
Filtering rule when data is send into and get from database.
2430
This has a little complex problem. 
cleanup
Yuki Kimoto authored on 2011-06-13
2431

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

            
2436
=over 4
2437

            
2438
=item 1. column name
2439

            
2440
    issue_date
2441
    issue_datetime
2442

            
2443
=item 2. table name and column name, separator is dot
2444

            
2445
    book.issue_date
2446
    book.issue_datetime
2447

            
2448
=back
2449

            
2450
In C<from> you can't specify type name defined by create table.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2451
You must specify data type, this is internal one.
2452
You get all data type by C<available_data_type>.
2453

            
2454
    print $dbi->available_data_type;
2455

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

            
2458
=item 1. column name
2459

            
2460
    issue_date
2461
    issue_datetime
2462

            
2463
=item 2. table name and column name, separator is dot
2464

            
2465
    book.issue_date
2466
    book.issue_datetime
2467

            
2468
=item 3. table name and column name, separator is double underbar
2469

            
2470
    book__issue_date
2471
    book__issue_datetime
2472

            
2473
=item 4. table name and column name, separator is hyphen
2474

            
2475
    book-issue_date
2476
    book-issue_datetime
2477

            
2478
This is useful in HTML.
2479

            
2480
=back
2481

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

            
2484
    $dbi->type_rule(
2485
        into => [
2486
            [qw/DATE DATETIME/] => sub { ... },
2487
        ],
2488
        from => {
2489
            # DATE
2490
            [qw/9 11/] => sub { ... },
2491
        }
2492
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2493

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2496
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2497
        table  => 'book',
2498
        column => ['author', 'title'],
2499
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2500
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2501
    
updated document
Yuki Kimoto authored on 2011-06-09
2502
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2503

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

            
2506
=over 4
2507

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2512
Append statement to last of SQL.
2513
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2514
=item C<column>
2515
    
updated document
Yuki Kimoto authored on 2011-06-09
2516
    column => 'author'
2517
    column => ['author', 'title']
2518

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2527
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2528
        {book => [qw/author title/]},
2529
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2530
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2531

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

            
2534
    book.author as "book.author",
2535
    book.title as "book.title",
2536
    person.name as "person.name",
2537
    person.age as "person.age"
2538

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2541
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2542
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2543
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2544

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

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

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

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

            
2553
=item C<id>
2554

            
2555
    id => 4
2556
    id => [4, 5]
2557

            
2558
ID corresponding to C<primary_key>.
2559
You can select rows by C<id> and C<primary_key>.
2560

            
2561
    $dbi->select(
2562
        parimary_key => ['id1', 'id2'],
2563
        id => [4, 5],
2564
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2565
    );
2566

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2569
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2570
        where => {id1 => 4, id2 => 5},
2571
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2572
    );
2573
    
updated document
Yuki Kimoto authored on 2011-06-09
2574
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2575

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

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

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

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

            
2588
    prefix => 'SQL_CALC_FOUND_ROWS'
2589

            
2590
Prefix of column cluase
2591

            
2592
    select SQL_CALC_FOUND_ROWS title, author from book;
2593

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

            
2596
    join => [
2597
        'left outer join company on book.company_id = company_id',
2598
        'left outer join location on company.location_id = location.id'
2599
    ]
2600
        
2601
Join clause. If column cluase or where clause contain table name like "company.name",
2602
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2603

            
2604
    $dbi->select(
2605
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2606
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2607
        where => {'company.name' => 'Orange'},
2608
        join => [
2609
            'left outer join company on book.company_id = company.id',
2610
            'left outer join location on company.location_id = location.id'
2611
        ]
2612
    );
2613

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2617
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2618
    from book
2619
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2620
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2621

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2641
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2642

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2647
=item C<where>
2648
    
2649
    # Hash refrence
2650
    where => {author => 'Ken', 'title' => 'Perl'}
2651
    
2652
    # DBIx::Custom::Where object
2653
    where => $dbi->where(
2654
        clause => ['and', 'author = :author', 'title like :title'],
2655
        param  => {author => 'Ken', title => '%Perl%'}
2656
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2657

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2662
Where clause.
2663
    
improved pod
Yuki Kimoto authored on 2011-04-19
2664
=item C<wrap> EXPERIMENTAL
2665

            
2666
Wrap statement. This is array reference.
2667

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

            
2670
This option is for Oracle and SQL Server paging process.
2671

            
update pod
Yuki Kimoto authored on 2011-03-12
2672
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2673

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2682
=over 4
2683

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2694
    id => 4
2695
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2696

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2700
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2701
        {title => 'Perl', author => 'Ken'}
2702
        parimary_key => ['id1', 'id2'],
2703
        id => [4, 5],
2704
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2705
    );
update pod
Yuki Kimoto authored on 2011-03-13
2706

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2709
    $dbi->update(
2710
        {title => 'Perl', author => 'Ken'}
2711
        where => {id1 => 4, id2 => 5},
2712
        table => 'book'
2713
    );
update pod
Yuki Kimoto authored on 2011-03-13
2714

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2721
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
2722

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

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

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

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

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

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

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

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

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

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

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

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

            
2748
Same as C<execute> method's C<type> option.
2749

            
2750
=item C<type_rule_off> EXPERIMENTAL
2751

            
2752
Turn type rule off.
2753

            
updated pod
Yuki Kimoto authored on 2011-06-08
2754
=back
update pod
Yuki Kimoto authored on 2011-03-13
2755

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

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

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

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

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

            
2767
Create update parameter tag.
2768

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

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

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

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

            
2780
Create a new L<DBIx::Custom::Where> object.
2781

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

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

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

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

            
2791
Update statement, using primary key.
2792

            
2793
    $dbi->update_at(
2794
        table => 'book',
2795
        primary_key => 'id',
2796
        where => '5',
2797
        param => {title => 'Perl'}
2798
    );
2799

            
2800
This method is same as C<update()> exept that
2801
C<primary_key> is specified and C<where> is constant value or array refrence.
2802
all option of C<update()> is available.
2803

            
2804
=head2 C<delete_at()> DEPRECATED!
2805

            
2806
Delete statement, using primary key.
2807

            
2808
    $dbi->delete_at(
2809
        table => 'book',
2810
        primary_key => 'id',
2811
        where => '5'
2812
    );
2813

            
2814
This method is same as C<delete()> exept that
2815
C<primary_key> is specified and C<where> is constant value or array refrence.
2816
all option of C<delete()> is available.
2817

            
2818
=head2 C<select_at()> DEPRECATED!
2819

            
2820
Select statement, using primary key.
2821

            
2822
    $dbi->select_at(
2823
        table => 'book',
2824
        primary_key => 'id',
2825
        where => '5'
2826
    );
2827

            
2828
This method is same as C<select()> exept that
2829
C<primary_key> is specified and C<where> is constant value or array refrence.
2830
all option of C<select()> is available.
2831

            
2832
=head2 C<register_tag> DEPRECATED!
2833

            
2834
    $dbi->register_tag(
2835
        update => sub {
2836
            my @columns = @_;
2837
            
2838
            # Update parameters
2839
            my $s = 'set ';
2840
            $s .= "$_ = ?, " for @columns;
2841
            $s =~ s/, $//;
2842
            
2843
            return [$s, \@columns];
2844
        }
2845
    );
2846

            
2847
Register tag, used by C<execute()>.
2848

            
2849
See also L<Tags/Tags> about tag registered by default.
2850

            
2851
Tag parser receive arguments specified in tag.
2852
In the following tag, 'title' and 'author' is parser arguments
2853

            
2854
    {update_param title author} 
2855

            
2856
Tag parser must return array refrence,
2857
first element is the result statement, 
2858
second element is column names corresponding to place holders.
2859

            
2860
In this example, result statement is 
2861

            
2862
    set title = ?, author = ?
2863

            
2864
Column names is
2865

            
2866
    ['title', 'author']
2867

            
EXPERIMENTAL type_rule_off i...
Yuki Kimoto authored on 2011-06-14
2868
=head2 C<apply_filter> DEPRECATED!
2869

            
2870
    $dbi->apply_filter(
2871
        'book',
2872
        'issue_date' => {
2873
            out => 'tp_to_date',
2874
            in  => 'date_to_tp',
2875
            end => 'tp_to_displaydate'
2876
        },
2877
        'write_date' => {
2878
            out => 'tp_to_date',
2879
            in  => 'date_to_tp',
2880
            end => 'tp_to_displaydate'
2881
        }
2882
    );
2883

            
2884
Apply filter to columns.
2885
C<out> filter is executed before data is send to database.
2886
C<in> filter is executed after a row is fetch.
2887
C<end> filter is execute after C<in> filter is executed.
2888

            
2889
Filter is applied to the follwoing tree column name pattern.
2890

            
2891
       PETTERN         EXAMPLE
2892
    1. Column        : author
2893
    2. Table.Column  : book.author
2894
    3. Table__Column : book__author
2895
    4. Table-Column  : book-author
2896

            
2897
If column name is duplicate with other table,
2898
Main filter specified by C<table> option is used.
2899

            
2900
You can set multiple filters at once.
2901

            
2902
    $dbi->apply_filter(
2903
        'book',
2904
        [qw/issue_date write_date/] => {
2905
            out => 'tp_to_date',
2906
            in  => 'date_to_tp',
2907
            end => 'tp_to_displaydate'
2908
        }
2909
    );
2910

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2911
=head1 Parameter
2912

            
2913
Parameter start at ':'. This is replaced to place holoder
2914

            
2915
    $dbi->execute(
2916
        "select * from book where title = :title and author = :author"
2917
        param => {title => 'Perl', author => 'Ken'}
2918
    );
2919

            
2920
    "select * from book where title = ? and author = ?"
2921

            
2922
=head1 Tags DEPRECATED!
2923

            
2924
B<Tag> system is DEPRECATED! use parameter system :name instead.
2925
Parameter is simple and readable.
2926

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

            
2929
The following tags is available.
2930

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

            
2933
Placeholder tag.
2934

            
2935
    {? NAME}    ->   ?
2936

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

            
2939
Equal tag.
2940

            
2941
    {= NAME}    ->   NAME = ?
2942

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

            
2945
Not equal tag.
2946

            
2947
    {<> NAME}   ->   NAME <> ?
2948

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

            
2951
Lower than tag
2952

            
2953
    {< NAME}    ->   NAME < ?
2954

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

            
2957
Greater than tag
2958

            
2959
    {> NAME}    ->   NAME > ?
2960

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

            
2963
Greater than or equal tag
2964

            
2965
    {>= NAME}   ->   NAME >= ?
2966

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

            
2969
Lower than or equal tag
2970

            
2971
    {<= NAME}   ->   NAME <= ?
2972

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

            
2975
Like tag
2976

            
2977
    {like NAME}   ->   NAME like ?
2978

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

            
2981
In tag.
2982

            
2983
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2984

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

            
2987
Insert parameter tag.
2988

            
2989
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2990

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

            
2993
Updata parameter tag.
2994

            
2995
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
2996

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

            
2999
Insert statement, using primary key.
3000

            
3001
    $dbi->insert_at(
3002
        table => 'book',
3003
        primary_key => 'id',
3004
        where => '5',
3005
        param => {title => 'Perl'}
3006
    );
3007

            
3008
This method is same as C<insert()> exept that
3009
C<primary_key> is specified and C<where> is constant value or array refrence.
3010
all option of C<insert()> is available.
3011

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

            
3014
=head2 C<DBIX_CUSTOM_DEBUG>
3015

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

            
3019
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3020

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

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

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

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

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

            
3032
C<< <kimoto.yuki at gmail.com> >>
3033

            
3034
L<http://github.com/yuki-kimoto/DBIx-Custom>
3035

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3036
=head1 AUTHOR
3037

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

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

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

            
3044
This program is free software; you can redistribute it and/or modify it
3045
under the same terms as Perl itself.
3046

            
3047
=cut