DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3048 lines | 76.363kb
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} || {},
524
            type_rule => $self->type_rule,
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} ||= {};
992
        $self->each_column(sub {
993
            my ($dbi, $table, $column, $column_info) = @_;
994
            
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
995
            my $type_name = $column_info->{TYPE_NAME};
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
996
            if ($type_rule->{into} &&
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
997
                (my $filter = $type_rule->{into}->{$type_name}))
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
998
            {
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
999
                return unless exists $type_rule->{into}->{$type_name};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1000
                if  (defined $filter && ref $filter ne 'CODE') 
1001
                {
1002
                    my $fname = $filter;
1003
                    croak qq{Filter "$fname" is not registered" } . _subname
1004
                      unless exists $self->filters->{$fname};
1005
                    
1006
                    $filter = $self->filters->{$fname};
1007
                }
1008

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

            
1014
        # From
1015
        $type_rule->{from} = _array_to_hash($type_rule->{from});
1016
        foreach my $data_type (keys %{$type_rule->{from} || {}}) {
1017
            my $fname = $type_rule->{from}{$data_type};
1018
            if (defined $fname && ref $fname ne 'CODE') {
1019
                croak qq{Filter "$fname" is not registered" } . _subname
1020
                  unless exists $self->filters->{$fname};
1021
                
1022
                $type_rule->{from}{$data_type} = $self->filters->{$fname};
1023
            }
1024
        }
1025
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1026
        return $self;
1027
    }
1028
    
1029
    return $self->{type_rule} || {};
1030
}
1031

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1772
Filter when data is send or receive.
1773

            
1774
=item *
1775

            
1776
Data filtering system
1777

            
1778
=item *
1779

            
1780
Model support.
1781

            
1782
=item *
1783

            
1784
Generate where clause dinamically.
1785

            
1786
=item *
1787

            
1788
Generate join clause dinamically.
1789

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

            
1792
=head1 GUIDE
1793

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1839
=head2 C<default_dbi_option>
1840

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1921
    print $dbi->available_data_type;
1922

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

            
1926
=head2 C<available_type_name> EXPERIMENTAL
1927

            
1928
    print $dbi->available_type_name;
1929

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

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

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1939
    title = :title, author = :author
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
This is equal to C<update_param> exept that set is not added.
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1942

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2024
=head2 C<each_column>
2025

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

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

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

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

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

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

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

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

            
2060
=over 4
2061

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

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

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

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

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

            
2088
    query => 1
2089

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

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

            
2097
Table names for filtering.
2098

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

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

            
2104
Specify database data type.
2105

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

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

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

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

            
2116
=item C<type_rule_off> EXPERIMENTAL
2117

            
2118
    type_rule_off => 1
2119

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

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

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

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

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

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

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

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

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

            
2138
=item C<filter>
2139

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2180
=item C<type_rule_off> EXPERIMENTAL
2181

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

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

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

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

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

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

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

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

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

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

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

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

            
2207
=item C<filter>
2208

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

            
2211
=item C<id>
2212

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

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

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

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

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

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

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

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

            
2240
=item C<param>
2241

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

            
2244
Insert data.
2245

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

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

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

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

            
2255
=item C<table>
2256

            
2257
    table => 'book'
2258

            
2259
Table name.
2260

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

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

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

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

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

            
2271
=over 4
2272

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2333
Merge paramters.
2334

            
2335
$param:
2336

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2437
=over 4
2438

            
2439
=item 1. column name
2440

            
2441
    issue_date
2442
    issue_datetime
2443

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

            
2446
    book.issue_date
2447
    book.issue_datetime
2448

            
2449
=back
2450

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

            
2455
    print $dbi->available_data_type;
2456

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

            
2459
=item 1. column name
2460

            
2461
    issue_date
2462
    issue_datetime
2463

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

            
2466
    book.issue_date
2467
    book.issue_datetime
2468

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

            
2471
    book__issue_date
2472
    book__issue_datetime
2473

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

            
2476
    book-issue_date
2477
    book-issue_datetime
2478

            
2479
This is useful in HTML.
2480

            
2481
=back
2482

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

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

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

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

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

            
2507
=over 4
2508

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2554
=item C<id>
2555

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

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

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

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

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

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

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

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

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

            
2589
    prefix => 'SQL_CALC_FOUND_ROWS'
2590

            
2591
Prefix of column cluase
2592

            
2593
    select SQL_CALC_FOUND_ROWS title, author from book;
2594

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2667
Wrap statement. This is array reference.
2668

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2751
=item C<type_rule_off> EXPERIMENTAL
2752

            
2753
Turn type rule off.
2754

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

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

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

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

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

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

            
2768
Create update parameter tag.
2769

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

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

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

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

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

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

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

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

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

            
2792
Update statement, using primary key.
2793

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

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

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

            
2807
Delete statement, using primary key.
2808

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

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

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

            
2821
Select statement, using primary key.
2822

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

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

            
2833
=head2 C<register_tag> DEPRECATED!
2834

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

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

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

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

            
2855
    {update_param title author} 
2856

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

            
2861
In this example, result statement is 
2862

            
2863
    set title = ?, author = ?
2864

            
2865
Column names is
2866

            
2867
    ['title', 'author']
2868

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

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

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

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

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

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

            
2901
You can set multiple filters at once.
2902

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

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

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

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

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

            
2923
=head1 Tags DEPRECATED!
2924

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

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

            
2930
The following tags is available.
2931

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

            
2934
Placeholder tag.
2935

            
2936
    {? NAME}    ->   ?
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
Equal tag.
2941

            
2942
    {= NAME}    ->   NAME = ?
2943

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

            
2946
Not equal tag.
2947

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

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

            
2952
Lower than tag
2953

            
2954
    {< NAME}    ->   NAME < ?
2955

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

            
2958
Greater 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 or equal tag
2965

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

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

            
2970
Lower than or equal tag
2971

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

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

            
2976
Like tag
2977

            
2978
    {like NAME}   ->   NAME like ?
2979

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

            
2982
In tag.
2983

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

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

            
2988
Insert parameter tag.
2989

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

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

            
2994
Updata parameter tag.
2995

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

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

            
3000
Insert statement, using primary key.
3001

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

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

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

            
3015
=head2 C<DBIX_CUSTOM_DEBUG>
3016

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

            
3020
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3021

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

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

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

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

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

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

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

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

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

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

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

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

            
3048
=cut