DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3427 lines | 88.746kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2
use Object::Simple -base;
cleanup
yuki-kimoto authored on 2009-12-22
3

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
4
our $VERSION = '0.1717';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
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/;
cleanup
Yuki Kimoto authored on 2011-08-13
18
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
19

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

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

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
67
sub available_datatype {
test cleanup
Yuki Kimoto authored on 2011-08-10
68
    my $self = shift;
69
    
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
70
    my $data_types = '';
71
    foreach my $i (-1000 .. 1000) {
72
         my $type_info = $self->dbh->type_info($i);
73
         my $data_type = $type_info->{DATA_TYPE};
74
         my $type_name = $type_info->{TYPE_NAME};
75
         $data_types .= "$data_type ($type_name)\n"
76
           if defined $data_type;
77
    }
78
    return "Data Type maybe equal to Type Name" unless $data_types;
79
    $data_types = "Data Type (Type name)\n" . $data_types;
80
    return $data_types;
81
}
82

            
83
sub available_typename {
84
    my $self = shift;
85
    
86
    # Type Names
87
    my $type_names = {};
88
    $self->each_column(sub {
89
        my ($self, $table, $column, $column_info) = @_;
90
        $type_names->{$column_info->{TYPE_NAME}} = 1
91
          if $column_info->{TYPE_NAME};
92
    });
93
    my @output = sort keys %$type_names;
94
    unshift @output, "Type Name";
95
    return join "\n", @output;
test cleanup
Yuki Kimoto authored on 2011-08-10
96
}
97

            
added helper method
yuki-kimoto authored on 2010-10-17
98
our $AUTOLOAD;
99
sub AUTOLOAD {
100
    my $self = shift;
101

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
105
    # Call method
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
106
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
107
    if (my $method = $self->{_methods}->{$mname}) {
108
        return $self->$method(@_)
109
    }
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
110
    elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
111
        $self->dbh->$dbh_method(@_);
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
112
    }
113
    else {
cleanup
Yuki Kimoto authored on 2011-04-25
114
        croak qq{Can't locate object method "$mname" via "$package" }
115
            . _subname;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
116
    }
added helper method
yuki-kimoto authored on 2010-10-17
117
}
118

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
119
sub assign_param {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
120
    my ($self, $param) = @_;
121
    
122
    # Create set tag
123
    my @params;
124
    my $safety = $self->safety_character;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
125
    foreach my $column (sort keys %$param) {
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
126
        croak qq{"$column" is not safety column name } . _subname
127
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
128
        my $column_quote = $self->_q($column);
129
        $column_quote =~ s/\./$self->_q(".")/e;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
130
        push @params, ref $param->{$column} eq 'SCALAR'
131
          ? "$column_quote = " . ${$param->{$column}}
132
          : "$column_quote = :$column";
133

            
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
134
    }
135
    my $tag = join(', ', @params);
136
    
137
    return $tag;
138
}
139

            
cleanup
Yuki Kimoto authored on 2011-03-21
140
sub column {
- DBIx::Custom Model filter ...
Yuki Kimoto authored on 2011-06-15
141
    my $self = shift;
142
    my $option = pop if ref $_[-1] eq 'HASH';
143
    my $real_table = shift;
144
    my $columns = shift;
145
    my $table = $option->{alias} || $real_table;
146
    
147
    # Columns
148
    unless ($columns) {
149
        $columns ||= $self->model($real_table)->columns;
150
    }
added helper method
yuki-kimoto authored on 2010-10-17
151
    
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
152
    # Separator
153
    my $separator = $self->separator;
154
    
cleanup
Yuki Kimoto authored on 2011-04-02
155
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-21
156
    my @column;
cleanup
Yuki Kimoto authored on 2011-04-02
157
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
158
    push @column, $self->_q($table) . "." . $self->_q($_) .
159
      " as " . $self->_q("${table}${separator}$_")
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
160
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
161
    
162
    return join (', ', @column);
added helper method
yuki-kimoto authored on 2010-10-17
163
}
164

            
packaging one directory
yuki-kimoto authored on 2009-11-16
165
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
166
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
167
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
168
    # Connect
169
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
170
    
packaging one directory
yuki-kimoto authored on 2009-11-16
171
    return $self;
172
}
173

            
update pod
Yuki Kimoto authored on 2011-03-13
174
sub dbh {
175
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
176
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
177
    # Set
178
    if (@_) {
179
        $self->{dbh} = $_[0];
180
        
181
        return $self;
182
    }
183
    
184
    # Get
185
    else {
186
        # From Connction manager
187
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
188
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
189
              unless ref $connector && $connector->can('dbh');
190
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
191
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
192
        }
193
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
194
        # Connect
195
        $self->{dbh} ||= $self->_connect;
196
        
197
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
198
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
199
            my $driver = $self->_driver;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
200
            my $quote =  $driver eq 'odbc' ? '[]'
201
                       : $driver eq 'ado' ? '[]'
202
                       : $driver eq 'mysql' ? '`'
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
203
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
204
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
205
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
206
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
207
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
208
    }
209
}
210

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

            
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
214
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
215
    my $table = $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
216
    croak qq{"table" option must be specified. } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
217
      unless $table;
cleanup
Yuki Kimoto authored on 2011-03-21
218
    my $where            = delete $args{where} || {};
219
    my $append           = delete $args{append};
220
    my $allow_delete_all = delete $args{allow_delete_all};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
221
    my $where_param      = delete $args{where_param} || {};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
222
    my $id = delete $args{id};
223
    my $primary_key = delete $args{primary_key};
224
    croak "update method primary_key option " .
225
          "must be specified when id is specified " . _subname
226
      if defined $id && !defined $primary_key;
227
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
228
    my $prefix = delete $args{prefix};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
229
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
230
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
231
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
232
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
233
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
234
        $where_clause = "where " . $where->[0];
235
        $where_param = $where->[1];
236
    }
237
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
238
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
239
        $where_param = keys %$where_param
240
                     ? $self->merge_param($where_param, $where->param)
241
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
242
        
243
        # String where
244
        $where_clause = $where->to_string;
245
    }
246
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
247
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
248
      if $where_clause eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
249

            
cleanup
Yuki Kimoto authored on 2011-04-02
250
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
251
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
252
    push @sql, "delete";
253
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
254
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
255
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
256
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
257
    
258
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
259
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
260
}
261

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

            
added memory leak check test
Yuki Kimoto authored on 2011-08-15
264
sub DESTROY {}
added helper method
yuki-kimoto authored on 2010-10-17
265

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
266
sub create_model {
267
    my $self = shift;
268
    
cleanup
Yuki Kimoto authored on 2011-04-02
269
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
270
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
271
    $args->{dbi} = $self;
272
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
273
    my $model_name  = delete $args->{name};
274
    my $model_table = delete $args->{table};
275
    $model_name ||= $model_table;
276
    
cleanup
Yuki Kimoto authored on 2011-04-02
277
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
278
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
279
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
280
    $model->name($model_name) unless $model->name;
281
    $model->table($model_table) unless $model->table;
282
    
micro optimization
Yuki Kimoto authored on 2011-07-30
283
    # Apply filter(DEPRECATED logic)
284
    if ($model->{filter}) {
285
        my $filter = ref $model->filter eq 'HASH'
286
                   ? [%{$model->filter}]
287
                   : $model->filter;
288
        $filter ||= [];
289
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
290
          if @$filter;
291
        $self->_apply_filter($model->table, @$filter);
292
    }
293
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
294
    # Set model
295
    $self->model($model->name, $model);
296
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
297
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
298
}
299

            
300
sub each_column {
301
    my ($self, $cb) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
302

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
303
    my $re = $self->exclude_table;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
304
    
cleanup
Yuki Kimoto authored on 2011-08-15
305
    # Tables
added SQL Server test
Yuki Kimoto authored on 2011-08-14
306
    my %tables;
cleanup
Yuki Kimoto authored on 2011-08-15
307
    $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
308

            
309
    # Iterate all tables
310
    my @tables = sort keys %tables;
311
    for (my $i = 0; $i < @tables; $i++) {
312
        my $table = $tables[$i];
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
313
        
314
        # Iterate all columns
cleanup test
Yuki Kimoto authored on 2011-08-16
315
        my $sth_columns;
316
        eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
317
        next if $@;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
318
        while (my $column_info = $sth_columns->fetchrow_hashref) {
319
            my $column = $column_info->{COLUMN_NAME};
320
            $self->$cb($table, $column, $column_info);
321
        }
322
    }
323
}
324

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
325
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
326
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
327
    
cleanup test
Yuki Kimoto authored on 2011-08-16
328
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
329
    
added test
Yuki Kimoto authored on 2011-08-16
330
    # Iterate tables
331
    if ($user_table_infos) {
332
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
333
    }
334
    else {
335
        my $re = $self->exclude_table || $option{exclude};
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
            next if defined $re && $table =~ /$re/;
342
            $self->$cb($table, $table_info);
343
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
344
    }
345
}
346

            
simplified arguments check
Yuki Kimoto authored on 2011-07-11
347
our %VALID_ARGS = map { $_ => 1 } qw/append allow_delete_all
348
  allow_update_all bind_type column filter id join param prefix primary_key
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
349
  query relation sqlfilter table table_alias type type_rule_off type_rule1_off
simplified arguments check
Yuki Kimoto authored on 2011-07-11
350
  type_rule2_off wrap/;
cleanup
Yuki Kimoto authored on 2011-04-02
351

            
352
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
353
    my $self = shift;
354
    my $query = shift;
355
    my $param;
356
    $param = shift if @_ % 2;
357
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
358
    
cleanup
Yuki Kimoto authored on 2011-04-02
359
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
360
    my $p = delete $args{param} || {};
361
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
362
    my $tables = delete $args{table} || [];
363
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
364
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
365
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
366
    my $bind_type = delete $args{bind_type} || delete $args{type};
367
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
368
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
369
    my $type_rule_off_parts = {
370
        1 => delete $args{type_rule1_off},
371
        2 => delete $args{type_rule2_off}
372
    };
cleanup
Yuki Kimoto authored on 2011-06-09
373
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
374
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
375
    my $sqlfilter = $args{sqlfilter};
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
376
    
cleanup
Yuki Kimoto authored on 2011-03-09
377
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
378
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
379
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
380
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
381
    }
382
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
383
    $query = $self->_create_query($query, $sqlfilter) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
384
    
385
    # Save query
386
    $self->last_sql($query->sql);
387

            
cleanup
Yuki Kimoto authored on 2011-06-09
388
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
389
    
390
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
391
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
392
    
cleanup
Yuki Kimoto authored on 2011-04-02
393
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
394
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
395
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
396
    
micro optimization
Yuki Kimoto authored on 2011-07-30
397
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
398
    $tables = $self->_remove_duplicate_table($tables, $main_table)
399
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
400
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
401
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
402
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
403
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
404
        foreach my $i (1, 2) {
405
            unless ($type_rule_off_parts->{$i}) {
406
                $type_filters->{$i} = {};
407
                foreach my $alias (keys %$table_alias) {
408
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
409
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
410
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
411
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
412
                    }
413
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
414
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
415
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
416
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
417
        }
418
    }
cleanup
Yuki Kimoto authored on 2011-04-02
419
    
