DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3054 lines | 76.679kb
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);
added DBIx::Custom result_fi...
Yuki Kimoto authored on 2011-06-12
309
    my $result_filter = ref $model->result_filter eq 'HASH'
310
               ? [%{$model->result_filter}]
311
               : $model->result_filter;
312
    for (my $i = 1; $i < @$result_filter; $i += 2) {
313
        $result_filter->[$i] = {in => $result_filter->[$i]};
314
    }
cleanup
Yuki Kimoto authored on 2011-06-13
315
    $self->_apply_filter($model->table, @$result_filter);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
316
    
cleanup
Yuki Kimoto authored on 2011-04-02
317
    # Associate table with model
cleanup
Yuki Kimoto authored on 2011-04-25
318
    croak "Table name is duplicated " . _subname
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
319
      if exists $self->{_model_from}->{$model->table};
320
    $self->{_model_from}->{$model->table} = $model->name;
321

            
322
    # Table alias
323
    $self->{_table_alias} ||= {};
324
    $self->{_table_alias} = {%{$self->{_table_alias}}, %{$model->table_alias}};
325
    
326
    # Set model
327
    $self->model($model->name, $model);
328
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
329
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
330
}
331

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

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

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

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

            
527
        return $result;
528
    }
cleanup
Yuki Kimoto authored on 2011-04-02
529
    
530
    # Not select statement
531
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
532
}
533

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

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

            
556
    # Check arguments
557
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
558
        croak qq{"$name" is wrong option } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
559
          unless $INSERT_ARGS{$name};
560
    }
561

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
562
    # Merge parameter
563
    if ($id) {
cleanup
Yuki Kimoto authored on 2011-06-08
564
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
565
        $param = $self->merge_param($id_param, $param);
566
    }
567

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
607
sub include_model {
608
    my ($self, $name_space, $model_infos) = @_;
609
    
cleanup
Yuki Kimoto authored on 2011-04-02
610
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
611
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
612
    
613
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
614
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
615

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

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
696
sub method {
697
    my $self = shift;
698
    
cleanup
Yuki Kimoto authored on 2011-04-02
699
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
700
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
701
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
702
    
703
    return $self;
704
}
705

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
723
sub mycolumn {
724
    my ($self, $table, $columns) = @_;
725
    
cleanup
Yuki Kimoto authored on 2011-04-02
726
    # Create column clause
727
    my @column;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
728
    my $q = $self->reserved_word_quote;
cleanup
Yuki Kimoto authored on 2011-03-21
729
    $columns ||= [];
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
730
    push @column, "$q$table$q.$q$_$q as $q$_$q" for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
731
    
732
    return join (', ', @column);
733
}
734

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
765
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
766
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
767
    
768
    # Register filter
769
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
770
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
771
    
cleanup
Yuki Kimoto authored on 2011-04-02
772
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
773
}
packaging one directory
yuki-kimoto authored on 2009-11-16
774

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

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

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

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

            
added EXPERIMETNAL separator...
Yuki Kimoto authored on 2011-06-13
920
sub separator {
921
    my $self = shift;
922
    
923
    if (@_) {
924
        my $separator = $_[0] || '';
925
        croak qq{Separator must be "." or "__" or "-" } . _subname
926
          unless $separator eq '.' || $separator eq '__'
927
              || $separator eq '-';
928
        
929
        $self->{separator} = $separator;
930
    
931
        return $self;
932
    }
933
    return $self->{separator} ||= '.';
934
}
935

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

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

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

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

            
1013
                $self->{_into}{$table}{$column} = $filter;
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
1014
            }
1015
        });
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1016
        
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1017

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

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

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

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1114
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1115
    my ($self, $param, $opt) = @_;
1116
    
cleanup
Yuki Kimoto authored on 2011-04-02
1117
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1118
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1119
    $tag = "set $tag" unless $opt->{no_set};