micro optimization
Yuki Kimoto authored on 2011-07-30
420
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
421
    if ($self->{filter}{on}) {
422
        my $applied_filter = {};
423
        foreach my $table (@$tables) {
424
            $applied_filter = {
425
                %$applied_filter,
426
                %{$self->{filter}{out}->{$table} || {}}
427
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
428
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
429
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
430
    }
431
    
cleanup
Yuki Kimoto authored on 2011-04-02
432
    # Replace filter name to code
433
    foreach my $column (keys %$filter) {
434
        my $name = $filter->{$column};
435
        if (!defined $name) {
436
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
437
        }
cleanup
Yuki Kimoto authored on 2011-04-02
438
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
439
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
440
            unless exists $self->filters->{$name};
441
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
442
        }
443
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
444
    
cleanup
Yuki Kimoto authored on 2011-04-02
445
    # Create bind values
446
    my $bind = $self->_create_bind_values(
447
        $param,
448
        $query->columns,
449
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
450
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
451
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
452
    );
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
453

            
cleanup
yuki-kimoto authored on 2010-10-17
454
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
455
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
456
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
457
    eval {
458
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
459
            my $bind_type = $bind->[$i]->{bind_type};
460
            $sth->bind_param(
461
                $i + 1,
462
                $bind->[$i]->{value},
463
                $bind_type ? $bind_type : ()
464
            );
cleanup
Yuki Kimoto authored on 2011-03-21
465
        }
466
        $affected = $sth->execute;
467
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
468
    
micro optimization
Yuki Kimoto authored on 2011-07-30
469
    $self->_croak($@, qq{. Following SQL is executed.\n}
470
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
471
    
improved debug message
Yuki Kimoto authored on 2011-05-23
472
    # DEBUG message
473
    if (DEBUG) {
474
        print STDERR "SQL:\n" . $query->sql . "\n";
475
        my @output;
476
        foreach my $b (@$bind) {
477
            my $value = $b->{value};
478
            $value = 'undef' unless defined $value;
479
            $value = encode(DEBUG_ENCODING(), $value)
480
              if utf8::is_utf8($value);
481
            push @output, $value;
482
        }
483
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
484
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
485
    
cleanup
Yuki Kimoto authored on 2011-04-02
486
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
487
    if ($sth->{NUM_OF_FIELDS}) {
488
        
micro optimization
Yuki Kimoto authored on 2011-07-30
489
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
490
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
491
        if ($self->{filter}{on}) {
492
            $filter->{in}  = {};
493
            $filter->{end} = {};
494
            push @$tables, $main_table if $main_table;
495
            foreach my $table (@$tables) {
496
                foreach my $way (qw/in end/) {
497
                    $filter->{$way} = {
498
                        %{$filter->{$way}},
499
                        %{$self->{filter}{$way}{$table} || {}}
500
                    };
501
                }
cleanup
Yuki Kimoto authored on 2011-04-02
502
            }
cleanup
Yuki Kimoto authored on 2011-01-12
503
        }
504
        
505
        # Result
506
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
507
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
508
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
509
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
510
            filter => $filter->{in} || {},
511
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
512
            type_rule => {
513
                from1 => $self->type_rule->{from1},
514
                from2 => $self->type_rule->{from2}
515
            },
cleanup
yuki-kimoto authored on 2010-10-17
516
        );
517

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

            
added test
Yuki Kimoto authored on 2011-08-16
525
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
526
    my ($self, %args) = @_;
527
    
528
    my $exclude = delete $args{exclude};
529
    croak qq/"$_" is wrong option/ for keys %args;
530
    
added test
Yuki Kimoto authored on 2011-08-16
531
    my $table_info = [];
532
    $self->each_table(
533
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
534
        exclude => $exclude
535
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
536
    
cleanup test
Yuki Kimoto authored on 2011-08-16
537
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
538
}
539

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
567
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
568
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
569
    push @sql, "insert";
570
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
571
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
572
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
573
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
574
    
575
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
576
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
577
}
578

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

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

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
665
sub map_param {
666
    my $self = shift;
667
    my $param = shift;
668
    my %map = @_;
669
    
670
    # Mapping
671
    my $map_param = {};
672
    foreach my $key (keys %map) {
673
        my $value_cb;
674
        my $condition;
675
        my $map_key;
676
        
677
        # Get mapping information
678
        if (ref $map{$key} eq 'ARRAY') {
679
            foreach my $some (@{$map{$key}}) {
680
                $map_key = $some unless ref $some;
681
                $condition = $some->{if} if ref $some eq 'HASH';
682
                $value_cb = $some if ref $some eq 'CODE';
683
            }
684
        }
685
        else {
686
            $map_key = $map{$key};
687
        }
688
        $value_cb ||= sub { $_[0] };
689
        $condition ||= sub { defined $_[0] && length $_[0] };
690

            
691
        # Map parameter
692
        my $value;
693
        if (ref $condition eq 'CODE') {
694
            $map_param->{$map_key} = $value_cb->($param->{$key})
695
              if $condition->($param->{$key});
696
        }
697
        elsif ($condition eq 'exists') {
698
            $map_param->{$map_key} = $value_cb->($param->{$key})
699
              if exists $param->{$key};
700
        }
701
        else { croak qq/Condition must be code reference or "exists" / . _subname }
702
    }
703
    
704
    return $map_param;
705
}
706

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
707
sub merge_param {
708
    my ($self, @params) = @_;
709
    
cleanup
Yuki Kimoto authored on 2011-04-02
710
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
711
    my $merge = {};
712
    foreach my $param (@params) {
713
        foreach my $column (keys %$param) {
714
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
715
            
716
            if (exists $merge->{$column}) {
717
                $merge->{$column} = [$merge->{$column}]
718
                  unless ref $merge->{$column} eq 'ARRAY';
719
                push @{$merge->{$column}},
720
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
721
            }
722
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
723
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
724
            }
725
        }
726
    }
727
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
728
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
729
}
730

            
cleanup
Yuki Kimoto authored on 2011-03-21
731
sub method {
732
    my $self = shift;
733
    
cleanup
Yuki Kimoto authored on 2011-04-02
734
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
735
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
736
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
737
    
738
    return $self;
739
}
740

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
741
sub model {
742
    my ($self, $name, $model) = @_;
743
    
cleanup
Yuki Kimoto authored on 2011-04-02
744
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
745
    if ($model) {
746
        $self->models->{$name} = $model;
747
        return $self;
748
    }
749
    
750
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
751
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
752
      unless $self->models->{$name};
753
    
cleanup
Yuki Kimoto authored on 2011-04-02
754
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
755
    return $self->models->{$name};
756
}
757

            
cleanup
Yuki Kimoto authored on 2011-03-21
758
sub mycolumn {
759
    my ($self, $table, $columns) = @_;
760
    
cleanup
Yuki Kimoto authored on 2011-04-02
761
    # Create column clause
762
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
763
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
764
    push @column, $self->_q($table) . "." . $self->_q($_) .
765
      " as " . $self->_q($_)
766
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
767
    
768
    return join (', ', @column);
769
}
770

            
added dbi_options attribute
kimoto authored on 2010-12-20
771
sub new {
772
    my $self = shift->SUPER::new(@_);
773
    
cleanup
Yuki Kimoto authored on 2011-04-02
774
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
775
    my @attrs = keys %$self;
776
    foreach my $attr (@attrs) {
cleanup
Yuki Kimoto authored on 2011-04-25
777
        croak qq{"$attr" is wrong name } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
778
          unless $self->can($attr);
779
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
780

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
781
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
782
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
783
        '?'     => \&DBIx::Custom::Tag::placeholder,
784
        '='     => \&DBIx::Custom::Tag::equal,
785
        '<>'    => \&DBIx::Custom::Tag::not_equal,
786
        '>'     => \&DBIx::Custom::Tag::greater_than,
787
        '<'     => \&DBIx::Custom::Tag::lower_than,
788
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
789
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
790
        'like'  => \&DBIx::Custom::Tag::like,
791
        'in'    => \&DBIx::Custom::Tag::in,
792
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
793
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
794
    };
795
    
796
    return $self;
797
}
798

            
799
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
800
sub not_exists { $not_exists }
801

            
802
sub order {
803
    my $self = shift;
804
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
805
}
806

            
cleanup
yuki-kimoto authored on 2010-10-17
807
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
808
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
809
    
810
    # Register filter
811
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
812
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
813
    
cleanup
Yuki Kimoto authored on 2011-04-02
814
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
815
}
packaging one directory
yuki-kimoto authored on 2009-11-16
816

            
817
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
818
    my ($self, %args) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
819

            
refactoring select
yuki-kimoto authored on 2010-04-28
820
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
821
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
822
    my $tables = ref $table eq 'ARRAY' ? $table
823
               : defined $table ? [$table]
824
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
825
    my $columns   = delete $args{column};
826
    my $where     = delete $args{where} || {};
827
    my $append    = delete $args{append};
828
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
829
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
830
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
831
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
832
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
833
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
834
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
835
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
836
      if keys %$param;
837
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
838
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
839
    my $id = delete $args{id};
840
    my $primary_key = delete $args{primary_key};
841
    croak "update method primary_key option " .
842
          "must be specified when id is specified " . _subname
843
      if defined $id && !defined $primary_key;
844
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
845
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
846
    
cleanup
Yuki Kimoto authored on 2011-03-09
847
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
848
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
849
    
cleanup
Yuki Kimoto authored on 2011-04-02
850
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
851
    my @sql;
852
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
853
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
854
    # Prefix
855
    push @sql, $prefix if defined $prefix;
856
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
857
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
858
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
859
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
860
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
861
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
862
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
863
            }
864
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
865
                if (@$column == 3 && $column->[1] eq 'as') {
866
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
867
                    splice @$column, 1, 1;
868
                }
869
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
870
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
871
            }
cleanup
Yuki Kimoto authored on 2011-04-02
872
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
873
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
874
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
875
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
876
    }
877
    else { push @sql, '*' }
878
    
879
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
880
    push @sql, 'from';
881
    if ($relation) {
882
        my $found = {};
883
        foreach my $table (@$tables) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
884
            push @sql, ($self->_q($table), ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
885
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
886
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
887
    }
cleanup
Yuki Kimoto authored on 2011-03-30
888
    else {
889
        my $main_table = $tables->[-1] || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
890
        push @sql, $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
891
    }
892
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
893
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
894
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
895

            
cleanup
Yuki Kimoto authored on 2011-04-02
896
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
897
    unshift @$tables,
898
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
899
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
900
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
901
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
902
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
903
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
904
        $where_clause = "where " . $where->[0];
905
        $where_param = $where->[1];
906
    }
907
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
908
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
909
        $where_param = keys %$where_param
910
                     ? $self->merge_param($where_param, $where->param)
911
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
912
        
913
        # String where
914
        $where_clause = $where->to_string;
915
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
916
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
917
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
918
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
919
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
920
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
921
    # Push join
922
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
923
    
cleanup
Yuki Kimoto authored on 2011-03-09
924
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
925
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
926
    
cleanup
Yuki Kimoto authored on 2011-03-08
927
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
928
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
929
    
cleanup
Yuki Kimoto authored on 2011-04-02
930
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
931
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
932
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
933
    # Wrap
934
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
935
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
936
          unless ref $wrap eq 'ARRAY';
937
        unshift @sql, $wrap->[0];
938
        push @sql, $wrap->[1];
939
    }
940
    
cleanup
Yuki Kimoto authored on 2011-01-27
941
    # SQL
942
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
943
    
944
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
945
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
946
    
947
    return $result;