1120

            
cleanup
Yuki Kimoto authored on 2011-04-02
1121
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1122
}
1123

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

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

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

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

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

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

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1324
sub _need_tables {
1325
    my ($self, $tree, $need_tables, $tables) = @_;
1326
    
cleanup
Yuki Kimoto authored on 2011-04-02
1327
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1328
    foreach my $table (@$tables) {
1329
        if ($tree->{$table}) {
1330
            $need_tables->{$table} = 1;
1331
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1332
        }
1333
    }
1334
}
1335

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1378
sub _remove_duplicate_table {
1379
    my ($self, $tables, $main_table) = @_;
1380
    
1381
    # Remove duplicate table
1382
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1383
    delete $tables{$main_table} if $main_table;
1384
    
1385
    return [keys %tables, $main_table ? $main_table : ()];
1386
}
1387

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1447
# DEPRECATED!
1448
sub apply_filter {
1449
    my $self = shift;
1450
    
1451
    warn "apply_filter is DEPRECATED! " . 
1452
         "use type_rule method, DBIx::Custom::Result filter method, " .
1453
         "and DBIx::Custom::Model result_filter method instead";
1454
    
1455
    return $self->_apply_filter(@_);
1456
}
1457

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1458
# DEPRECATED!
1459
our %SELECT_AT_ARGS = (%SELECT_ARGS, where => 1, primary_key => 1);
1460
sub select_at {
1461
    my ($self, %args) = @_;
1462

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

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

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1488
# DEPRECATED!
1489
our %DELETE_AT_ARGS = (%DELETE_ARGS, where => 1, primary_key => 1);
1490
sub delete_at {
1491
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1492

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1512
# DEPRECATED!
1513
our %UPDATE_AT_ARGS = (%UPDATE_ARGS, where => 1, primary_key => 1);
1514
sub update_at {
1515
    my $self = shift;
1516

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

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

            
added warnings
Yuki Kimoto authored on 2011-06-07
1571
# DEPRECATED!
1572
sub register_tag {
1573
    warn "register_tag is DEPRECATED!";
1574
    shift->query_builder->register_tag(@_)
1575
}
1576

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1577
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1578
has 'data_source';
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1579

            
cleanup
Yuki Kimoto authored on 2011-01-25
1580
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1581
has dbi_options => sub { {} },
1582
    filter_check  => 1;
1583

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1609
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1610
sub default_fetch_filter {
1611
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1612

            
cleanup
Yuki Kimoto authored on 2011-06-13
1613
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1614
    
1615
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1616
        my $fname = $_[0];
1617

            
cleanup
Yuki Kimoto authored on 2011-01-12
1618
        if (@_ && !$fname) {
1619
            $self->{default_in_filter} = undef;
1620
        }
1621
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1622
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1623
              unless exists $self->filters->{$fname};
1624
        
1625
            $self->{default_in_filter} = $self->filters->{$fname};
1626
        }
1627
        
1628
        return $self;
1629
    }
1630
    
many changed
Yuki Kimoto authored on 2011-01-23
1631
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1632
}
1633

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1634
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1635
sub insert_param_tag {
1636
    warn "insert_param_tag is DEPRECATED! " .
1637
         "use insert_param instead!";
1638
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1639
}
1640

            
cleanup
Yuki Kimoto authored on 2011-01-25
1641
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1642
sub register_tag_processor {
added warnings
Yuki Kimoto authored on 2011-06-07
1643
    warn "register_tag_processor is DEPRECATED!";
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1644
    return shift->query_builder->register_tag_processor(@_);
1645
}
1646

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1691
=head1 NAME
1692

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

            
1695
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1696

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

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

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

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

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

            
1765
=head1 FEATURES
removed reconnect method
yuki-kimoto authored on 2010-05-28
1766

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1776
=item *
1777

            
1778
Filter when data is send or receive.
1779

            
1780
=item *
1781

            
1782
Data filtering system
1783

            
1784
=item *
1785

            
1786
Model support.
1787

            
1788
=item *
1789

            
1790
Generate where clause dinamically.
1791

            
1792
=item *
1793

            
1794
Generate join clause dinamically.
1795

            
1796
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1797

            
1798
=head1 GUIDE
1799

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

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

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

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

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

            
1810
    my $connector = $dbi->connector;
1811
    $dbi          = $dbi->connector(DBIx::Connector->new(...));
1812

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

            
1816
This is L<DBIx::Connector> example. Please pass
1817
C<default_dbi_option> to L<DBIx::Connector>.
1818

            
1819
    my $connector = DBIx::Connector->new(
1820
        "dbi:mysql:database=$DATABASE",
1821
        $USER,
1822
        $PASSWORD,
1823
        DBIx::Custom->new->default_dbi_option
1824
    );
1825
    
1826
    my $dbi = DBIx::Custom->new(connector => $connector);
1827

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

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

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

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

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

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

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

            
1845
=head2 C<default_dbi_option>
1846

            
1847
    my $default_dbi_option = $dbi->default_dbi_option;
1848
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1849

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1853
    {
1854
        RaiseError => 1,
1855
        PrintError => 0,
1856
        AutoCommit => 1,
1857
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
1858

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

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

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

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

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

            
1871
    my $models = $dbi->models;
1872
    $dbi       = $dbi->models(\%models);
1873

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1876
=head2 C<password>
1877

            
1878
    my $password = $dbi->password;
1879
    $dbi         = $dbi->password('lkj&le`@s');
1880

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

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

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

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

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

            
1892
     my reserved_word_quote = $dbi->reserved_word_quote;
1893
     $dbi                   = $dbi->reserved_word_quote('"');
1894

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1914
    my $user = $dbi->user;
1915
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1916

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

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

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

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

            
1927
    print $dbi->available_data_type;
1928

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

            
1932
=head2 C<available_type_name> EXPERIMENTAL
1933

            
1934
    print $dbi->available_type_name;
1935

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

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

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

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

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

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

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

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

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

            
1955
    book.author as "book.author",
1956
    book.title as "book.title"
1957

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
1960
    # Separator is double underbar
1961
    $dbi->separator('__');
1962
    
1963
    book.author as "book__author",
1964
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
1965

            
cleanup
Yuki Kimoto authored on 2011-06-13
1966
    # Separator is hyphen
1967
    $dbi->separator('-');
1968
    
1969
    book.author as "book-author",
1970
    book.title as "book-title"
1971
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1972
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1973

            
update pod
Yuki Kimoto authored on 2011-03-13
1974
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1975
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
1976
        user => 'ken',
1977
        password => '!LFKD%$&',
1978
        dbi_option => {mysql_enable_utf8 => 1}
1979
    );
1980

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

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

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

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

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

            
2007
   $dbi->model('book')->select(...);
2008

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

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

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

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

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

            
2025
    my $dbh = $dbi->dbh;
2026

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

            
2030
=head2 C<each_column>
2031

            
2032
    $dbi->each_column(
2033
        sub {
2034
            my ($dbi, $table, $column, $column_info) = @_;
2035
            
2036
            my $type = $column_info->{TYPE_NAME};
2037
            
2038
            if ($type eq 'DATE') {
2039
                # ...
2040
            }
2041
        }
2042
    );
2043

            
2044
Iterate all column informations of all table from database.
2045
Argument is callback when one column is found.
2046
Callback receive four arguments, dbi object, table name,
2047
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2048

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

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

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

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

            
2062
    select * from where title = ? and author like ?;
2063

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

            
2066
=over 4
2067

            
2068
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2069
    
2070
    filter => {
2071
        title  => sub { uc $_[0] }
2072
        author => sub { uc $_[0] }
2073
    }
update pod
Yuki Kimoto authored on 2011-03-13
2074

            
updated pod
Yuki Kimoto authored on 2011-06-09
2075
    # Filter name
2076
    filter => {
2077
        title  => 'upper_case',
2078
        author => 'upper_case'
2079
    }
2080
        
2081
    # At once
2082
    filter => [
2083
        [qw/title author/]  => sub { uc $_[0] }
2084
    ]
2085

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

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

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

            
2094
    query => 1
2095

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2098
=item C<table>
2099
    
2100
    table => 'author'
2101
    table => ['author', 'book']
2102

            
2103
Table names for filtering.
2104

            
2105
Filtering by C<apply_filter> is off in C<execute> method,
2106
because we don't know what filter is applied.
2107

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

            
2110
Specify database data type.
2111

            
2112
    type => [image => DBI::SQL_BLOB]
2113
    type => [[qw/image audio/] => DBI::SQL_BLOB]
2114

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

            
2117
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2118

            
2119
C<type> option is also available
2120
by C<insert()>, C<update()>, C<delete()>, C<select()>.
2121

            
2122
=item C<type_rule_off> EXPERIMENTAL
2123

            
2124
    type_rule_off => 1
2125

            
2126
Trun type rule off.
update document
yuki-kimoto authored on 2009-11-19
2127

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2138
=over 4
2139

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

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

            
2144
=item C<filter>
2145

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2150
    id => 4
2151
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2152

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2156
    $dbi->delete(
2157
        parimary_key => ['id1', 'id2'],
2158
        id => [4, 5],
2159
        table => 'book',
2160
    );
update pod
Yuki Kimoto authored on 2011-03-13
2161

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

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

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

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

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

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

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

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

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

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

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

            
2184
Same as C<execute> method's C<type> option.
2185

            
2186
=item C<type_rule_off> EXPERIMENTAL
2187

            
2188
Same as C<execute> method's C<type_rule_off> option.
2189

            
updated pod
Yuki Kimoto authored on 2011-06-08
2190
=back
update pod
Yuki Kimoto authored on 2011-03-13
2191

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2199
=head2 C<insert>
2200

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

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

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

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

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

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

            
2213
=item C<filter>
2214

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

            
2217
=item C<id>
2218

            
updated document
Yuki Kimoto authored on 2011-06-09
2219
    id => 4
2220
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2221

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

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

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

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

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

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

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

            
2246
=item C<param>
2247

            
2248
    param => {title => 'Perl', author => 'Ken'}
2249

            
2250
Insert data.
2251

            
2252
If C<insert> method's arguments is odd numbers,
2253
first argument is received as C<param>.
2254

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

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

            
2259
Same as C<execute> method's C<query> option.
2260

            
2261
=item C<table>
2262

            
2263
    table => 'book'
2264

            
2265
Table name.
2266

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2275
=back
2276

            
2277
=over 4
2278

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2294
    lib / MyModel.pm
2295
        / MyModel / book.pm
2296
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2297

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

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

            
2302
    package MyModel;
2303
    
2304
    use base 'DBIx::Custom::Model';
update pod
Yuki Kimoto authored on 2011-03-13
2305
    
2306
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2307

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2312
    package MyModel::book;
2313
    
2314
    use base 'MyModel';
2315
    
2316
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2317

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2320
    package MyModel::company;
2321
    
2322
    use base 'MyModel';
2323
    
2324
    1;
2325
    
2326
MyModel::book and MyModel::company is included by C<include_model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2327

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

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

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

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

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

            
2339
Merge paramters.
2340

            
2341
$param:
2342

            
2343
    {key1 => [1, 1], key2 => 2}
2344

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

            
2347
    $dbi->method(
2348
        update_or_insert => sub {
2349
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2350
            
2351
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2352
        },
2353
        find_or_create   => sub {
2354
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2355
            
2356
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2357
        }
2358
    );
2359

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

            
2362
    $dbi->update_or_insert;
2363
    $dbi->find_or_create;
2364

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

            
2367
    $dbi->model('book')->method(
2368
        insert => sub { ... },
2369
        update => sub { ... }
2370
    );
2371
    
2372
    my $model = $dbi->model('book');
2373

            
2374
Set and get a L<DBIx::Custom::Model> object,
2375

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

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

            
2380
Create column clause for myself. The follwoing column clause is created.
2381

            
2382
    book.author as author,
2383
    book.title as title
2384

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2387
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2388
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2389
        user => 'ken',
2390
        password => '!LFKD%$&',
2391
        dbi_option => {mysql_enable_utf8 => 1}
2392
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2393

            
2394
Create a new L<DBIx::Custom> object.
2395

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

            
2398
    my $not_exists = $dbi->not_exists;
2399

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2403
=head2 C<register_filter>
2404

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

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

            
2422
    $dbi->type_rule(
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2423
        into => {
2424
            DATE => sub { ... },
2425
            DATETIME => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2426
        },
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2427
        from => {
2428
            # DATE
2429
            9 => sub { ... },
2430
            
2431
            # DATETIME or TIMESTAMP
2432
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2433
        }
2434
    );
2435

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

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

            
2443
=over 4
2444

            
2445
=item 1. column name
2446

            
2447
    issue_date
2448
    issue_datetime
2449

            
2450
=item 2. table name and column name, separator is dot
2451

            
2452
    book.issue_date
2453
    book.issue_datetime
2454

            
2455
=back
2456

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

            
2461
    print $dbi->available_data_type;
2462

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

            
2465
=item 1. column name
2466

            
2467
    issue_date
2468
    issue_datetime
2469

            
2470
=item 2. table name and column name, separator is dot
2471

            
2472
    book.issue_date
2473
    book.issue_datetime
2474

            
2475
=item 3. table name and column name, separator is double underbar
2476

            
2477
    book__issue_date
2478
    book__issue_datetime
2479

            
2480
=item 4. table name and column name, separator is hyphen
2481

            
2482
    book-issue_date
2483
    book-issue_datetime
2484

            
2485
This is useful in HTML.
2486

            
2487
=back
2488

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

            
2491
    $dbi->type_rule(
2492
        into => [
2493
            [qw/DATE DATETIME/] => sub { ... },
2494
        ],
2495
        from => {
2496
            # DATE
2497
            [qw/9 11/] => sub { ... },
2498
        }
2499
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2500

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2503
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2504
        table  => 'book',
2505
        column => ['author', 'title'],
2506
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2507
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2508
    
updated document
Yuki Kimoto authored on 2011-06-09
2509
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2510

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

            
2513
=over 4
2514

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2519
Append statement to last of SQL.
2520
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2521
=item C<column>
2522
    
updated document
Yuki Kimoto authored on 2011-06-09
2523
    column => 'author'
2524
    column => ['author', 'title']
2525

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2534
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2535
        {book => [qw/author title/]},
2536
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2537
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2538

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

            
2541
    book.author as "book.author",
2542
    book.title as "book.title",
2543
    person.name as "person.name",
2544
    person.age as "person.age"
2545

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2548
    column => [
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2549
        ['date(book.register_datetime)', as => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2550
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2551

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

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

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

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

            
2560
=item C<id>
2561

            
2562
    id => 4
2563
    id => [4, 5]
2564

            
2565
ID corresponding to C<primary_key>.
2566
You can select rows by C<id> and C<primary_key>.
2567

            
2568
    $dbi->select(
2569
        parimary_key => ['id1', 'id2'],
2570
        id => [4, 5],
2571
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2572
    );
2573

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2576
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2577
        where => {id1 => 4, id2 => 5},
2578
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2579
    );
2580
    
updated document
Yuki Kimoto authored on 2011-06-09
2581
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2582

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

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

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

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

            
2595
    prefix => 'SQL_CALC_FOUND_ROWS'
2596

            
2597
Prefix of column cluase
2598

            
2599
    select SQL_CALC_FOUND_ROWS title, author from book;
2600

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

            
2603
    join => [
2604
        'left outer join company on book.company_id = company_id',
2605
        'left outer join location on company.location_id = location.id'
2606
    ]
2607
        
2608
Join clause. If column cluase or where clause contain table name like "company.name",
2609
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
2610

            
2611
    $dbi->select(
2612
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
2613
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
2614
        where => {'company.name' => 'Orange'},
2615
        join => [
2616
            'left outer join company on book.company_id = company.id',
2617
            'left outer join location on company.location_id = location.id'
2618
        ]
2619
    );
2620

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2624
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
2625
    from book
2626
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
2627
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
2628

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2648
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
2649

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2654
=item C<where>
2655
    
2656
    # Hash refrence
2657
    where => {author => 'Ken', 'title' => 'Perl'}
2658
    
2659
    # DBIx::Custom::Where object
2660
    where => $dbi->where(
2661
        clause => ['and', 'author = :author', 'title like :title'],
2662
        param  => {author => 'Ken', title => '%Perl%'}
2663
    );
updated pod
Yuki Kimoto authored on 2011-06-08
2664

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2669
Where clause.
2670
    
improved pod
Yuki Kimoto authored on 2011-04-19
2671
=item C<wrap> EXPERIMENTAL
2672

            
2673
Wrap statement. This is array reference.
2674

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

            
2677
This option is for Oracle and SQL Server paging process.
2678

            
update pod
Yuki Kimoto authored on 2011-03-12
2679
=back
cleanup
Yuki Kimoto authored on 2011-03-08
2680

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2689
=over 4
2690

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2701
    id => 4
2702
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
2703

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
2707
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
2708
        {title => 'Perl', author => 'Ken'}
2709
        parimary_key => ['id1', 'id2'],
2710
        id => [4, 5],
2711
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2712
    );
update pod
Yuki Kimoto authored on 2011-03-13
2713

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2716
    $dbi->update(
2717
        {title => 'Perl', author => 'Ken'}
2718
        where => {id1 => 4, id2 => 5},
2719
        table => 'book'
2720
    );
update pod
Yuki Kimoto authored on 2011-03-13
2721

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2755
Same as C<execute> method's C<type> option.
2756

            
2757
=item C<type_rule_off> EXPERIMENTAL
2758

            
2759
Turn type rule off.
2760

            
updated pod
Yuki Kimoto authored on 2011-06-08
2761
=back
update pod
Yuki Kimoto authored on 2011-03-13
2762

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

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

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

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

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

            
2774
Create update parameter tag.
2775

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

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

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

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

            
2787
Create a new L<DBIx::Custom::Where> object.
2788

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

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

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

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

            
2798
Update statement, using primary key.
2799

            
2800
    $dbi->update_at(
2801
        table => 'book',
2802
        primary_key => 'id',
2803
        where => '5',
2804
        param => {title => 'Perl'}
2805
    );
2806

            
2807
This method is same as C<update()> exept that
2808
C<primary_key> is specified and C<where> is constant value or array refrence.
2809
all option of C<update()> is available.
2810

            
2811
=head2 C<delete_at()> DEPRECATED!
2812

            
2813
Delete statement, using primary key.
2814

            
2815
    $dbi->delete_at(
2816
        table => 'book',
2817
        primary_key => 'id',
2818
        where => '5'
2819
    );
2820

            
2821
This method is same as C<delete()> exept that
2822
C<primary_key> is specified and C<where> is constant value or array refrence.
2823
all option of C<delete()> is available.
2824

            
2825
=head2 C<select_at()> DEPRECATED!
2826

            
2827
Select statement, using primary key.
2828

            
2829
    $dbi->select_at(
2830
        table => 'book',
2831
        primary_key => 'id',
2832
        where => '5'
2833
    );
2834

            
2835
This method is same as C<select()> exept that
2836
C<primary_key> is specified and C<where> is constant value or array refrence.
2837
all option of C<select()> is available.
2838

            
2839
=head2 C<register_tag> DEPRECATED!
2840

            
2841
    $dbi->register_tag(
2842
        update => sub {
2843
            my @columns = @_;
2844
            
2845
            # Update parameters
2846
            my $s = 'set ';
2847
            $s .= "$_ = ?, " for @columns;
2848
            $s =~ s/, $//;
2849
            
2850
            return [$s, \@columns];
2851
        }
2852
    );
2853

            
2854
Register tag, used by C<execute()>.
2855

            
2856
See also L<Tags/Tags> about tag registered by default.
2857

            
2858
Tag parser receive arguments specified in tag.
2859
In the following tag, 'title' and 'author' is parser arguments
2860

            
2861
    {update_param title author} 
2862

            
2863
Tag parser must return array refrence,
2864
first element is the result statement, 
2865
second element is column names corresponding to place holders.
2866

            
2867
In this example, result statement is 
2868

            
2869
    set title = ?, author = ?
2870

            
2871
Column names is
2872

            
2873
    ['title', 'author']
2874

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

            
2877
    $dbi->apply_filter(
2878
        'book',
2879
        'issue_date' => {
2880
            out => 'tp_to_date',
2881
            in  => 'date_to_tp',
2882
            end => 'tp_to_displaydate'
2883
        },
2884
        'write_date' => {
2885
            out => 'tp_to_date',
2886
            in  => 'date_to_tp',
2887
            end => 'tp_to_displaydate'
2888
        }
2889
    );
2890

            
2891
Apply filter to columns.
2892
C<out> filter is executed before data is send to database.
2893
C<in> filter is executed after a row is fetch.
2894
C<end> filter is execute after C<in> filter is executed.
2895

            
2896
Filter is applied to the follwoing tree column name pattern.
2897

            
2898
       PETTERN         EXAMPLE
2899
    1. Column        : author
2900
    2. Table.Column  : book.author
2901
    3. Table__Column : book__author
2902
    4. Table-Column  : book-author
2903

            
2904
If column name is duplicate with other table,
2905
Main filter specified by C<table> option is used.
2906

            
2907
You can set multiple filters at once.
2908

            
2909
    $dbi->apply_filter(
2910
        'book',
2911
        [qw/issue_date write_date/] => {
2912
            out => 'tp_to_date',
2913
            in  => 'date_to_tp',
2914
            end => 'tp_to_displaydate'
2915
        }
2916
    );
2917

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2918
=head1 Parameter
2919

            
2920
Parameter start at ':'. This is replaced to place holoder
2921

            
2922
    $dbi->execute(
2923
        "select * from book where title = :title and author = :author"
2924
        param => {title => 'Perl', author => 'Ken'}
2925
    );
2926

            
2927
    "select * from book where title = ? and author = ?"
2928

            
2929
=head1 Tags DEPRECATED!
2930

            
2931
B<Tag> system is DEPRECATED! use parameter system :name instead.
2932
Parameter is simple and readable.
2933

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

            
2936
The following tags is available.
2937

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

            
2940
Placeholder tag.
2941

            
2942
    {? NAME}    ->   ?
2943

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

            
2946
Equal tag.
2947

            
2948
    {= NAME}    ->   NAME = ?
2949

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

            
2952
Not equal tag.
2953

            
2954
    {<> NAME}   ->   NAME <> ?
2955

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

            
2958
Lower than tag
2959

            
2960
    {< NAME}    ->   NAME < ?
2961

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

            
2964
Greater than tag
2965

            
2966
    {> NAME}    ->   NAME > ?
2967

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

            
2970
Greater than or equal tag
2971

            
2972
    {>= NAME}   ->   NAME >= ?
2973

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

            
2976
Lower than or equal tag
2977

            
2978
    {<= NAME}   ->   NAME <= ?
2979

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

            
2982
Like tag
2983

            
2984
    {like NAME}   ->   NAME like ?
2985

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

            
2988
In tag.
2989

            
2990
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
2991

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

            
2994
Insert parameter tag.
2995

            
2996
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
2997

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

            
3000
Updata parameter tag.
3001

            
3002
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
3003

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

            
3006
Insert statement, using primary key.
3007

            
3008
    $dbi->insert_at(
3009
        table => 'book',
3010
        primary_key => 'id',
3011
        where => '5',
3012
        param => {title => 'Perl'}
3013
    );
3014

            
3015
This method is same as C<insert()> exept that
3016
C<primary_key> is specified and C<where> is constant value or array refrence.
3017
all option of C<insert()> is available.
3018

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

            
3021
=head2 C<DBIX_CUSTOM_DEBUG>
3022

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

            
3026
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3027

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

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

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

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

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

            
3039
C<< <kimoto.yuki at gmail.com> >>
3040

            
3041
L<http://github.com/yuki-kimoto/DBIx-Custom>
3042

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3043
=head1 AUTHOR
3044

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

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

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

            
3051
This program is free software; you can redistribute it and/or modify it
3052
under the same terms as Perl itself.
3053

            
3054
=cut