948
}
949

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
950
sub setup_model {
951
    my $self = shift;
952
    
cleanup
Yuki Kimoto authored on 2011-04-02
953
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
954
    $self->each_column(
955
        sub {
956
            my ($self, $table, $column, $column_info) = @_;
957
            if (my $model = $self->models->{$table}) {
958
                push @{$model->columns}, $column;
959
            }
960
        }
961
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
962
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
963
}
964

            
update pod
Yuki Kimoto authored on 2011-08-10
965
sub show_datatype {
966
    my ($self, $table) = @_;
967
    croak "Table name must be specified" unless defined $table;
968
    print "$table\n";
969
    
970
    my $result = $self->select(table => $table, where => "'0' <> '0'");
971
    my $sth = $result->sth;
972

            
973
    my $columns = $sth->{NAME};
974
    my $data_types = $sth->{TYPE};
975
    
976
    for (my $i = 0; $i < @$columns; $i++) {
977
        my $column = $columns->[$i];
978
        my $data_type = $data_types->[$i];
979
        print "$column: $data_type\n";
980
    }
981
}
982

            
983
sub show_typename {
984
    my ($self, $t) = @_;
985
    croak "Table name must be specified" unless defined $t;
986
    print "$t\n";
987
    
988
    $self->each_column(sub {
989
        my ($self, $table, $column, $infos) = @_;
990
        return unless $table eq $t;
991
        my $typename = $infos->{TYPE_NAME};
992
        print "$column: $typename\n";
993
    });
994
    
995
    return $self;
996
}
997

            
test cleanup
Yuki Kimoto authored on 2011-08-15
998
sub show_tables {
999
    my $self = shift;
1000
    
1001
    my %tables;
1002
    $self->each_table(sub { $tables{$_[1]}++ });
1003
    print join("\n", sort keys %tables) . "\n";
1004
    return $self;
1005
}
1006

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1007
sub type_rule {
1008
    my $self = shift;
1009
    
1010
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1011
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1012
        
1013
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1014
        foreach my $i (1 .. 2) {
1015
            my $into = "into$i";
1016
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1017
            $self->{type_rule} = $type_rule;
1018
            $self->{"_$into"} = {};
1019
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1020
                croak qq{type name of $into section must be lower case}
1021
                  if $type_name =~ /[A-Z]/;
1022
            }
1023
            $self->each_column(sub {
1024
                my ($dbi, $table, $column, $column_info) = @_;
1025
                
1026
                my $type_name = lc $column_info->{TYPE_NAME};
1027
                if ($type_rule->{$into} &&
1028
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1029
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1030
                    return unless exists $type_rule->{$into}->{$type_name};
1031
                    if  (defined $filter && ref $filter ne 'CODE') 
1032
                    {
1033
                        my $fname = $filter;
1034
                        croak qq{Filter "$fname" is not registered" } . _subname
1035
                          unless exists $self->filters->{$fname};
1036
                        
1037
                        $filter = $self->filters->{$fname};
1038
                    }
1039

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1040
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1041
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1042
                }
1043
            });
1044
        }
1045

            
1046
        # From
1047
        foreach my $i (1 .. 2) {
1048
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1049
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1050
                croak qq{data type of from$i section must be lower case or number}
1051
                  if $data_type =~ /[A-Z]/;
1052
                my $fname = $type_rule->{"from$i"}{$data_type};
1053
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1054
                    croak qq{Filter "$fname" is not registered" } . _subname
1055
                      unless exists $self->filters->{$fname};
1056
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1057
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1058
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1059
            }
1060
        }
1061
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1062
        return $self;
1063
    }
1064
    
1065
    return $self->{type_rule} || {};
1066
}
1067

            
cleanup
yuki-kimoto authored on 2010-10-17
1068
sub update {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1069
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1070

            
cleanup
yuki-kimoto authored on 2010-10-17
1071
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1072
    my $param;
1073
    $param = shift if @_ % 2;
1074
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1075
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1076
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1077
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1078
    my $p = delete $args{param} || {};
1079
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1080
    my $where = delete $args{where} || {};
1081
    my $where_param = delete $args{where_param} || {};
1082
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1083
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1084
    my $id = delete $args{id};
1085
    my $primary_key = delete $args{primary_key};
1086
    croak "update method primary_key option " .
1087
          "must be specified when id is specified " . _subname
1088
      if defined $id && !defined $primary_key;
1089
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1090
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1091

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

            
1095
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1096
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1097
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1098
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1099
        $where_clause = "where " . $where->[0];
1100
        $where_param = $where->[1];
1101
    }
1102
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1103
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1104
        $where_param = keys %$where_param
1105
                     ? $self->merge_param($where_param, $where->param)
1106
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1107
        
1108
        # String where
1109
        $where_clause = $where->to_string;
1110
    }
1111
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1112
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1113
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1114
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1115
    # Merge param
1116
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1117
    
cleanup
Yuki Kimoto authored on 2011-04-02
1118
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1119
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1120
    push @sql, "update";
1121
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1122
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1123
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1124
    
cleanup
Yuki Kimoto authored on 2011-01-27
1125
    # SQL
1126
    my $sql = join(' ', @sql);
1127
    
cleanup
yuki-kimoto authored on 2010-10-17
1128
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1129
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1130
}
1131

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1134
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1135
    my ($self, $param, $opt) = @_;
1136
    
cleanup
Yuki Kimoto authored on 2011-04-02
1137
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1138
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1139
    $tag = "set $tag" unless $opt->{no_set};
1140

            
cleanup
Yuki Kimoto authored on 2011-04-02
1141
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1142
}
1143

            
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
1144
sub where { DBIx::Custom::Where->new(dbi => shift, @_) }
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
1145

            
updated pod
Yuki Kimoto authored on 2011-06-21
1146
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1147
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1148
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1149
    
updated pod
Yuki Kimoto authored on 2011-06-21
1150
    # Cache
1151
    my $cache = $self->cache;
1152
    
1153
    # Query
1154
    my $query;
1155
    
1156
    # Get cached query
1157
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1158
        
updated pod
Yuki Kimoto authored on 2011-06-21
1159
        # Get query
1160
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1161
        
updated pod
Yuki Kimoto authored on 2011-06-21
1162
        # Create query
1163
        if ($q) {
1164
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1165
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1166
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1167
    }
1168
    
1169
    # Create query
1170
    unless ($query) {
1171

            
1172
        # Create query
1173
        my $builder = $self->query_builder;
1174
        $query = $builder->build_query($source);
1175

            
1176
        # Remove reserved word quote
1177
        if (my $q = $self->_quote) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1178
            $q = quotemeta($q);
1179
            $_ =~ s/[$q]//g for @{$query->columns}
cleanup
Yuki Kimoto authored on 2011-06-13
1180
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1181

            
1182
        # Save query to cache
1183
        $self->cache_method->(
1184
            $self, $source,
1185
            {
1186
                sql     => $query->sql, 
1187
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1188
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1189
            }
1190
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1191
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1192

            
1193
    # Filter SQL
1194
    if ($sqlfilter) {
1195
        my $sql = $query->sql;
1196
        $sql = $sqlfilter->($sql);
1197
        $query->sql($sql);
1198
    }
1199
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1200
    # Save sql
1201
    $self->last_sql($query->sql);
1202
    
updated pod
Yuki Kimoto authored on 2011-06-21
1203
    # Prepare statement handle
1204
    my $sth;
1205
    eval { $sth = $self->dbh->prepare($query->{sql})};
1206
    
1207
    if ($@) {
1208
        $self->_croak($@, qq{. Following SQL is executed.\n}
1209
                        . qq{$query->{sql}\n} . _subname);
1210
    }
1211
    
1212
    # Set statement handle
1213
    $query->sth($sth);
1214
    
1215
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1216
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1217
    
1218
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1219
}
1220

            
cleanup
Yuki Kimoto authored on 2011-04-02
1221
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1222
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1223
    
cleanup
Yuki Kimoto authored on 2011-04-02
1224
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1225
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1226
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1227
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1228
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1229
        
1230
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1231
        my $value;
1232
        if(ref $params->{$column} eq 'ARRAY') {
1233
            my $i = $count->{$column} || 0;
1234
            $i += $not_exists->{$column} || 0;
1235
            my $found;
1236
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1237
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1238
                    $not_exists->{$column}++;
1239
                }
1240
                else  {
1241
                    $value = $params->{$column}->[$k];
1242
                    $found = 1;
1243
                    last
1244
                }
1245
            }
1246
            next unless $found;
1247
        }
1248
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1249
        
cleanup
Yuki Kimoto authored on 2011-01-12
1250
        # Filter
1251
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1252
        $value = $f->($value) if $f;
1253
        
1254
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1255
        foreach my $i (1 .. 2) {
1256
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1257
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1258
            $value = $tf->($value) if $tf;
1259
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1260
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1261
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1262
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1263
        
1264
        # Count up 
1265
        $count->{$column}++;
1266
    }
1267
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1268
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1269
}
1270

            
cleanup
Yuki Kimoto authored on 2011-06-08
1271
sub _create_param_from_id {
1272
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1273
    
cleanup
Yuki Kimoto authored on 2011-06-08
1274
    # Create parameter
1275
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1276
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1277
        $id = [$id] unless ref $id;
1278
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1279
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1280
          unless !ref $id || ref $id eq 'ARRAY';
1281
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1282
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1283
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1284
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1285
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1286
        }
1287
    }
1288
    
cleanup
Yuki Kimoto authored on 2011-06-08
1289
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1290
}
1291

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1292
sub _connect {
1293
    my $self = shift;
1294
    
1295
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1296
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1297
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1298
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1299
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1300
    croak qq{"dsn" must be specified } . _subname
1301
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1302
    my $user        = $self->user;
1303
    my $password    = $self->password;
1304
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1305
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1306
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1307
    
1308
    # Connect
1309
    my $dbh = eval {DBI->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1310
        $dsn,
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1311
        $user,
1312
        $password,
1313
        {
1314
            %{$self->default_dbi_option},
1315
            %$dbi_option
1316
        }
1317
    )};
1318
    
1319
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1320
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1321
    
1322
    return $dbh;
1323
}
1324

            
cleanup
yuki-kimoto authored on 2010-10-17
1325
sub _croak {
1326
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1327
    
1328
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1329
    $append ||= "";
1330
    
1331
    # Verbose
1332
    if ($Carp::Verbose) { croak $error }
1333
    
1334
    # Not verbose
1335
    else {
1336
        
1337
        # Remove line and module infromation
1338
        my $at_pos = rindex($error, ' at ');
1339
        $error = substr($error, 0, $at_pos);
1340
        $error =~ s/\s+$//;
1341
        croak "$error$append";
1342
    }
1343
}
1344

            
prepare oracle test
Yuki Kimoto authored on 2011-08-15
1345
sub _driver { lc shift->{dbh}->{Driver}->{Name} }
1346

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1347
sub _need_tables {
1348
    my ($self, $tree, $need_tables, $tables) = @_;
1349
    
cleanup
Yuki Kimoto authored on 2011-04-02
1350
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1351
    foreach my $table (@$tables) {
1352
        if ($tree->{$table}) {
1353
            $need_tables->{$table} = 1;
1354
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1355
        }
1356
    }
1357
}
1358

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1359
sub _push_join {
1360
    my ($self, $sql, $join, $join_tables) = @_;
1361
    
cleanup
Yuki Kimoto authored on 2011-04-02
1362
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1363
    return unless @$join;
1364
    
cleanup
Yuki Kimoto authored on 2011-04-02
1365
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1366
    my $tree = {};
1367
    for (my $i = 0; $i < @$join; $i++) {
1368
        
cleanup
Yuki Kimoto authored on 2011-07-28
1369
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1370
        my $join_clause;;
1371
        my $option;
1372
        if (ref $join->[$i] eq 'HASH') {
1373
            $join_clause = $join->[$i]->{clause};
1374
            $option = {table => $join->[$i]->{table}};
1375
        }
1376
        else {
1377
            $join_clause = $join->[$i];
1378
            $option = {};
1379
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1380

            
1381
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1382
        my $table1;
1383
        my $table2;
1384
        if (my $table = $option->{table}) {
1385
            $table1 = $table->[0];
1386
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1387
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1388
        else {
1389
            my $q = $self->_quote;
1390
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1391
            $j_clause =~ s/'.+?'//g;
1392
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1393
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1394
            my $c = $self->safety_character;
1395
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1396
            if ($j_clause =~ $join_re) {
1397
                $table1 = $1;
1398
                $table2 = $2;
1399
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1400
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1401
        croak qq{join clause must have two table name after "on" keyword. } .
1402
              qq{"$join_clause" is passed }  . _subname
1403
          unless defined $table1 && defined $table2;
1404
        croak qq{right side table of "$join_clause" must be unique }
1405
            . _subname
1406
          if exists $tree->{$table2};
1407
        croak qq{Same table "$table1" is specified} . _subname
1408
          if $table1 eq $table2;
1409
        $tree->{$table2}
1410
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1411
    }
1412
    
cleanup
Yuki Kimoto authored on 2011-04-02
1413
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1414
    my $need_tables = {};
1415
    $self->_need_tables($tree, $need_tables, $join_tables);
1416
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1417
    
1418
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1419
    foreach my $need_table (@need_tables) {
1420
        push @$sql, $tree->{$need_table}{join};
1421
    }
1422
}
cleanup
Yuki Kimoto authored on 2011-03-08
1423

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1424
sub _quote {
1425
    my $self = shift;
1426
    
1427
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1428
         : defined $self->quote ? $self->quote
1429
         : '';
1430
}
1431

            
cleanup
Yuki Kimoto authored on 2011-07-29
1432
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1433
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1434
    
1435
    my $quote = $self->_quote;
1436
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1437
    my $p;
1438
    if (defined $quote && length $quote > 1) {
1439
        $p = substr($quote, 1, 1);
1440
    }
1441
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1442
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1443
    if ($quotemeta) {
1444
        $q = quotemeta($q);
1445
        $p = quotemeta($p);
1446
    }
1447
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1448
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1449
}
1450

            
cleanup
Yuki Kimoto authored on 2011-04-02
1451
sub _remove_duplicate_table {
1452
    my ($self, $tables, $main_table) = @_;
1453
    
1454
    # Remove duplicate table
1455
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1456
    delete $tables{$main_table} if $main_table;
1457
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1458
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1459
    if (my $q = $self->_quote) {
1460
        $q = quotemeta($q);
1461
        $_ =~ s/[$q]//g for @$new_tables;
1462
    }
1463

            
1464
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1465
}
1466

            
cleanup
Yuki Kimoto authored on 2011-04-02
1467
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1468
    my ($self, $source) = @_;
1469
    
cleanup
Yuki Kimoto authored on 2011-04-02
1470
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1471
    my $tables = [];
1472
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1473
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1474
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1475
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1476
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1477
    while ($source =~ /$table_re/g) {
1478
        push @$tables, $1;
1479
    }
1480
    
1481
    return $tables;
1482
}
1483

            
cleanup
Yuki Kimoto authored on 2011-04-02
1484
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1485
    my ($self, $where) = @_;
1486
    
cleanup
Yuki Kimoto authored on 2011-04-02
1487
    my $obj;
1488
    
1489
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1490
    if (ref $where eq 'HASH') {
1491
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1492
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1493
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1494
            my $table;
1495
            my $c;
1496
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1497
                $table = $1;
1498
                $c = $2;
1499
            }
1500
            
1501
            my $table_quote;
1502
            $table_quote = $self->_q($table) if defined $table;
1503
            my $column_quote = $self->_q($c);
1504
            $column_quote = $table_quote . '.' . $column_quote
1505
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1506
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1507
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1508
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1509
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1510
    
1511
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1512
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1513
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1514
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1515
    
updated pod
Yuki Kimoto authored on 2011-06-21
1516
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1517
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1518
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1519
            clause => $where->[0],
1520
            param  => $where->[1]
1521
        );
1522
    }
1523
    
cleanup
Yuki Kimoto authored on 2011-04-02
1524
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1525
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1526
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1527
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1528
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1529
    
cleanup
Yuki Kimoto authored on 2011-04-02
1530
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1531
}
1532

            
updated pod
Yuki Kimoto authored on 2011-06-21
1533
sub _apply_filter {
1534
    my ($self, $table, @cinfos) = @_;
1535

            
1536
    # Initialize filters
1537
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1538
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1539
    $self->{filter}{out} ||= {};
1540
    $self->{filter}{in} ||= {};
1541
    $self->{filter}{end} ||= {};
1542
    
1543
    # Usage
1544
    my $usage = "Usage: \$dbi->apply_filter(" .
1545
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1546
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1547
    
1548
    # Apply filter
1549
    for (my $i = 0; $i < @cinfos; $i += 2) {
1550
        
1551
        # Column
1552
        my $column = $cinfos[$i];
1553
        if (ref $column eq 'ARRAY') {
1554
            foreach my $c (@$column) {
1555
                push @cinfos, $c, $cinfos[$i + 1];
1556
            }
1557
            next;
1558
        }
1559
        
1560
        # Filter infomation
1561
        my $finfo = $cinfos[$i + 1] || {};
1562
        croak "$usage (table: $table) " . _subname
1563
          unless  ref $finfo eq 'HASH';
1564
        foreach my $ftype (keys %$finfo) {
1565
            croak "$usage (table: $table) " . _subname
1566
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1567
        }
1568
        
1569
        # Set filters
1570
        foreach my $way (qw/in out end/) {
1571
        
1572
            # Filter
1573
            my $filter = $finfo->{$way};
1574
            
1575
            # Filter state
1576
            my $state = !exists $finfo->{$way} ? 'not_exists'
1577
                      : !defined $filter        ? 'not_defined'
1578
                      : ref $filter eq 'CODE'   ? 'code'
1579
                      : 'name';
1580
            
1581
            # Filter is not exists
1582
            next if $state eq 'not_exists';
1583
            
1584
            # Check filter name
1585
            croak qq{Filter "$filter" is not registered } . _subname
1586
              if  $state eq 'name'
1587
               && ! exists $self->filters->{$filter};
1588
            
1589
            # Set filter
1590
            my $f = $state eq 'not_defined' ? undef
1591
                  : $state eq 'code'        ? $filter
1592
                  : $self->filters->{$filter};
1593
            $self->{filter}{$way}{$table}{$column} = $f;
1594
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1595
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1596
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1597
        }
1598
    }
1599
    
1600
    return $self;
1601
}
1602

            
1603
# DEPRECATED!
1604
sub create_query {
1605
    warn "create_query is DEPRECATED! use query option of each method";
1606
    shift->_create_query(@_);
1607
}
1608

            
cleanup
Yuki Kimoto authored on 2011-06-13
1609
# DEPRECATED!
1610
sub apply_filter {
1611
    my $self = shift;
1612
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1613
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1614
    return $self->_apply_filter(@_);
1615
}
1616

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1617
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1618
our %SELECT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1619
sub select_at {
1620
    my ($self, %args) = @_;
1621

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1624
    # Arguments
1625
    my $primary_keys = delete $args{primary_key};
1626
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1627
    my $where = delete $args{where};
1628
    my $param = delete $args{param};
1629
    
1630
    # Check arguments
1631
    foreach my $name (keys %args) {
1632
        croak qq{"$name" is wrong option } . _subname
1633
          unless $SELECT_AT_ARGS{$name};
1634
    }
1635
    
1636
    # Table
1637
    croak qq{"table" option must be specified } . _subname
1638
      unless $args{table};
1639
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1640
    
1641
    # Create where parameter
1642
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1643
    
1644
    return $self->select(where => $where_param, %args);
1645
}
1646

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1647
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1648
our %DELETE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1649
sub delete_at {
1650
    my ($self, %args) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1651

            
1652
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1653
    
1654
    # Arguments
1655
    my $primary_keys = delete $args{primary_key};
1656
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1657
    my $where = delete $args{where};
1658
    
1659
    # Check arguments
1660
    foreach my $name (keys %args) {
1661
        croak qq{"$name" is wrong option } . _subname
1662
          unless $DELETE_AT_ARGS{$name};
1663
    }
1664
    
1665
    # Create where parameter
1666
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1667
    
1668
    return $self->delete(where => $where_param, %args);
1669
}
1670

            
cleanup
Yuki Kimoto authored on 2011-06-08
1671
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1672
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1673
sub update_at {
1674
    my $self = shift;
1675

            
1676
    warn "update_at is DEPRECATED! use update and id option instead";
1677
    
1678
    # Arguments
1679
    my $param;
1680
    $param = shift if @_ % 2;
1681
    my %args = @_;
1682
    my $primary_keys = delete $args{primary_key};
1683
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1684
    my $where = delete $args{where};
1685
    my $p = delete $args{param} || {};
1686
    $param  ||= $p;
1687
    
1688
    # Check arguments
1689
    foreach my $name (keys %args) {
1690
        croak qq{"$name" is wrong option } . _subname
1691
          unless $UPDATE_AT_ARGS{$name};
1692
    }
1693
    
1694
    # Create where parameter
1695
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1696
    
1697
    return $self->update(where => $where_param, param => $param, %args);
1698
}
1699

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1700
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1701
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1702
sub insert_at {
1703
    my $self = shift;
1704
    
1705
    warn "insert_at is DEPRECATED! use insert and id option instead";
1706
    
1707
    # Arguments
1708
    my $param;
1709
    $param = shift if @_ % 2;
1710
    my %args = @_;
1711
    my $primary_key = delete $args{primary_key};
1712
    $primary_key = [$primary_key] unless ref $primary_key;
1713
    my $where = delete $args{where};
1714
    my $p = delete $args{param} || {};
1715
    $param  ||= $p;
1716
    
1717
    # Check arguments
1718
    foreach my $name (keys %args) {
1719
        croak qq{"$name" is wrong option } . _subname
1720
          unless $INSERT_AT_ARGS{$name};
1721
    }
1722
    
1723
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1724
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1725
    $param = $self->merge_param($where_param, $param);
1726
    
1727
    return $self->insert(param => $param, %args);
1728
}
1729

            
added warnings
Yuki Kimoto authored on 2011-06-07
1730
# DEPRECATED!
1731
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1732
    my $self = shift;
1733
    
added warnings
Yuki Kimoto authored on 2011-06-07
1734
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1735
    
1736
    # Merge tag
1737
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1738
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1739
    
1740
    return $self;
1741
}
1742

            
1743
# DEPRECATED!
1744
sub register_tag_processor {
1745
    my $self = shift;
1746
    warn "register_tag_processor is DEPRECATED!";
1747
    # Merge tag
1748
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1749
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1750
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1751
}
1752

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1753
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1754
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1755
has dbi_options => sub { {} };
1756
has filter_check  => 1;
1757
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1758

            
cleanup
Yuki Kimoto authored on 2011-01-25
1759
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1760
sub default_bind_filter {
1761
    my $self = shift;
1762
    
cleanup
Yuki Kimoto authored on 2011-06-13
1763
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1764
    
cleanup
Yuki Kimoto authored on 2011-01-12
1765
    if (@_) {
1766
        my $fname = $_[0];
1767
        
1768
        if (@_ && !$fname) {
1769
            $self->{default_out_filter} = undef;
1770
        }
1771
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1772
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1773
              unless exists $self->filters->{$fname};
1774
        
1775
            $self->{default_out_filter} = $self->filters->{$fname};
1776
        }
1777
        return $self;
1778
    }
1779
    
1780
    return $self->{default_out_filter};
1781
}
1782

            
cleanup
Yuki Kimoto authored on 2011-01-25
1783
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1784
sub default_fetch_filter {
1785
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1786

            
cleanup
Yuki Kimoto authored on 2011-06-13
1787
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1788
    
1789
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1790
        my $fname = $_[0];
1791

            
cleanup
Yuki Kimoto authored on 2011-01-12
1792
        if (@_ && !$fname) {
1793
            $self->{default_in_filter} = undef;
1794
        }
1795
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1796
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1797
              unless exists $self->filters->{$fname};
1798
        
1799
            $self->{default_in_filter} = $self->filters->{$fname};
1800
        }
1801
        
1802
        return $self;
1803
    }
1804
    
many changed
Yuki Kimoto authored on 2011-01-23
1805
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1806
}
1807

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1808
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1809
sub insert_param_tag {
1810
    warn "insert_param_tag is DEPRECATED! " .
1811
         "use insert_param instead!";
1812
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1813
}
1814

            
1815
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1816
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1817
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1818
         "use update_param instead";
1819
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1820
}
cleanup
Yuki Kimoto authored on 2011-03-08
1821
# DEPRECATED!
1822
sub _push_relation {
1823
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1824
    
1825
    if (keys %{$relation || {}}) {
1826
        push @$sql, $need_where ? 'where' : 'and';
1827
        foreach my $rcolumn (keys %$relation) {
1828
            my $table1 = (split (/\./, $rcolumn))[0];
1829
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1830
            push @$tables, ($table1, $table2);
1831
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1832
        }
1833
    }
1834
    pop @$sql if $sql->[-1] eq 'and';    
1835
}
1836

            
1837
# DEPRECATED!
1838
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1839
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1840
    
1841
    if (keys %{$relation || {}}) {
1842
        foreach my $rcolumn (keys %$relation) {
1843
            my $table1 = (split (/\./, $rcolumn))[0];
1844
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1845
            my $table1_exists;
1846
            my $table2_exists;
1847
            foreach my $table (@$tables) {
1848
                $table1_exists = 1 if $table eq $table1;
1849
                $table2_exists = 1 if $table eq $table2;
1850
            }
1851
            unshift @$tables, $table1 unless $table1_exists;
1852
            unshift @$tables, $table2 unless $table2_exists;
1853
        }
1854
    }
1855
}
1856

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1859
=head1 NAME
1860

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1861
DBIx::Custom - Execute insert, update, delete, and select statement easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1862

            
1863
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1864

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1865
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1866
    
1867
    # Connect
1868
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1869
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1870
        user => 'ken',
1871
        password => '!LFKD%$&',
1872
        dbi_option => {mysql_enable_utf8 => 1}
1873
    );
cleanup
yuki-kimoto authored on 2010-08-05
1874

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1875
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1876
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1877
    
1878
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1879
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1880
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1881
    
1882
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1883
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1884

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1885
    # Select
updated pod
Yuki Kimoto authored on 2011-06-21
1886
    my $result = $dbi->select(table  => 'book',
1887
      column => ['title', 'author'], where  => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1888

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1889
    # Select, more complex
1890
    my $result = $dbi->select(
1891
        table  => 'book',
1892
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1893
            {book => [qw/title author/]},
1894
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1895
        ],
1896
        where  => {'book.author' => 'Ken'},
1897
        join => ['left outer join company on book.company_id = company.id'],
1898
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1899
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1900
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1901
    # Fetch
1902
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1903
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1904
    }
1905
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1906
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1907
    while (my $row = $result->fetch_hash) {
1908
        
1909
    }
1910
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1911
    # Execute SQL with parameter.
1912
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1913
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1914
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1915
    );
1916
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1917
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1918

            
cleanup
Yuki Kimoto authored on 2011-07-29
1919
L<DBIx::Custom> is L<DBI> wrapper module to execute SQL easily.
updated pod
Yuki Kimoto authored on 2011-06-21
1920
This module have the following features.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1921

            
updated pod
Yuki Kimoto authored on 2011-06-21
1922
=over 4
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1923

            
cleanup
Yuki Kimoto authored on 2011-07-29
1924
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1925

            
cleanup
Yuki Kimoto authored on 2011-07-29
1926
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1927

            
cleanup
Yuki Kimoto authored on 2011-07-29
1928
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1929

            
cleanup
Yuki Kimoto authored on 2011-07-29
1930
Create C<where> clause flexibly
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1931

            
cleanup
Yuki Kimoto authored on 2011-07-29
1932
=item *
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1933

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1934
Named place holder support
1935

            
1936
=item *
1937

            
cleanup
Yuki Kimoto authored on 2011-07-29
1938
Model support
1939

            
1940
=item *
1941

            
1942
Connection manager support
1943

            
1944
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
1945

            
cleanup
Yuki Kimoto authored on 2011-07-30
1946
Choice your favorite relational database management system,
cleanup
Yuki Kimoto authored on 2011-07-29
1947
C<MySQL>, C<SQLite>, C<PostgreSQL>, C<Oracle>,
1948
C<Microsoft SQL Server>, C<Microsoft Access>, C<DB2> or anything, 
1949

            
1950
=item *
1951

            
1952
Filtering by data type or column name(EXPERIMENTAL)
1953

            
1954
=item *
1955

            
1956
Create C<order by> clause flexibly(EXPERIMENTAL)
1957

            
1958
=back
pod fix
Yuki Kimoto authored on 2011-01-21
1959

            
cleanup
Yuki Kimoto authored on 2011-07-29
1960
=head1 DOCUMENTATIONS
pod fix
Yuki Kimoto authored on 2011-01-21
1961

            
cleanup
Yuki Kimoto authored on 2011-07-29
1962
L<DBIx::Custom::Guide> - How to use L<DBIx::Custom>
pod fix
Yuki Kimoto authored on 2011-01-21
1963

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1964
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki>
cleanup
Yuki Kimoto authored on 2011-07-29
1965
- Theare are various examples.
1966

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1967
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
1968
L<DBIx::Custom::Result>,
1969
L<DBIx::Custom::Query>,
1970
L<DBIx::Custom::Where>,
1971
L<DBIx::Custom::Model>,
1972
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
1973

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

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

            
1978
    my $connector = $dbi->connector;
micro optimization
Yuki Kimoto authored on 2011-07-30
1979
    $dbi = $dbi->connector($connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1980

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1981
Connection manager object. if C<connector> is set, you can get C<dbh>
1982
through connection manager. Conection manager object must have C<dbh> mehtod.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1983

            
1984
This is L<DBIx::Connector> example. Please pass
updated pod
Yuki Kimoto authored on 2011-06-21
1985
C<default_dbi_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1986

            
1987
    my $connector = DBIx::Connector->new(
1988
        "dbi:mysql:database=$DATABASE",
1989
        $USER,
1990
        $PASSWORD,
1991
        DBIx::Custom->new->default_dbi_option
1992
    );
1993
    
updated pod
Yuki Kimoto authored on 2011-06-21
1994
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
1995

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

            
1998
    my $dsn = $dbi->dsn;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1999
    $dbi = $dbi->dsn("DBI:mysql:database=dbname");
packaging one directory
yuki-kimoto authored on 2009-11-16
2000

            
updated pod
Yuki Kimoto authored on 2011-06-21
2001
Data source name, used when C<connect> method is executed.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
2002

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

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
2005
    my $dbi_option = $dbi->dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2006
    $dbi = $dbi->dbi_option($dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2007

            
updated pod
Yuki Kimoto authored on 2011-06-21
2008
L<DBI> option, used when C<connect> method is executed.
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2009
Each value in option override the value of C<default_dbi_option>.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2010

            
2011
=head2 C<default_dbi_option>
2012

            
2013
    my $default_dbi_option = $dbi->default_dbi_option;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2014
    $dbi = $dbi->default_dbi_option($default_dbi_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2015

            
updated pod
Yuki Kimoto authored on 2011-06-21
2016
L<DBI> default option, used when C<connect> method is executed,
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2017
default to the following values.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2018

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2019
    {
2020
        RaiseError => 1,
2021
        PrintError => 0,
2022
        AutoCommit => 1,
2023
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2024

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2027
    my $filters = $dbi->filters;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2028
    $dbi = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
2029

            
updated pod
Yuki Kimoto authored on 2011-06-21
2030
Filters, registered by C<register_filter> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
2031

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2032
=head2 C<last_sql>
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
2033

            
2034
    my $last_sql = $dbi->last_sql;
2035
    $dbi = $dbi->last_sql($last_sql);
2036

            
2037
Get last successed SQL executed by C<execute> method.
2038

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

            
2041
    my $models = $dbi->models;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2042
    $dbi = $dbi->models(\%models);
add models() attribute
Yuki Kimoto authored on 2011-02-21
2043

            
updated pod
Yuki Kimoto authored on 2011-06-21
2044
Models, included by C<include_model> method.
add models() attribute
Yuki Kimoto authored on 2011-02-21
2045

            
cleanup
yuki-kimoto authored on 2010-10-17
2046
=head2 C<password>
2047

            
2048
    my $password = $dbi->password;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2049
    $dbi = $dbi->password('lkj&le`@s');
cleanup
yuki-kimoto authored on 2010-10-17
2050

            
updated pod
Yuki Kimoto authored on 2011-06-21
2051
Password, used when C<connect> method is executed.
update document
yuki-kimoto authored on 2010-01-30
2052

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

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2055
    my $builder = $dbi->query_builder;
added commit method
yuki-kimoto authored on 2010-05-27
2056

            
test cleanup
Yuki Kimoto authored on 2011-08-10
2057
Creat query builder. This is L<DBIx::Custom::QueryBuilder>.
cleanup
yuki-kimoto authored on 2010-08-05
2058

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2059
=head2 C<quote>
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2060

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2061
     my quote = $dbi->quote;
2062
     $dbi = $dbi->quote('"');
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2063

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2064
Reserved word quote.
2065
Default to double quote '"' except for mysql.
2066
In mysql, default to back quote '`'
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
2067

            
cleanup
Yuki Kimoto authored on 2011-07-30
2068
You can set quote pair.
2069

            
2070
    $dbi->quote('[]');
2071

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2074
    my $result_class = $dbi->result_class;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2075
    $dbi = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
2076

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2081
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2082
    $dbi = $self->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2083

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

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2087
=head2 C<separator>
2088

            
2089
    my $separator = $self->separator;
2090
    $dbi = $self->separator($separator);
2091

            
2092
Separator whichi join table and column.
2093
This is used by C<column> and C<mycolumn> method.
2094

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2095
=head2 C<exclude_table EXPERIMENTAL>
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2096

            
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2097
    my $exclude_table = $self->exclude_table;
2098
    $dbi = $self->exclude_table(qr/pg_/);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2099

            
2100
Regex matching system table.
2101
this regex match is used by C<each_table> method and C<each_column> method
2102
System table is ignored.
2103
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2104
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2105
The performance is up.
2106

            
added tag_parse attribute
Yuki Kimoto authored on 2011-06-28
2107
=head2 C<tag_parse>
2108

            
2109
    my $tag_parse = $dbi->tag_parse(0);
2110
    $dbi = $dbi->tag_parse;
2111

            
2112
Enable DEPRECATED tag parsing functionality, default to 1.
2113
If you want to disable tag parsing functionality, set to 0.
2114

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2117
    my $user = $dbi->user;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
2118
    $dbi = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
2119

            
updated pod
Yuki Kimoto authored on 2011-06-21
2120
User name, used when C<connect> method is executed.
update pod
Yuki Kimoto authored on 2011-01-27
2121

            
added test
Yuki Kimoto authored on 2011-08-16
2122
=head2 C<user_table_info EXPERIMENTAL>
2123

            
2124
    my $user_table_info = $dbi->user_table_info;
2125
    $dbi = $dbi->user_table_info($user_table_info);
2126

            
2127
You can set the following data.
2128

            
2129
    [
2130
        {table => 'book', info => {...}},
2131
        {table => 'author', info => {...}}
2132
    ]
2133

            
2134
Usually, you can set return value of C<get_table_info>.
2135

            
2136
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2137
    $dbi->user_table_info($user_table_info);
2138

            
2139
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2140
to find table info.
2141

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

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

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2148
=head2 C<available_datatype> EXPERIMENTAL
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2149

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2150
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2151

            
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2152
Get available data types. You can use these data types
updated pod
Yuki Kimoto authored on 2011-06-21
2153
in C<type rule>'s C<from1> and C<from2> section.
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2154

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2155
=head2 C<available_typename> EXPERIMENTAL
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2156

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2157
    print $dbi->available_typename;
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2158

            
2159
Get available type names. You can use these type names in
updated pod
Yuki Kimoto authored on 2011-06-21
2160
C<type_rule>'s C<into1> and C<into2> section.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2161

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

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

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

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

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

            
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2172
=head2 C<column>
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2173

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

            
2176
Create column clause. The follwoing column clause is created.
2177

            
2178
    book.author as "book.author",
2179
    book.title as "book.title"
2180

            
cleanup test
Yuki Kimoto authored on 2011-08-10
2181
You can change separator by C<separator> attribute.
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2182

            
cleanup
Yuki Kimoto authored on 2011-06-13
2183
    # Separator is double underbar
2184
    $dbi->separator('__');
2185
    
2186
    book.author as "book__author",
2187
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2188

            
cleanup
Yuki Kimoto authored on 2011-06-13
2189
    # Separator is hyphen
2190
    $dbi->separator('-');
2191
    
2192
    book.author as "book-author",
2193
    book.title as "book-title"
2194
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2195
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2196

            
update pod
Yuki Kimoto authored on 2011-03-13
2197
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2198
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2199
        user => 'ken',
2200
        password => '!LFKD%$&',
2201
        dbi_option => {mysql_enable_utf8 => 1}
2202
    );
2203

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

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

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2212
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2213
        table => 'book',
2214
        primary_key => 'id',
2215
        join => [
2216
            'inner join company on book.comparny_id = company.id'
2217
        ],
2218
    );
2219

            
2220
Create L<DBIx::Custom::Model> object and initialize model.
updated pod
Yuki Kimoto authored on 2011-06-21
2221
the module is also used from C<model> method.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2222

            
2223
   $dbi->model('book')->select(...);
2224

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

            
2227
    my $dbh = $dbi->dbh;
2228

            
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2229
Get L<DBI> database handle. if C<connector> is set, you can get
updated pod
Yuki Kimoto authored on 2011-06-21
2230
database handle through C<connector> object.
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2231

            
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2232
=head2 C<delete>
2233

            
2234
    $dbi->delete(table => 'book', where => {title => 'Perl'});
2235

            
2236
Execute delete statement.
2237

            
2238
The following opitons are available.
2239

            
2240
=over 4
2241

            
2242
=item C<append>
2243

            
2244
Same as C<select> method's C<append> option.
2245

            
2246
=item C<filter>
2247

            
2248
Same as C<execute> method's C<filter> option.
2249

            
2250
=item C<id>
2251

            
2252
    id => 4
2253
    id => [4, 5]
2254

            
2255
ID corresponding to C<primary_key>.
2256
You can delete rows by C<id> and C<primary_key>.
2257

            
2258
    $dbi->delete(
2259
        parimary_key => ['id1', 'id2'],
2260
        id => [4, 5],
2261
        table => 'book',
2262
    );
2263

            
2264
The above is same as the followin one.
2265

            
2266
    $dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book');
2267

            
2268
=item C<prefix>
2269

            
2270
    prefix => 'some'
2271

            
2272
prefix before table name section.
2273

            
2274
    delete some from book
2275

            
2276
=item C<query>
2277

            
2278
Same as C<execute> method's C<query> option.
2279

            
2280
=item C<sqlfilter EXPERIMENTAL>
2281

            
2282
Same as C<execute> method's C<sqlfilter> option.
2283

            
2284
=item C<table>
2285

            
2286
    table => 'book'
2287

            
2288
Table name.
2289

            
2290
=item C<where>
2291

            
2292
Same as C<select> method's C<where> option.
2293

            
2294
=item C<primary_key>
2295

            
2296
See C<id> option.
2297

            
2298
=item C<bind_type>
2299

            
2300
Same as C<execute> method's C<bind_type> option.
2301

            
2302
=item C<type_rule_off> EXPERIMENTAL
2303

            
2304
Same as C<execute> method's C<type_rule_off> option.
2305

            
2306
=item C<type_rule1_off> EXPERIMENTAL
2307

            
2308
    type_rule1_off => 1
2309

            
2310
Same as C<execute> method's C<type_rule1_off> option.
2311

            
2312
=item C<type_rule2_off> EXPERIMENTAL
2313

            
2314
    type_rule2_off => 1
2315

            
2316
Same as C<execute> method's C<type_rule2_off> option.
2317

            
2318
=back
2319

            
2320
=head2 C<delete_all>
2321

            
2322
    $dbi->delete_all(table => $table);
2323

            
2324
Execute delete statement for all rows.
2325
Options is same as C<delete>.
2326

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2327
=head2 C<each_column>
2328

            
2329
    $dbi->each_column(
2330
        sub {
2331
            my ($dbi, $table, $column, $column_info) = @_;
2332
            
2333
            my $type = $column_info->{TYPE_NAME};
2334
            
2335
            if ($type eq 'DATE') {
2336
                # ...
2337
            }
2338
        }
2339
    );
2340

            
2341
Iterate all column informations of all table from database.
2342
Argument is callback when one column is found.
2343
Callback receive four arguments, dbi object, table name,
2344
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2345

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2346
=head2 C<each_table>
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2347

            
2348
    $dbi->each_table(
2349
        sub {
2350
            my ($dbi, $table, $table_info) = @_;
2351
            
2352
            my $table_name = $table_info->{TABLE_NAME};
2353
        }
2354
    );
2355

            
2356
Iterate all table informationsfrom database.
2357
Argument is callback when one table is found.
2358
Callback receive three arguments, dbi object, table name,
2359
table information.
2360

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2363
    my $result = $dbi->execute(
updated pod
Yuki Kimoto authored on 2011-06-21
2364
      "select * from book where title = :title and author like :author",
2365
      {title => 'Perl', author => '%Ken%'}
2366
    );
2367

            
2368
    my $result = $dbi->execute(
2369
      "select * from book where title = :book.title and author like :book.author",
2370
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2371
    );
2372

            
updated pod
Yuki Kimoto authored on 2011-06-21
2373
Execute SQL. SQL can contain column parameter such as :author and :title.
2374
You can append table name to column name such as :book.title and :book.author.
2375
Second argunet is data, embedded into column parameter.
2376
Return value is L<DBIx::Custom::Result> object when select statement is executed,
2377
or the count of affected rows when insert, update, delete statement is executed.
update pod
Yuki Kimoto authored on 2011-03-13
2378

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2379
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2380
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2381
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2382
    select * from book where title = :title and author like :author
2383
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2384
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2385
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2386

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2387
You can specify operator with named placeholder
2388
 by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2389

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2390
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2391
    select * from book where :title{=} and :author{like}
2392
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2393
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2394
    select * from where title = ? and author like ?;
2395

            
fixed named placeholder bug ...
Yuki Kimoto authored on 2011-08-01
2396
Note that colons in time format such as 12:13:15 is exeption,
2397
it is not parsed as named placeholder.
2398
If you want to use colon generally, you must escape it by C<\\>
2399

            
2400
    select * from where title = "aa\\:bb";
2401

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

            
2404
=over 4
2405

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2406
=item C<bind_type>
2407

            
2408
Specify database bind data type.
2409

            
2410
    bind_type => [image => DBI::SQL_BLOB]
2411
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2412

            
2413
This is used to bind parameter by C<bind_param> of statment handle.
2414

            
2415
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2416

            
update pod
Yuki Kimoto authored on 2011-03-13
2417
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2418
    
2419
    filter => {
2420
        title  => sub { uc $_[0] }
2421
        author => sub { uc $_[0] }
2422
    }
update pod
Yuki Kimoto authored on 2011-03-13
2423

            
updated pod
Yuki Kimoto authored on 2011-06-09
2424
    # Filter name
2425
    filter => {
2426
        title  => 'upper_case',
2427
        author => 'upper_case'
2428
    }
2429
        
2430
    # At once
2431
    filter => [
2432
        [qw/title author/]  => sub { uc $_[0] }
2433
    ]
2434

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2435
Filter. You can set subroutine or filter name
updated pod
Yuki Kimoto authored on 2011-06-21
2436
registered by by C<register_filter>.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2437
This filter is executed before data is saved into database.
2438
and before type rule filter is executed.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2439

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

            
2442
    query => 1
2443

            
2444
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
cleanup
Yuki Kimoto authored on 2011-07-30
2445
You can check SQL or get statment handle.
updated pod
Yuki Kimoto authored on 2011-06-21
2446

            
2447
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2448
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2449
    my $columns = $query->columns;
2450
    
2451
If you want to execute SQL fast, you can do the following way.
2452

            
2453
    my $query;
2454
    foreach my $row (@$rows) {
2455
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2456
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2457
    }
2458

            
2459
Statement handle is reused and SQL parsing is finished,
2460
so you can get more performance than normal way.
cleanup
Yuki Kimoto authored on 2011-07-30
2461

            
2462
If you want to execute SQL as possible as fast and don't need filtering.
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2463
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2464
    
2465
    my $query;
2466
    my $sth;
2467
    foreach my $row (@$rows) {
2468
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2469
      $sth ||= $query->sth;
2470
      $sth->execute(map { $row->{$_} } sort keys %$row);
2471
    }
2472

            
2473
Note that $row must be simple hash reference, such as
2474
{title => 'Perl', author => 'Ken'}.
2475
and don't forget to sort $row values by $row key asc order.
updated document
Yuki Kimoto authored on 2011-06-09
2476

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2477
=item C<sqlfilter EXPERIMENTAL> 
2478

            
2479
SQL filter function.
2480

            
2481
    sqlfilter => $code_ref
2482

            
2483
This option is generally for Oracle and SQL Server paging process.
2484
    
2485
    my $limit = sub {
2486
        my ($sql, $count, $offset) = @_;
2487
        
2488
        my $min = $offset + 1;
2489
        my $max = $offset + $count;
2490
        
2491
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2492
        
2493
        return $sql;
2494
    }
2495
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2496
        my $sql = shift;
2497
        return $limit->($sql, 100, 50);
2498
    })
2499

            
updated pod
Yuki Kimoto authored on 2011-06-09
2500
=item C<table>
2501
    
2502
    table => 'author'
2503

            
updated pod
Yuki Kimoto authored on 2011-06-21
2504
If you want to omit table name in column name
2505
and enable C<into1> and C<into2> type filter,
2506
You must set C<table> option.
updated pod
Yuki Kimoto authored on 2011-06-09
2507

            
updated pod
Yuki Kimoto authored on 2011-06-21
2508
    $dbi->execute("select * from book where title = :title and author = :author",
2509
        {title => 'Perl', author => 'Ken', table => 'book');
updated pod
Yuki Kimoto authored on 2011-06-09
2510

            
updated pod
Yuki Kimoto authored on 2011-06-21
2511
    # Same
2512
    $dbi->execute(
2513
      "select * from book where title = :book.title and author = :book.author",
2514
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2515

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2516
=item C<table_alias> EXPERIMENTAL
2517

            
2518
    table_alias => {user => 'hiker'}
2519

            
2520
Table alias. Key is real table name, value is alias table name.
2521
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2522
on alias table name.
2523

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

            
2526
    type_rule_off => 1
2527

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2528
Turn C<into1> and C<into2> type rule off.
2529

            
2530
=item C<type_rule1_off> EXPERIMENTAL
2531

            
2532
    type_rule1_off => 1
2533

            
2534
Turn C<into1> type rule off.
2535

            
2536
=item C<type_rule2_off> EXPERIMENTAL
2537

            
2538
    type_rule2_off => 1
2539

            
2540
Turn C<into2> type rule off.
update document
yuki-kimoto authored on 2009-11-19
2541

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

            
added test
Yuki Kimoto authored on 2011-08-16
2544
=head2 C<get_table_info EXPERIMENTAL>
2545

            
2546
    my $tables = $self->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2547

            
added test
Yuki Kimoto authored on 2011-08-16
2548
get table infomation except for one which match C<exclude> pattern.
2549

            
2550
    [
2551
        {table => 'book', info => {...}},
2552
        {table => 'author', info => {...}}
2553
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2554

            
added test
Yuki Kimoto authored on 2011-08-16
2555
You can set this value to C<user_table_info>.
update pod
Yuki Kimoto authored on 2011-03-13
2556

            
cleanup
yuki-kimoto authored on 2010-10-17
2557
=head2 C<insert>
2558

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2561
Execute insert statement. First argument is row data. Return value is
2562
affected row count.
update pod
Yuki Kimoto authored on 2011-03-13
2563

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
2564
If you want to set constant value to row data, use scalar reference
2565
as parameter value.
2566

            
2567
    {date => \"NOW()"}
2568

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2577
=item C<bind_type>
2578

            
2579
Same as C<execute> method's C<bind_type> option.
2580

            
update pod
Yuki Kimoto authored on 2011-03-13
2581
=item C<filter>
2582

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

            
2585
=item C<id>
2586

            
updated document
Yuki Kimoto authored on 2011-06-09
2587
    id => 4
2588
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2589

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2593
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2594
        {title => 'Perl', author => 'Ken'}
2595
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2596
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2597
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2598
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2599

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2607
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
2608

            
2609
    prefix => 'or replace'
2610

            
2611
prefix before table name section
2612

            
2613
    insert or replace into book
2614

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

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

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

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

            
2624
Same as C<execute> method's C<query> option.
2625

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2626
=item C<sqlfilter EXPERIMENTAL>
2627

            
2628
Same as C<execute> method's C<sqlfilter> option.
2629

            
updated document
Yuki Kimoto authored on 2011-06-09
2630
=item C<table>
2631

            
2632
    table => 'book'
2633

            
2634
Table name.
2635

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

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2640
=item C<type_rule1_off> EXPERIMENTAL
2641

            
2642
    type_rule1_off => 1
2643

            
2644
Same as C<execute> method's C<type_rule1_off> option.
2645

            
2646
=item C<type_rule2_off> EXPERIMENTAL
2647

            
2648
    type_rule2_off => 1
2649

            
2650
Same as C<execute> method's C<type_rule2_off> option.
2651

            
update pod
Yuki Kimoto authored on 2011-03-13
2652
=back
2653

            
2654
=over 4
2655

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2671
    lib / MyModel.pm
2672
        / MyModel / book.pm
2673
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2674

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

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

            
2679
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2680
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2681
    
2682
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2683

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2688
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2689
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2690
    
2691
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2692

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2695
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2696
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2697
    
2698
    1;
2699
    
updated pod
Yuki Kimoto authored on 2011-06-21
2700
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2701

            
updated pod
Yuki Kimoto authored on 2011-06-21
2702
You can get model object by C<model>.
update pod
Yuki Kimoto authored on 2011-03-13
2703

            
updated pod
Yuki Kimoto authored on 2011-06-21
2704
    my $book_model = $dbi->model('book');
update pod
Yuki Kimoto authored on 2011-03-13
2705
    my $company_model = $dbi->model('company');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2706

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

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
2709
=head2 C<map_param> EXPERIMENTAL
2710

            
2711
    my $map_param = $dbi->map_param(
2712
        {id => 1, authro => 'Ken', price => 1900},
2713
        'id' => 'book.id',
2714
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2715
        'price' => [
2716
            'book.price', {if => sub { length $_[0] }}
2717
        ]
2718
    );
2719

            
2720
Map paramters to other key and value. First argument is original
2721
parameter. this is hash reference. Rest argument is mapping.
2722
By default, Mapping is done if the value length is not zero.
2723

            
2724
=over 4
2725

            
2726
=item Key mapping
2727

            
2728
    'id' => 'book.id'
2729

            
2730
This is only key mapping. Value is same as original one.
2731

            
2732
    (id => 1) is mapped to ('book.id' => 1) if value length is not zero.
2733

            
2734
=item Key and value mapping
2735

            
2736
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2737

            
2738
This is key and value mapping. Frist element of array reference
2739
is mapped key name, second element is code reference to map the value.
2740

            
2741
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2742
      if value length is not zero.
2743

            
2744
=item Condition
2745

            
2746
    'price' => ['book.price', {if => 'exists'}]
2747
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2748
    'price' => ['book.price', {if => sub { defined shift }}]
2749

            
2750
If you need condition, you can sepecify it. this is code reference
2751
or 'exists'. By default, condition is the following one.
2752

            
2753
    sub { defined $_[0] && length $_[0] }
2754

            
2755
=back
2756

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

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

            
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
2761
Merge parameters.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2762

            
2763
    {key1 => [1, 1], key2 => 2}
2764

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

            
2767
    $dbi->method(
2768
        update_or_insert => sub {
2769
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2770
            
2771
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2772
        },
2773
        find_or_create   => sub {
2774
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2775
            
2776
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2777
        }
2778
    );
2779

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

            
2782
    $dbi->update_or_insert;
2783
    $dbi->find_or_create;
2784

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

            
2787
    my $model = $dbi->model('book');
2788

            
updated pod
Yuki Kimoto authored on 2011-06-21
2789
Get a L<DBIx::Custom::Model> object,
update pod
Yuki Kimoto authored on 2011-03-13
2790

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

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

            
2795
Create column clause for myself. The follwoing column clause is created.
2796

            
2797
    book.author as author,
2798
    book.title as title
2799

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2802
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2803
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2804
        user => 'ken',
2805
        password => '!LFKD%$&',
2806
        dbi_option => {mysql_enable_utf8 => 1}
2807
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2808

            
2809
Create a new L<DBIx::Custom> object.
2810

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

            
2813
    my $not_exists = $dbi->not_exists;
2814

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2818
=head2 C<order> EXPERIMENTAL
2819

            
2820
    my $order = $dbi->order;
2821

            
2822
Create a new L<DBIx::Custom::Order> object.
2823

            
cleanup
yuki-kimoto authored on 2010-10-17
2824
=head2 C<register_filter>
2825

            
update pod
Yuki Kimoto authored on 2011-03-13
2826
    $dbi->register_filter(
2827
        # Time::Piece object to database DATE format
2828
        tp_to_date => sub {
2829
            my $tp = shift;
2830
            return $tp->strftime('%Y-%m-%d');
2831
        },
2832
        # database DATE format to Time::Piece object
2833
        date_to_tp => sub {
2834
           my $date = shift;
2835
           return Time::Piece->strptime($date, '%Y-%m-%d');
2836
        }
2837
    );
cleanup
yuki-kimoto authored on 2010-10-17
2838
    
update pod
Yuki Kimoto authored on 2011-03-13
2839
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2840

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

            
2843
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2844
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2845
            date => sub { ... },
2846
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2847
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2848
        into2 => {
2849
            date => sub { ... },
2850
            datetime => sub { ... }
2851
        },
2852
        from1 => {
2853
            # DATE
2854
            9 => sub { ... },
2855
            # DATETIME or TIMESTAMP
2856
            11 => sub { ... },
2857
        }
2858
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2859
            # DATE
2860
            9 => sub { ... },
2861
            # DATETIME or TIMESTAMP
2862
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2863
        }
2864
    );
2865

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2869
In C<into1> and C<into2> you can specify
2870
type name as same as type name defined
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2871
by create table, such as C<DATETIME> or C<DATE>.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2872

            
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2873
Note that type name and data type don't contain upper case.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2874
If these contain upper case charactor, you convert it to lower case.
2875

            
updated pod
Yuki Kimoto authored on 2011-06-21
2876
C<into2> is executed after C<into1>.
2877

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2878
Type rule of C<into1> and C<into2> is enabled on the following
2879
column name.
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2880

            
cleanup
Yuki Kimoto authored on 2011-06-13
2881
=over 4
2882

            
2883
=item 1. column name
2884

            
2885
    issue_date
2886
    issue_datetime
2887

            
updated pod
Yuki Kimoto authored on 2011-06-21
2888
This need C<table> option in each method.
2889

            
cleanup
Yuki Kimoto authored on 2011-06-13
2890
=item 2. table name and column name, separator is dot
2891

            
2892
    book.issue_date
2893
    book.issue_datetime
2894

            
2895
=back
2896

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2897
You get all type name used in database by C<available_typename>.
update pod
Yuki Kimoto authored on 2011-06-15
2898

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2899
    print $dbi->available_typename;
update pod
Yuki Kimoto authored on 2011-06-15
2900

            
updated pod
Yuki Kimoto authored on 2011-06-21
2901
In C<from1> and C<from2> you specify data type, not type name.
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2902
C<from2> is executed after C<from1>.
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2903
You get all data type by C<available_datatype>.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2904

            
added EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-08-09
2905
    print $dbi->available_datatype;
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2906

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2907
You can also specify multiple types at once.
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2908

            
2909
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2910
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2911
            [qw/DATE DATETIME/] => sub { ... },
2912
        ],
2913
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2914

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2917
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2918
        table  => 'book',
2919
        column => ['author', 'title'],
2920
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2921
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2922
    
updated document
Yuki Kimoto authored on 2011-06-09
2923
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2924

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

            
2927
=over 4
2928

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2933
Append statement to last of SQL.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2934

            
2935
=item C<bind_type>
2936

            
2937
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
2938
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2939
=item C<column>
2940
    
updated document
Yuki Kimoto authored on 2011-06-09
2941
    column => 'author'
2942
    column => ['author', 'title']
2943

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
2950
You can specify hash of array reference.
updated pod
Yuki Kimoto authored on 2011-06-07
2951

            
updated document
Yuki Kimoto authored on 2011-06-09
2952
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2953
        {book => [qw/author title/]},
2954
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2955
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2956

            
updated pod
Yuki Kimoto authored on 2011-06-21
2957
This is expanded to the following one by using C<colomn> method.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2958

            
2959
    book.author as "book.author",
2960
    book.title as "book.title",
2961
    person.name as "person.name",
2962
    person.age as "person.age"
2963

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2964
You can specify array of array reference, first argument is
2965
column name, second argument is alias.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2966

            
updated document
Yuki Kimoto authored on 2011-06-09
2967
    column => [
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2968
        ['date(book.register_datetime)' => 'book.register_date']
updated document
Yuki Kimoto authored on 2011-06-09
2969
    ];
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2970

            
- select method column optio...
Yuki Kimoto authored on 2011-07-11
2971
Alias is quoted properly and joined.
- select() column option can...
Yuki Kimoto authored on 2011-06-08
2972

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

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

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

            
2979
=item C<id>
2980

            
2981
    id => 4
2982
    id => [4, 5]
2983

            
2984
ID corresponding to C<primary_key>.
2985
You can select rows by C<id> and C<primary_key>.
2986

            
2987
    $dbi->select(
2988
        parimary_key => ['id1', 'id2'],
2989
        id => [4, 5],
2990
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2991
    );
2992

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
2995
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
2996
        where => {id1 => 4, id2 => 5},
2997
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
2998
    );
2999
    
updated document
Yuki Kimoto authored on 2011-06-09
3000
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3001

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

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

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

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
3012
=itme C<prefix>
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
3013

            
3014
    prefix => 'SQL_CALC_FOUND_ROWS'
3015

            
3016
Prefix of column cluase
3017

            
3018
    select SQL_CALC_FOUND_ROWS title, author from book;
3019

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

            
3022
    join => [
3023
        'left outer join company on book.company_id = company_id',
3024
        'left outer join location on company.location_id = location.id'
3025
    ]
3026
        
3027
Join clause. If column cluase or where clause contain table name like "company.name",
3028
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3029

            
3030
    $dbi->select(
3031
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3032
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3033
        where => {'company.name' => 'Orange'},
3034
        join => [
3035
            'left outer join company on book.company_id = company.id',
3036
            'left outer join location on company.location_id = location.id'
3037
        ]
3038
    );
3039

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3043
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3044
    from book
3045
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3046
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3047

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3048
You can specify two table by yourself. This is useful when join parser can't parse
cleanup
Yuki Kimoto authored on 2011-07-28
3049
the join clause correctly. This is EXPERIMENTAL.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3050

            
3051
    $dbi->select(
3052
        table => 'book',
3053
        column => ['company.location_id as location_id'],
3054
        where => {'company.name' => 'Orange'},
3055
        join => [
3056
            {
3057
                clause => 'left outer join location on company.location_id = location.id',
3058
                table => ['company', 'location']
3059
            }
3060
        ]
3061
    );
3062

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

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3074
=item C<sqlfilter EXPERIMENTAL>
updated pod
Yuki Kimoto authored on 2011-06-08
3075

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3076
Same as C<execute> method's C<sqlfilter> option
updated pod
Yuki Kimoto authored on 2011-06-08
3077

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3082
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3083

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

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3088
=item C<type_rule1_off> EXPERIMENTAL
3089

            
3090
    type_rule1_off => 1
3091

            
3092
Same as C<execute> method's C<type_rule1_off> option.
3093

            
3094
=item C<type_rule2_off> EXPERIMENTAL
3095

            
3096
    type_rule2_off => 1
3097

            
3098
Same as C<execute> method's C<type_rule2_off> option.
3099

            
updated document
Yuki Kimoto authored on 2011-06-09
3100
=item C<where>
3101
    
3102
    # Hash refrence
3103
    where => {author => 'Ken', 'title' => 'Perl'}
3104
    
3105
    # DBIx::Custom::Where object
3106
    where => $dbi->where(
3107
        clause => ['and', 'author = :author', 'title like :title'],
3108
        param  => {author => 'Ken', title => '%Perl%'}
3109
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3110
    
3111
    # Array reference 1 (array reference, hash referenc). same as above
3112
    where => [
3113
        ['and', 'author = :author', 'title like :title'],
3114
        {author => 'Ken', title => '%Perl%'}
3115
    ];    
3116
    
3117
    # Array reference 2 (String, hash reference)
3118
    where => [
3119
        'title like :title',
3120
        {title => '%Perl%'}
3121
    ]
3122
    
3123
    # String
3124
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3125

            
updated document
Yuki Kimoto authored on 2011-06-09
3126
Where clause.
3127
    
improved pod
Yuki Kimoto authored on 2011-04-19
3128
=item C<wrap> EXPERIMENTAL
3129

            
3130
Wrap statement. This is array reference.
3131

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3132
    wrap => ['select * from (', ') as t where ROWNUM < 10']
improved pod
Yuki Kimoto authored on 2011-04-19
3133

            
3134
This option is for Oracle and SQL Server paging process.
3135

            
update pod
Yuki Kimoto authored on 2011-03-12
3136
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3137

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

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

            
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
3142
Execute update statement. First argument is update row data.
3143

            
3144
If you want to set constant value to row data, use scalar reference
3145
as parameter value.
3146

            
3147
    {date => \"NOW()"}
added experimental update_pa...
Yuki Kimoto authored on 2011-03-08
3148

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3151
=over 4
3152

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3157
=item C<bind_type>
3158

            
3159
Same as C<execute> method's C<bind_type> option.
3160

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3167
    id => 4
3168
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3169

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3173
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3174
        {title => 'Perl', author => 'Ken'}
3175
        parimary_key => ['id1', 'id2'],
3176
        id => [4, 5],
3177
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3178
    );
update pod
Yuki Kimoto authored on 2011-03-13
3179

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3182
    $dbi->update(
3183
        {title => 'Perl', author => 'Ken'}
3184
        where => {id1 => 4, id2 => 5},
3185
        table => 'book'
3186
    );
update pod
Yuki Kimoto authored on 2011-03-13
3187

            
- removed EXPERIMENTAL statu...
Yuki Kimoto authored on 2011-07-26
3188
=item C<prefix>
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
3189

            
3190
    prefix => 'or replace'
3191

            
3192
prefix before table name section
3193

            
3194
    update or replace book
3195

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

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

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

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

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

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3207
=item C<sqlfilter EXPERIMENTAL>
3208

            
3209
Same as C<execute> method's C<sqlfilter> option.
3210

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

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

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

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

            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3219
Same as C<execute> method's C<type_rule_off> option.
3220

            
3221
=item C<type_rule1_off> EXPERIMENTAL
3222

            
3223
    type_rule1_off => 1
3224

            
3225
Same as C<execute> method's C<type_rule1_off> option.
3226

            
3227
=item C<type_rule2_off> EXPERIMENTAL
3228

            
3229
    type_rule2_off => 1
3230

            
3231
Same as C<execute> method's C<type_rule2_off> option.
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
3232

            
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
3233
=item C<where>
3234

            
3235
Same as C<select> method's C<where> option.
3236

            
updated pod
Yuki Kimoto authored on 2011-06-08
3237
=back
update pod
Yuki Kimoto authored on 2011-03-13
3238

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3243
Execute update statement for all rows.
updated pod
Yuki Kimoto authored on 2011-06-21
3244
Options is same as C<update> method.
update pod
Yuki Kimoto authored on 2011-03-13
3245

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

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

            
3250
Create update parameter tag.
3251

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

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

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

            
3261
Create a new L<DBIx::Custom::Where> object.
3262

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

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

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

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

            
3272
=head2 C<DBIX_CUSTOM_DEBUG>
3273

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

            
update pod
Yuki Kimoto authored on 2011-08-10
3277
=head2 C<show_datatype EXPERIMENTAL>
3278

            
3279
    $dbi->show_datatype($table);
3280

            
3281
Show data type of the columns of specified table.
3282

            
3283
    book
3284
    title: 5
3285
    issue_date: 91
3286

            
3287
This data type is used in C<type_rule>'s C<from1> and C<from2>.
3288

            
test cleanup
Yuki Kimoto authored on 2011-08-15
3289
=head2 C<show_tables EXPERIMETNAL>
3290

            
3291
    $dbi->show_tables;
3292

            
3293
Show tables.
3294

            
update pod
Yuki Kimoto authored on 2011-08-10
3295
=head2 C<show_typename EXPERIMENTAL>
3296

            
3297
    $dbi->show_typename($table);
3298

            
3299
Show type name of the columns of specified table.
3300

            
3301
    book
3302
    title: varchar
3303
    issue_date: date
3304

            
3305
This type name is used in C<type_rule>'s C<into1> and C<into2>.
3306

            
improved debug message
Yuki Kimoto authored on 2011-05-23
3307
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING>
3308

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

            
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3311
=head1 DEPRECATED FUNCTIONALITIES
3312

            
3313
L<DBIx::Custom>
3314

            
3315
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3316
    data_source # will be removed at 2017/1/1
3317
    dbi_options # will be removed at 2017/1/1
3318
    filter_check # will be removed at 2017/1/1
3319
    reserved_word_quote # will be removed at 2017/1/1
3320
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3321
    
3322
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3323
    create_query # will be removed at 2017/1/1
3324
    apply_filter # will be removed at 2017/1/1
3325
    select_at # will be removed at 2017/1/1
3326
    delete_at # will be removed at 2017/1/1
3327
    update_at # will be removed at 2017/1/1
3328
    insert_at # will be removed at 2017/1/1
3329
    register_tag # will be removed at 2017/1/1
3330
    default_bind_filter # will be removed at 2017/1/1
3331
    default_fetch_filter # will be removed at 2017/1/1
3332
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3333
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3334
    register_tag_processor # will be removed at 2017/1/1
3335
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3336
    
3337
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3338
    select method relation option # will be removed at 2017/1/1
3339
    select method param option # will be removed at 2017/1/1
3340
    select method column option [COLUMN, as => ALIAS] format
3341
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3342
    
3343
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3344
    execute("select * from {= title}"); # execute method's
3345
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3346
                                        # will be removed at 2017/1/1
3347
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3348

            
3349
L<DBIx::Custom::Model>
3350

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3351
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3352
    filter # will be removed at 2017/1/1
3353
    name # will be removed at 2017/1/1
3354
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3355

            
3356
L<DBIx::Custom::Query>
3357
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3358
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3359
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3360
    table # will be removed at 2017/1/1
3361
    filters # will be removed at 2017/1/1
3362
    
3363
    # Methods
3364
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3365

            
3366
L<DBIx::Custom::QueryBuilder>
3367
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3368
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3369
    tags # will be removed at 2017/1/1
3370
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3371
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3372
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3373
    register_tag # will be removed at 2017/1/1
3374
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3375
    
3376
    # Others
3377
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3378
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3379

            
3380
L<DBIx::Custom::Result>
3381
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3382
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3383
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3384
    
3385
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3386
    end_filter # will be removed at 2017/1/1
3387
    remove_end_filter # will be removed at 2017/1/1
3388
    remove_filter # will be removed at 2017/1/1
3389
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3390

            
3391
L<DBIx::Custom::Tag>
3392

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3393
    This module is DEPRECATED! # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3394

            
3395
=head1 BACKWORD COMPATIBLE POLICY
3396

            
3397
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3398
except for attribute method.
3399
You can check all DEPRECATED functionalities by document.
3400
DEPRECATED functionality is removed after five years,
3401
but if at least one person use the functionality and tell me that thing
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3402
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3403

            
3404
EXPERIMENTAL functionality will be changed without warnings.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3405

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3406
This policy was changed at 2011/6/28
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
3407

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

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

            
3412
C<< <kimoto.yuki at gmail.com> >>
3413

            
3414
L<http://github.com/yuki-kimoto/DBIx-Custom>
3415

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3416
=head1 AUTHOR
3417

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

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

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

            
3424
This program is free software; you can redistribute it and/or modify it
3425
under the same terms as Perl itself.
3426

            
3427
=cut