DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3571 lines | 92.803kb
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 pass at...
Yuki Kimoto authored on 2011-09-02
4
our $VERSION = '0.1722';
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/;
added tests
Yuki Kimoto authored on 2011-08-26
17
use DBIx::Custom::Mapper;
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
18
use DBIx::Custom::NotExists;
improved debug message
Yuki Kimoto authored on 2011-05-23
19
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
20
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
101
our $AUTOLOAD;
102
sub AUTOLOAD {
103
    my $self = shift;
104

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

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

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

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

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
168
sub connect {
cleanup
Yuki Kimoto authored on 2011-08-16
169
    my $self = ref $_[0] ? shift : shift->new(@_);
170
    
171
    my $connector = $self->connector;
172
    
173
    if (!ref $connector && $connector) {
174
        require DBIx::Connector;
175
        
176
        my $dsn = $self->dsn;
177
        my $user = $self->user;
178
        my $password = $self->password;
179
        my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
180
        my $connector = DBIx::Connector->new($dsn, $user, $password,
181
          {%{$self->default_dbi_option} , %$dbi_option});
182
        $self->connector($connector);
183
    }
removed register_format()
yuki-kimoto authored on 2010-05-26
184
    
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
185
    # Connect
186
    $self->dbh;
update document
yuki-kimoto authored on 2010-01-30
187
    
packaging one directory
yuki-kimoto authored on 2009-11-16
188
    return $self;
189
}
190

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
191
sub count { shift->select(column => 'count(*)', @_)->fetch_first->[0] }
192

            
update pod
Yuki Kimoto authored on 2011-03-13
193
sub dbh {
194
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-04-02
195
    
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
196
    # Set
197
    if (@_) {
198
        $self->{dbh} = $_[0];
199
        
200
        return $self;
201
    }
202
    
203
    # Get
204
    else {
205
        # From Connction manager
206
        if (my $connector = $self->connector) {
cleanup
Yuki Kimoto authored on 2011-04-25
207
            croak "connector must have dbh() method " . _subname
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
208
              unless ref $connector && $connector->can('dbh');
209
              
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
210
            $self->{dbh} = $connector->dbh;
fixed dbh() method bug:wq
Yuki Kimoto authored on 2011-04-05
211
        }
212
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
213
        # Connect
214
        $self->{dbh} ||= $self->_connect;
215
        
216
        # Quote
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
217
        if (!defined $self->reserved_word_quote && !defined $self->quote) {
prepare oracle test
Yuki Kimoto authored on 2011-08-15
218
            my $driver = $self->_driver;
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
219
            my $quote =  $driver eq 'odbc' ? '[]'
220
                       : $driver eq 'ado' ? '[]'
221
                       : $driver eq 'mysql' ? '`'
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
222
                       : '"';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
223
            $self->quote($quote);
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
224
        }
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
225
        
set reserved_word_quote auto...
Yuki Kimoto authored on 2011-06-08
226
        return $self->{dbh};
update pod
Yuki Kimoto authored on 2011-03-13
227
    }
228
}
229

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
269
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-01-27
270
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
271
    push @sql, "delete";
272
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
273
    push @sql, "from " . $self->_q($table) . " $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
274
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
275
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
276
    
277
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
278
    return $self->execute($sql, $where_param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
279
}
280

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
285
sub create_model {
286
    my $self = shift;
287
    
cleanup
Yuki Kimoto authored on 2011-04-02
288
    # Arguments
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
289
    my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_};
290
    $args->{dbi} = $self;
291
    my $model_class = delete $args->{model_class} || 'DBIx::Custom::Model';
292
    my $model_name  = delete $args->{name};
293
    my $model_table = delete $args->{table};
294
    $model_name ||= $model_table;
295
    
cleanup
Yuki Kimoto authored on 2011-04-02
296
    # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
297
    my $model = $model_class->new($args);
cleanup
Yuki Kimoto authored on 2011-08-13
298
    weaken $model->{dbi};
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
299
    $model->name($model_name) unless $model->name;
300
    $model->table($model_table) unless $model->table;
301
    
micro optimization
Yuki Kimoto authored on 2011-07-30
302
    # Apply filter(DEPRECATED logic)
303
    if ($model->{filter}) {
304
        my $filter = ref $model->filter eq 'HASH'
305
                   ? [%{$model->filter}]
306
                   : $model->filter;
307
        $filter ||= [];
308
        warn "DBIx::Custom::Model filter method is DEPRECATED!"
309
          if @$filter;
310
        $self->_apply_filter($model->table, @$filter);
311
    }
312
    
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
313
    # Set model
314
    $self->model($model->name, $model);
315
    
create_model() return model
Yuki Kimoto authored on 2011-03-29
316
    return $self->model($model->name);
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
317
}
318

            
319
sub each_column {
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
320
    my ($self, $cb, %options) = @_;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
321

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
322
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
323
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
324
    if ($user_column_info) {
325
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
326
    }
327
    else {
328
    
329
        my $re = $self->exclude_table || $options{exclude_table};
330
        # Tables
331
        my %tables;
332
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
333

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
334
        # Iterate all tables
335
        my @tables = sort keys %tables;
336
        for (my $i = 0; $i < @tables; $i++) {
337
            my $table = $tables[$i];
338
            
339
            # Iterate all columns
340
            my $sth_columns;
341
            eval {$sth_columns = $self->dbh->column_info(undef, undef, $table, '%')};
342
            next if $@;
343
            while (my $column_info = $sth_columns->fetchrow_hashref) {
344
                my $column = $column_info->{COLUMN_NAME};
345
                $self->$cb($table, $column, $column_info);
346
            }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
347
        }
348
    }
349
}
350

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
351
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
352
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
353
    
cleanup test
Yuki Kimoto authored on 2011-08-16
354
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
355
    
added test
Yuki Kimoto authored on 2011-08-16
356
    # Iterate tables
357
    if ($user_table_infos) {
358
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
359
    }
360
    else {
361
        my $re = $self->exclude_table || $option{exclude};
362
        my $sth_tables = $self->dbh->table_info;
363
        while (my $table_info = $sth_tables->fetchrow_hashref) {
364
            
365
            # Table
366
            my $table = $table_info->{TABLE_NAME};
367
            next if defined $re && $table =~ /$re/;
368
            $self->$cb($table, $table_info);
369
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
370
    }
371
}
372

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

            
378
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
379
    my $self = shift;
380
    my $query = shift;
381
    my $param;
382
    $param = shift if @_ % 2;
383
    my %args = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
384
    
cleanup
Yuki Kimoto authored on 2011-04-02
385
    # Arguments
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
386
    my $p = delete $args{param} || {};
387
    $param ||= $p;
cleanup
Yuki Kimoto authored on 2011-04-02
388
    my $tables = delete $args{table} || [];
389
    $tables = [$tables] unless ref $tables eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-04-02
390
    my $filter = delete $args{filter};
cleanup
Yuki Kimoto authored on 2011-04-25
391
    $filter = _array_to_hash($filter);
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
392
    my $bind_type = delete $args{bind_type} || delete $args{type};
393
    $bind_type = _array_to_hash($bind_type);
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
394
    my $type_rule_off = delete $args{type_rule_off};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
395
    my $type_rule_off_parts = {
396
        1 => delete $args{type_rule1_off},
397
        2 => delete $args{type_rule2_off}
398
    };
cleanup
Yuki Kimoto authored on 2011-06-09
399
    my $query_return = delete $args{query};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
400
    my $table_alias = delete $args{table_alias} || {};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
401
    my $sqlfilter = $args{sqlfilter};
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
402
    my $id = delete $args{id};
403
    my $primary_key = delete $args{primary_key};
404
    croak "insert method primary_key option " .
405
          "must be specified when id is specified " . _subname
406
      if defined $id && !defined $primary_key;
407
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
408

            
409
    if (defined $id) {
410
        my $id_param = $self->_create_param_from_id($id, $primary_key);
411
        $param = $self->merge_param($id_param, $param);
412
    }
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
413
    
cleanup
Yuki Kimoto authored on 2011-03-09
414
    # Check argument names
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
415
    foreach my $name (keys %args) {
cleanup
Yuki Kimoto authored on 2011-04-25
416
        croak qq{"$name" is wrong option } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
417
          unless $VALID_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
418
    }
419
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
420
    $query = $self->_create_query($query, $sqlfilter) unless ref $query;
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
421
    
422
    # Save query
423
    $self->last_sql($query->sql);
424

            
cleanup
Yuki Kimoto authored on 2011-06-09
425
    return $query if $query_return;
micro optimization
Yuki Kimoto authored on 2011-07-30
426
    
427
    # DEPRECATED! Merge query filter
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
428
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
429
    
cleanup
Yuki Kimoto authored on 2011-04-02
430
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
431
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
432
    my $main_table = @{$tables}[-1];
micro optimization
Yuki Kimoto authored on 2011-07-30
433
    
micro optimization
Yuki Kimoto authored on 2011-07-30
434
    # DEPRECATED! Cleanup tables
micro optimization
Yuki Kimoto authored on 2011-07-30
435
    $tables = $self->_remove_duplicate_table($tables, $main_table)
436
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
437
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
438
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
439
    my $type_filters = {};
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
440
    unless ($type_rule_off) {
micro optimization
Yuki Kimoto authored on 2011-07-30
441
        foreach my $i (1, 2) {
442
            unless ($type_rule_off_parts->{$i}) {
443
                $type_filters->{$i} = {};
444
                foreach my $alias (keys %$table_alias) {
445
                    my $table = $table_alias->{$alias};
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
446
                    
micro optimization
Yuki Kimoto authored on 2011-07-30
447
                    foreach my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
448
                        $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
449
                    }
450
                }
micro optimization
Yuki Kimoto authored on 2011-07-30
451
                $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
452
                  if $main_table;
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
453
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
454
        }
455
    }
cleanup
Yuki Kimoto authored on 2011-04-02
456
    
micro optimization
Yuki Kimoto authored on 2011-07-30
457
    # DEPRECATED! Applied filter
micro optimization
Yuki Kimoto authored on 2011-07-30
458
    if ($self->{filter}{on}) {
459
        my $applied_filter = {};
460
        foreach my $table (@$tables) {
461
            $applied_filter = {
462
                %$applied_filter,
463
                %{$self->{filter}{out}->{$table} || {}}
464
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
465
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
466
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
467
    }
468
    
cleanup
Yuki Kimoto authored on 2011-04-02
469
    # Replace filter name to code
470
    foreach my $column (keys %$filter) {
471
        my $name = $filter->{$column};
472
        if (!defined $name) {
473
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
474
        }
cleanup
Yuki Kimoto authored on 2011-04-02
475
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
476
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
477
            unless exists $self->filters->{$name};
478
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
479
        }
480
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
481
    
cleanup
Yuki Kimoto authored on 2011-04-02
482
    # Create bind values
483
    my $bind = $self->_create_bind_values(
484
        $param,
485
        $query->columns,
486
        $filter,
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
487
        $type_filters,
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
488
        $bind_type
cleanup
Yuki Kimoto authored on 2011-04-02
489
    );
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
490

            
cleanup
yuki-kimoto authored on 2010-10-17
491
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
492
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
493
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
494
    eval {
495
        for (my $i = 0; $i < @$bind; $i++) {
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
496
            my $bind_type = $bind->[$i]->{bind_type};
497
            $sth->bind_param(
498
                $i + 1,
499
                $bind->[$i]->{value},
500
                $bind_type ? $bind_type : ()
501
            );
cleanup
Yuki Kimoto authored on 2011-03-21
502
        }
503
        $affected = $sth->execute;
504
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
505
    
micro optimization
Yuki Kimoto authored on 2011-07-30
506
    $self->_croak($@, qq{. Following SQL is executed.\n}
507
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
508
    
improved debug message
Yuki Kimoto authored on 2011-05-23
509
    # DEBUG message
510
    if (DEBUG) {
511
        print STDERR "SQL:\n" . $query->sql . "\n";
512
        my @output;
513
        foreach my $b (@$bind) {
514
            my $value = $b->{value};
515
            $value = 'undef' unless defined $value;
516
            $value = encode(DEBUG_ENCODING(), $value)
517
              if utf8::is_utf8($value);
518
            push @output, $value;
519
        }
520
        print STDERR "Bind values: " . join(', ', @output) . "\n\n";
521
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
522
    
cleanup
Yuki Kimoto authored on 2011-04-02
523
    # Select statement
cleanup
yuki-kimoto authored on 2010-10-17
524
    if ($sth->{NUM_OF_FIELDS}) {
525
        
micro optimization
Yuki Kimoto authored on 2011-07-30
526
        # DEPRECATED! Filter
cleanup
Yuki Kimoto authored on 2011-04-02
527
        my $filter = {};
micro optimization
Yuki Kimoto authored on 2011-07-30
528
        if ($self->{filter}{on}) {
529
            $filter->{in}  = {};
530
            $filter->{end} = {};
531
            push @$tables, $main_table if $main_table;
532
            foreach my $table (@$tables) {
533
                foreach my $way (qw/in end/) {
534
                    $filter->{$way} = {
535
                        %{$filter->{$way}},
536
                        %{$self->{filter}{$way}{$table} || {}}
537
                    };
538
                }
cleanup
Yuki Kimoto authored on 2011-04-02
539
            }
cleanup
Yuki Kimoto authored on 2011-01-12
540
        }
541
        
542
        # Result
543
        my $result = $self->result_class->new(
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
544
            sth => $sth,
sub module use DBIx::Custom ...
Yuki Kimoto authored on 2011-08-02
545
            dbi => $self,
cleanup
Yuki Kimoto authored on 2011-01-12
546
            default_filter => $self->{default_in_filter},
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
547
            filter => $filter->{in} || {},
548
            end_filter => $filter->{end} || {},
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
549
            type_rule => {
550
                from1 => $self->type_rule->{from1},
551
                from2 => $self->type_rule->{from2}
552
            },
cleanup
yuki-kimoto authored on 2010-10-17
553
        );
554

            
555
        return $result;
556
    }
cleanup
Yuki Kimoto authored on 2011-04-02
557
    
558
    # Not select statement
559
    else { return $affected }
cleanup
yuki-kimoto authored on 2010-10-17
560
}
561

            
added test
Yuki Kimoto authored on 2011-08-16
562
sub get_table_info {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
563
    my ($self, %args) = @_;
564
    
565
    my $exclude = delete $args{exclude};
566
    croak qq/"$_" is wrong option/ for keys %args;
567
    
added test
Yuki Kimoto authored on 2011-08-16
568
    my $table_info = [];
569
    $self->each_table(
570
        sub { push @$table_info, {table => $_[1], info => $_[2] } },
571
        exclude => $exclude
572
    );
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
573
    
cleanup test
Yuki Kimoto authored on 2011-08-16
574
    return [sort {$a->{table} cmp $b->{table} } @$table_info];
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
575
}
576

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
577
sub get_column_info {
578
    my ($self, %args) = @_;
579
    
580
    my $exclude_table = delete $args{exclude_table};
581
    croak qq/"$_" is wrong option/ for keys %args;
582
    
583
    my $column_info = [];
584
    $self->each_column(
585
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
586
        exclude_table => $exclude_table
587
    );
588
    
589
    return [
590
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
591
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
592
}
593

            
cleanup
yuki-kimoto authored on 2010-10-17
594
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
595
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
596
    
cleanup
yuki-kimoto authored on 2010-10-17
597
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
598
    my $param;
599
    $param = shift if @_ % 2;
600
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
601
    my $table  = delete $args{table};
cleanup
Yuki Kimoto authored on 2011-04-25
602
    croak qq{"table" option must be specified } . _subname
simplified arguments check
Yuki Kimoto authored on 2011-07-11
603
      unless defined $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
604
    my $p = delete $args{param} || {};
605
    $param  ||= $p;
cleanup
Yuki Kimoto authored on 2011-03-21
606
    my $append = delete $args{append} || '';
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
607
    my $id = delete $args{id};
608
    my $primary_key = delete $args{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
609
    croak "insert method primary_key option " .
added tests
Yuki Kimoto authored on 2011-06-08
610
          "must be specified when id is specified " . _subname
611
      if defined $id && !defined $primary_key;
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
612
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
613
    my $prefix = delete $args{prefix};
cleanup
Yuki Kimoto authored on 2011-04-02
614

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
615
    # Merge parameter
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
616
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
617
        my $id_param = $self->_create_param_from_id($id, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
618
        $param = $self->merge_param($id_param, $param);
619
    }
620

            
cleanup
Yuki Kimoto authored on 2011-04-02
621
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-01-27
622
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
623
    push @sql, "insert";
624
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
625
    push @sql, "into " . $self->_q($table) . " " . $self->insert_param($param);
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
626
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
627
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
628
    
629
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
630
    return $self->execute($sql, $param, table => $table, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
631
}
632

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
633
sub insert_param {
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
634
    my ($self, $param) = @_;
635
    
cleanup
Yuki Kimoto authored on 2011-04-02
636
    # Create insert parameter tag
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
637
    my $safety = $self->safety_character;
cleanup
Yuki Kimoto authored on 2011-04-02
638
    my @columns;
639
    my @placeholders;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
640
    foreach my $column (sort keys %$param) {
cleanup
Yuki Kimoto authored on 2011-04-25
641
        croak qq{"$column" is not safety column name } . _subname
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
642
          unless $column =~ /^[$safety\.]+$/;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
643
        my $column_quote = $self->_q($column);
644
        $column_quote =~ s/\./$self->_q(".")/e;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
645
        push @columns, $column_quote;
insert and update method's p...
Yuki Kimoto authored on 2011-07-29
646
        push @placeholders, ref $param->{$column} eq 'SCALAR'
647
          ? ${$param->{$column}} : ":$column";
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
648
    }
649
    
cleanup
Yuki Kimoto authored on 2011-04-02
650
    return '(' . join(', ', @columns) . ') ' . 'values ' .
651
           '(' . join(', ', @placeholders) . ')'
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
652
}
653

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
654
sub include_model {
655
    my ($self, $name_space, $model_infos) = @_;
656
    
cleanup
Yuki Kimoto authored on 2011-04-02
657
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
658
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
659
    
660
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
661
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
662

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
663
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
664
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
665
          if $name_space =~ /[^\w:]/;
666
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
667
        croak qq{Name space module "$name_space.pm" is needed. $@ }
668
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
669
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
670
        
671
        # Search model modules
672
        my $path = $INC{"$name_space.pm"};
673
        $path =~ s/\.pm$//;
674
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
675
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
676
        $model_infos = [];
677
        while (my $module = readdir $dh) {
678
            push @$model_infos, $module
679
              if $module =~ s/\.pm$//;
680
        }
681
        close $dh;
682
    }
683
    
cleanup
Yuki Kimoto authored on 2011-04-02
684
    # Include models
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
685
    foreach my $model_info (@$model_infos) {
686
        
cleanup
Yuki Kimoto authored on 2011-04-02
687
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
688
        my $model_class;
689
        my $model_name;
690
        my $model_table;
691
        if (ref $model_info eq 'HASH') {
692
            $model_class = $model_info->{class};
693
            $model_name  = $model_info->{name};
694
            $model_table = $model_info->{table};
695
            
696
            $model_name  ||= $model_class;
697
            $model_table ||= $model_name;
698
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
699
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
700
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
701
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
702
          if $mclass =~ /[^\w:]/;
703
        unless ($mclass->can('isa')) {
704
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
705
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
706
        }
707
        
cleanup
Yuki Kimoto authored on 2011-04-02
708
        # Create model
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
709
        my $args = {};
710
        $args->{model_class} = $mclass if $mclass;
711
        $args->{name}        = $model_name if $model_name;
712
        $args->{table}       = $model_table if $model_table;
713
        $self->create_model($args);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
714
    }
715
    
716
    return $self;
717
}
718

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
719
sub mapper {
720
    my $self = shift;
721
    return DBIx::Custom::Mapper->new(@_);
722
}
723

            
added EXPERIMENTAL map_param...
Yuki Kimoto authored on 2011-06-24
724
sub map_param {
725
    my $self = shift;
726
    my $param = shift;
727
    my %map = @_;
728
    
729
    # Mapping
730
    my $map_param = {};
731
    foreach my $key (keys %map) {
732
        my $value_cb;
733
        my $condition;
734
        my $map_key;
735
        
736
        # Get mapping information
737
        if (ref $map{$key} eq 'ARRAY') {
738
            foreach my $some (@{$map{$key}}) {
739
                $map_key = $some unless ref $some;
740
                $condition = $some->{if} if ref $some eq 'HASH';
741
                $value_cb = $some if ref $some eq 'CODE';
742
            }
743
        }
744
        else {
745
            $map_key = $map{$key};
746
        }
747
        $value_cb ||= sub { $_[0] };
748
        $condition ||= sub { defined $_[0] && length $_[0] };
749

            
750
        # Map parameter
751
        my $value;
752
        if (ref $condition eq 'CODE') {
753
            $map_param->{$map_key} = $value_cb->($param->{$key})
754
              if $condition->($param->{$key});
755
        }
756
        elsif ($condition eq 'exists') {
757
            $map_param->{$map_key} = $value_cb->($param->{$key})
758
              if exists $param->{$key};
759
        }
760
        else { croak qq/Condition must be code reference or "exists" / . _subname }
761
    }
762
    
763
    return $map_param;
764
}
765

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
766
sub merge_param {
767
    my ($self, @params) = @_;
768
    
cleanup
Yuki Kimoto authored on 2011-04-02
769
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
770
    my $merge = {};
771
    foreach my $param (@params) {
772
        foreach my $column (keys %$param) {
773
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
774
            
775
            if (exists $merge->{$column}) {
776
                $merge->{$column} = [$merge->{$column}]
777
                  unless ref $merge->{$column} eq 'ARRAY';
778
                push @{$merge->{$column}},
779
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
780
            }
781
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
782
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
783
            }
784
        }
785
    }
786
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
787
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
788
}
789

            
cleanup
Yuki Kimoto authored on 2011-03-21
790
sub method {
791
    my $self = shift;
792
    
cleanup
Yuki Kimoto authored on 2011-04-02
793
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
794
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
795
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
796
    
797
    return $self;
798
}
799

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
800
sub model {
801
    my ($self, $name, $model) = @_;
802
    
cleanup
Yuki Kimoto authored on 2011-04-02
803
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
804
    if ($model) {
805
        $self->models->{$name} = $model;
806
        return $self;
807
    }
808
    
809
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
810
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
811
      unless $self->models->{$name};
812
    
cleanup
Yuki Kimoto authored on 2011-04-02
813
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
814
    return $self->models->{$name};
815
}
816

            
cleanup
Yuki Kimoto authored on 2011-03-21
817
sub mycolumn {
818
    my ($self, $table, $columns) = @_;
819
    
cleanup
Yuki Kimoto authored on 2011-04-02
820
    # Create column clause
821
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
822
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
823
    push @column, $self->_q($table) . "." . $self->_q($_) .
824
      " as " . $self->_q($_)
825
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
826
    
827
    return join (', ', @column);
828
}
829

            
added dbi_options attribute
kimoto authored on 2010-12-20
830
sub new {
831
    my $self = shift->SUPER::new(@_);
832
    
cleanup
Yuki Kimoto authored on 2011-04-02
833
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
834
    my @attrs = keys %$self;
835
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
836
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
837
          unless $self->can($attr);
838
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
839

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
840
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
841
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
842
        '?'     => \&DBIx::Custom::Tag::placeholder,
843
        '='     => \&DBIx::Custom::Tag::equal,
844
        '<>'    => \&DBIx::Custom::Tag::not_equal,
845
        '>'     => \&DBIx::Custom::Tag::greater_than,
846
        '<'     => \&DBIx::Custom::Tag::lower_than,
847
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
848
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
849
        'like'  => \&DBIx::Custom::Tag::like,
850
        'in'    => \&DBIx::Custom::Tag::in,
851
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
852
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
853
    };
854
    
855
    return $self;
856
}
857

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
858
sub not_exists { DBIx::Custom::NotExists->singleton }
cleanup
Yuki Kimoto authored on 2011-08-13
859

            
860
sub order {
861
    my $self = shift;
862
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
863
}
864

            
cleanup
yuki-kimoto authored on 2010-10-17
865
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
866
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
867
    
868
    # Register filter
869
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
870
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
871
    
cleanup
Yuki Kimoto authored on 2011-04-02
872
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
873
}
packaging one directory
yuki-kimoto authored on 2009-11-16
874

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
878
    # Arguments
cleanup
Yuki Kimoto authored on 2011-03-21
879
    my $table = delete $args{table};
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
880
    my $tables = ref $table eq 'ARRAY' ? $table
881
               : defined $table ? [$table]
882
               : [];
cleanup
Yuki Kimoto authored on 2011-03-21
883
    my $columns   = delete $args{column};
884
    my $where     = delete $args{where} || {};
885
    my $append    = delete $args{append};
886
    my $join      = delete $args{join} || [];
cleanup
Yuki Kimoto authored on 2011-04-25
887
    croak qq{"join" must be array reference } . _subname
- added experimental DBIx::C...
Yuki Kimoto authored on 2011-03-08
888
      unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-03-21
889
    my $relation = delete $args{relation};
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
890
    warn "select() relation option is DEPRECATED!"
added warnings
Yuki Kimoto authored on 2011-06-07
891
      if $relation;
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
892
    my $param = delete $args{param} || {}; # DEPRECATED!
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
893
    warn "select() param option is DEPRECATED!"
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
894
      if keys %$param;
895
    my $where_param = delete $args{where_param} || $param || {};
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
896
    my $wrap = delete $args{wrap};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
897
    my $id = delete $args{id};
898
    my $primary_key = delete $args{primary_key};
899
    croak "update method primary_key option " .
900
          "must be specified when id is specified " . _subname
901
      if defined $id && !defined $primary_key;
902
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
903
    my $prefix = delete $args{prefix};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
904
    
cleanup
Yuki Kimoto authored on 2011-03-09
905
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-03-21
906
    $self->_add_relation_table($tables, $relation);
packaging one directory
yuki-kimoto authored on 2009-11-16
907
    
cleanup
Yuki Kimoto authored on 2011-04-02
908
    # Select statement
cleanup
Yuki Kimoto authored on 2011-01-27
909
    my @sql;
910
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
911
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
912
    # Prefix
913
    push @sql, $prefix if defined $prefix;
914
    
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
915
    # Column clause
cleanup
Yuki Kimoto authored on 2011-03-30
916
    if ($columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-07
917
        $columns = [$columns] unless ref $columns eq 'ARRAY';
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
918
        foreach my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
919
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
920
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
921
            }
922
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
923
                if (@$column == 3 && $column->[1] eq 'as') {
924
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
925
                    splice @$column, 1, 1;
926
                }
927
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
928
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
929
            }
cleanup
Yuki Kimoto authored on 2011-04-02
930
            unshift @$tables, @{$self->_search_tables($column)};
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
931
            push @sql, ($column, ',');
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
932
        }
removed EXPERIMETNAL select(...
Yuki Kimoto authored on 2011-04-01
933
        pop @sql if $sql[-1] eq ',';
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
934
    }
935
    else { push @sql, '*' }
936
    
937
    # Table
cleanup
Yuki Kimoto authored on 2011-03-30
938
    push @sql, 'from';
939
    if ($relation) {
940
        my $found = {};
941
        foreach my $table (@$tables) {
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
942
            push @sql, ($self->_q($table), ',') unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
943
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
944
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
945
    }
cleanup
Yuki Kimoto authored on 2011-03-30
946
    else {
947
        my $main_table = $tables->[-1] || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
948
        push @sql, $self->_q($main_table);
cleanup
Yuki Kimoto authored on 2011-03-30
949
    }
950
    pop @sql if ($sql[-1] || '') eq ',';
cleanup
Yuki Kimoto authored on 2011-04-25
951
    croak "Not found table name " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
952
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
953

            
cleanup
Yuki Kimoto authored on 2011-04-02
954
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
955
    unshift @$tables,
956
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
957
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
958
    # Where
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
959
    my $where_clause = '';
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
960
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
updated pod
Yuki Kimoto authored on 2011-06-21
961
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
962
        $where_clause = "where " . $where->[0];
963
        $where_param = $where->[1];
964
    }
965
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-04-25
966
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
967
        $where_param = keys %$where_param
968
                     ? $self->merge_param($where_param, $where->param)
969
                     : $where->param;
cleanup
Yuki Kimoto authored on 2011-04-25
970
        
971
        # String where
972
        $where_clause = $where->to_string;
973
    }
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
974
    elsif ($where) { $where_clause = "where $where" }
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
975
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
976
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-04-02
977
    unshift @$tables, @{$self->_search_tables($where_clause)};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
978
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
979
    # Push join
980
    $self->_push_join(\@sql, $join, $tables);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
981
    
cleanup
Yuki Kimoto authored on 2011-03-09
982
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-04-02
983
    push @sql, $where_clause;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
984
    
cleanup
Yuki Kimoto authored on 2011-03-08
985
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-04-02
986
    $self->_push_relation(\@sql, $tables, $relation, $where_clause eq '' ? 1 : 0);
cleanup
Yuki Kimoto authored on 2011-03-08
987
    
cleanup
Yuki Kimoto authored on 2011-04-02
988
    # Append
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
989
    push @sql, $append if defined $append;
cleanup
Yuki Kimoto authored on 2011-01-27
990
    
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
991
    # Wrap
992
    if ($wrap) {
cleanup
Yuki Kimoto authored on 2011-04-25
993
        croak "wrap option must be array refrence " . _subname
added EXPERIMENTAL select() ...
Yuki Kimoto authored on 2011-04-19
994
          unless ref $wrap eq 'ARRAY';
995
        unshift @sql, $wrap->[0];
996
        push @sql, $wrap->[1];
997
    }
998
    
cleanup
Yuki Kimoto authored on 2011-01-27
999
    # SQL
1000
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
1001
    
1002
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1003
    my $result = $self->execute($sql, $where_param, table => $tables, %args);
packaging one directory
yuki-kimoto authored on 2009-11-16
1004
    
1005
    return $result;
1006
}
1007

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1008
sub setup_model {
1009
    my $self = shift;
1010
    
cleanup
Yuki Kimoto authored on 2011-04-02
1011
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1012
    $self->each_column(
1013
        sub {
1014
            my ($self, $table, $column, $column_info) = @_;
1015
            if (my $model = $self->models->{$table}) {
1016
                push @{$model->columns}, $column;
1017
            }
1018
        }
1019
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1020
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1021
}
1022

            
update pod
Yuki Kimoto authored on 2011-08-10
1023
sub show_datatype {
1024
    my ($self, $table) = @_;
1025
    croak "Table name must be specified" unless defined $table;
1026
    print "$table\n";
1027
    
1028
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1029
    my $sth = $result->sth;
1030

            
1031
    my $columns = $sth->{NAME};
1032
    my $data_types = $sth->{TYPE};
1033
    
1034
    for (my $i = 0; $i < @$columns; $i++) {
1035
        my $column = $columns->[$i];
1036
        my $data_type = $data_types->[$i];
1037
        print "$column: $data_type\n";
1038
    }
1039
}
1040

            
1041
sub show_typename {
1042
    my ($self, $t) = @_;
1043
    croak "Table name must be specified" unless defined $t;
1044
    print "$t\n";
1045
    
1046
    $self->each_column(sub {
1047
        my ($self, $table, $column, $infos) = @_;
1048
        return unless $table eq $t;
1049
        my $typename = $infos->{TYPE_NAME};
1050
        print "$column: $typename\n";
1051
    });
1052
    
1053
    return $self;
1054
}
1055

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1056
sub show_tables {
1057
    my $self = shift;
1058
    
1059
    my %tables;
1060
    $self->each_table(sub { $tables{$_[1]}++ });
1061
    print join("\n", sort keys %tables) . "\n";
1062
    return $self;
1063
}
1064

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1065
sub type_rule {
1066
    my $self = shift;
1067
    
1068
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
1069
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1070
        
1071
        # Into
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1072
        foreach my $i (1 .. 2) {
1073
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
1074
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1075
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
1076
            $self->{type_rule} = $type_rule;
1077
            $self->{"_$into"} = {};
1078
            foreach my $type_name (keys %{$type_rule->{$into} || {}}) {
1079
                croak qq{type name of $into section must be lower case}
1080
                  if $type_name =~ /[A-Z]/;
1081
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1082
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1083
            $self->each_column(sub {
1084
                my ($dbi, $table, $column, $column_info) = @_;
1085
                
1086
                my $type_name = lc $column_info->{TYPE_NAME};
1087
                if ($type_rule->{$into} &&
1088
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1089
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1090
                    return unless exists $type_rule->{$into}->{$type_name};
1091
                    if  (defined $filter && ref $filter ne 'CODE') 
1092
                    {
1093
                        my $fname = $filter;
1094
                        croak qq{Filter "$fname" is not registered" } . _subname
1095
                          unless exists $self->filters->{$fname};
1096
                        
1097
                        $filter = $self->filters->{$fname};
1098
                    }
1099

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1100
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1101
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1102
                }
1103
            });
1104
        }
1105

            
1106
        # From
1107
        foreach my $i (1 .. 2) {
1108
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
1109
            foreach my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
1110
                croak qq{data type of from$i section must be lower case or number}
1111
                  if $data_type =~ /[A-Z]/;
1112
                my $fname = $type_rule->{"from$i"}{$data_type};
1113
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1114
                    croak qq{Filter "$fname" is not registered" } . _subname
1115
                      unless exists $self->filters->{$fname};
1116
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1117
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1118
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1119
            }
1120
        }
1121
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1122
        return $self;
1123
    }
1124
    
1125
    return $self->{type_rule} || {};
1126
}
1127

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1131
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1132
    my $param;
1133
    $param = shift if @_ % 2;
1134
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1135
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1136
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1137
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1138
    my $p = delete $args{param} || {};
1139
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1140
    my $where = delete $args{where} || {};
1141
    my $where_param = delete $args{where_param} || {};
1142
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1143
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1144
    my $id = delete $args{id};
1145
    my $primary_key = delete $args{primary_key};
1146
    croak "update method primary_key option " .
1147
          "must be specified when id is specified " . _subname
1148
      if defined $id && !defined $primary_key;
1149
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1150
    my $prefix = delete $args{prefix};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1151

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

            
1155
    # Where
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1156
    $where = $self->_create_param_from_id($id, $primary_key) if defined $id;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1157
    my $where_clause = '';
updated pod
Yuki Kimoto authored on 2011-06-21
1158
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1159
        $where_clause = "where " . $where->[0];
1160
        $where_param = $where->[1];
1161
    }
1162
    elsif (ref $where) {
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1163
        $where = $self->_where_to_obj($where);
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1164
        $where_param = keys %$where_param
1165
                     ? $self->merge_param($where_param, $where->param)
1166
                     : $where->param;
select, update, and delete w...
Yuki Kimoto authored on 2011-04-25
1167
        
1168
        # String where
1169
        $where_clause = $where->to_string;
1170
    }
1171
    elsif ($where) { $where_clause = "where $where" }
cleanup
Yuki Kimoto authored on 2011-04-25
1172
    croak qq{"where" must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1173
      if "$where_clause" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1174
    
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1175
    # Merge param
1176
    $param = $self->merge_param($param, $where_param) if keys %$where_param;
1177
    
cleanup
Yuki Kimoto authored on 2011-04-02
1178
    # Update statement
cleanup
Yuki Kimoto authored on 2011-01-27
1179
    my @sql;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1180
    push @sql, "update";
1181
    push @sql, $prefix if defined $prefix;
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1182
    push @sql, $self->_q($table) . " $update_clause $where_clause";
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1183
    push @sql, $append if defined $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1184
    
cleanup
Yuki Kimoto authored on 2011-01-27
1185
    # SQL
1186
    my $sql = join(' ', @sql);
1187
    
cleanup
yuki-kimoto authored on 2010-10-17
1188
    # Execute query
updated pod
Yuki Kimoto authored on 2011-06-21
1189
    return $self->execute($sql, $param, table => $table, %args);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1190
}
1191

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1194
sub update_param {
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1195
    my ($self, $param, $opt) = @_;
1196
    
cleanup
Yuki Kimoto authored on 2011-04-02
1197
    # Create update parameter tag
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1198
    my $tag = $self->assign_param($param);
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1199
    $tag = "set $tag" unless $opt->{no_set};
1200

            
cleanup
Yuki Kimoto authored on 2011-04-02
1201
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1202
}
1203

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1206
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1207
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1208
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1209
    
updated pod
Yuki Kimoto authored on 2011-06-21
1210
    # Cache
1211
    my $cache = $self->cache;
1212
    
1213
    # Query
1214
    my $query;
1215
    
1216
    # Get cached query
1217
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1218
        
updated pod
Yuki Kimoto authored on 2011-06-21
1219
        # Get query
1220
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1221
        
updated pod
Yuki Kimoto authored on 2011-06-21
1222
        # Create query
1223
        if ($q) {
1224
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1225
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1226
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1227
    }
1228
    
1229
    # Create query
1230
    unless ($query) {
1231

            
1232
        # Create query
1233
        my $builder = $self->query_builder;
1234
        $query = $builder->build_query($source);
1235

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

            
1242
        # Save query to cache
1243
        $self->cache_method->(
1244
            $self, $source,
1245
            {
1246
                sql     => $query->sql, 
1247
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1248
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1249
            }
1250
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1251
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1252

            
1253
    # Filter SQL
1254
    if ($sqlfilter) {
1255
        my $sql = $query->sql;
1256
        $sql = $sqlfilter->($sql);
1257
        $query->sql($sql);
1258
    }
1259
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1260
    # Save sql
1261
    $self->last_sql($query->sql);
1262
    
updated pod
Yuki Kimoto authored on 2011-06-21
1263
    # Prepare statement handle
1264
    my $sth;
1265
    eval { $sth = $self->dbh->prepare($query->{sql})};
1266
    
1267
    if ($@) {
1268
        $self->_croak($@, qq{. Following SQL is executed.\n}
1269
                        . qq{$query->{sql}\n} . _subname);
1270
    }
1271
    
1272
    # Set statement handle
1273
    $query->sth($sth);
1274
    
1275
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1276
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1277
    
1278
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1279
}
1280

            
cleanup
Yuki Kimoto authored on 2011-04-02
1281
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1282
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1283
    
cleanup
Yuki Kimoto authored on 2011-04-02
1284
    # Create bind values
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1285
    my $bind = [];
removed reconnect method
yuki-kimoto authored on 2010-05-28
1286
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1287
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
1288
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1289
        
1290
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1291
        my $value;
1292
        if(ref $params->{$column} eq 'ARRAY') {
1293
            my $i = $count->{$column} || 0;
1294
            $i += $not_exists->{$column} || 0;
1295
            my $found;
1296
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1297
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
1298
                    $not_exists->{$column}++;
1299
                }
1300
                else  {
1301
                    $value = $params->{$column}->[$k];
1302
                    $found = 1;
1303
                    last
1304
                }
1305
            }
1306
            next unless $found;
1307
        }
1308
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1309
        
cleanup
Yuki Kimoto authored on 2011-01-12
1310
        # Filter
1311
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1312
        $value = $f->($value) if $f;
1313
        
1314
        # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1315
        foreach my $i (1 .. 2) {
1316
            my $type_filter = $type_filters->{$i};
micro optimization
Yuki Kimoto authored on 2011-07-30
1317
            my $tf = $self->{"_into$i"}->{dot}->{$column} || $type_filter->{$column};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1318
            $value = $tf->($value) if $tf;
1319
        }
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
1320
        
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1321
        # Bind values
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1322
        push @$bind, {value => $value, bind_type => $bind_type->{$column}};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1323
        
1324
        # Count up 
1325
        $count->{$column}++;
1326
    }
1327
    
- added EXPERIMENTAL type() ...
Yuki Kimoto authored on 2011-03-21
1328
    return $bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1329
}
1330

            
cleanup
Yuki Kimoto authored on 2011-06-08
1331
sub _create_param_from_id {
1332
    my ($self, $id, $primary_keys) = @_;
improved error messages
Yuki Kimoto authored on 2011-04-18
1333
    
cleanup
Yuki Kimoto authored on 2011-06-08
1334
    # Create parameter
1335
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1336
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1337
        $id = [$id] unless ref $id;
1338
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1339
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1340
          unless !ref $id || ref $id eq 'ARRAY';
1341
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1342
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1343
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1344
        for(my $i = 0; $i < @$primary_keys; $i ++) {
cleanup
Yuki Kimoto authored on 2011-06-08
1345
           $param->{$primary_keys->[$i]} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1346
        }
1347
    }
1348
    
cleanup
Yuki Kimoto authored on 2011-06-08
1349
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1350
}
1351

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1352
sub _connect {
1353
    my $self = shift;
1354
    
1355
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1356
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1357
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1358
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1359
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1360
    croak qq{"dsn" must be specified } . _subname
1361
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1362
    my $user        = $self->user;
1363
    my $password    = $self->password;
1364
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added warnings
Yuki Kimoto authored on 2011-06-07
1365
    warn "dbi_options is DEPRECATED! use dbi_option instead\n"
1366
      if keys %{$self->dbi_options};
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1367
    
cleanup
Yuki Kimoto authored on 2011-08-16
1368
    $dbi_option = {%{$self->default_dbi_option}, %$dbi_option};
1369
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1370
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1371
    my $dbh;
1372
    eval {
1373
        $dbh = DBI->connect(
1374
            $dsn,
1375
            $user,
1376
            $password,
1377
            $dbi_option
1378
        );
1379
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1380
    
1381
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1382
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1383
    
1384
    return $dbh;
1385
}
1386

            
cleanup
yuki-kimoto authored on 2010-10-17
1387
sub _croak {
1388
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1389
    
1390
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1391
    $append ||= "";
1392
    
1393
    # Verbose
1394
    if ($Carp::Verbose) { croak $error }
1395
    
1396
    # Not verbose
1397
    else {
1398
        
1399
        # Remove line and module infromation
1400
        my $at_pos = rindex($error, ' at ');
1401
        $error = substr($error, 0, $at_pos);
1402
        $error =~ s/\s+$//;
1403
        croak "$error$append";
1404
    }
1405
}
1406

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1409
sub _need_tables {
1410
    my ($self, $tree, $need_tables, $tables) = @_;
1411
    
cleanup
Yuki Kimoto authored on 2011-04-02
1412
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1413
    foreach my $table (@$tables) {
1414
        if ($tree->{$table}) {
1415
            $need_tables->{$table} = 1;
1416
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1417
        }
1418
    }
1419
}
1420

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1421
sub _push_join {
1422
    my ($self, $sql, $join, $join_tables) = @_;
1423
    
cleanup
Yuki Kimoto authored on 2011-04-02
1424
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1425
    return unless @$join;
1426
    
cleanup
Yuki Kimoto authored on 2011-04-02
1427
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1428
    my $tree = {};
1429
    for (my $i = 0; $i < @$join; $i++) {
1430
        
cleanup
Yuki Kimoto authored on 2011-07-28
1431
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1432
        my $join_clause;;
1433
        my $option;
1434
        if (ref $join->[$i] eq 'HASH') {
1435
            $join_clause = $join->[$i]->{clause};
1436
            $option = {table => $join->[$i]->{table}};
1437
        }
1438
        else {
1439
            $join_clause = $join->[$i];
1440
            $option = {};
1441
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1442

            
1443
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1444
        my $table1;
1445
        my $table2;
1446
        if (my $table = $option->{table}) {
1447
            $table1 = $table->[0];
1448
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1449
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1450
        else {
1451
            my $q = $self->_quote;
1452
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1453
            $j_clause =~ s/'.+?'//g;
1454
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1455
            $j_clause =~ s/[$q_re]//g;
cleanup
Yuki Kimoto authored on 2011-07-28
1456
            my $c = $self->safety_character;
1457
            my $join_re = qr/(?:^|\s)($c+)\.$c+\s+=\s+($c+)\.$c+/;
1458
            if ($j_clause =~ $join_re) {
1459
                $table1 = $1;
1460
                $table2 = $2;
1461
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1462
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1463
        croak qq{join clause must have two table name after "on" keyword. } .
1464
              qq{"$join_clause" is passed }  . _subname
1465
          unless defined $table1 && defined $table2;
1466
        croak qq{right side table of "$join_clause" must be unique }
1467
            . _subname
1468
          if exists $tree->{$table2};
1469
        croak qq{Same table "$table1" is specified} . _subname
1470
          if $table1 eq $table2;
1471
        $tree->{$table2}
1472
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1473
    }
1474
    
cleanup
Yuki Kimoto authored on 2011-04-02
1475
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1476
    my $need_tables = {};
1477
    $self->_need_tables($tree, $need_tables, $join_tables);
1478
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1479
    
1480
    # Add join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1481
    foreach my $need_table (@need_tables) {
1482
        push @$sql, $tree->{$need_table}{join};
1483
    }
1484
}
cleanup
Yuki Kimoto authored on 2011-03-08
1485

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1486
sub _quote {
1487
    my $self = shift;
1488
    
1489
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1490
         : defined $self->quote ? $self->quote
1491
         : '';
1492
}
1493

            
cleanup
Yuki Kimoto authored on 2011-07-29
1494
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1495
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1496
    
1497
    my $quote = $self->_quote;
1498
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1499
    my $p;
1500
    if (defined $quote && length $quote > 1) {
1501
        $p = substr($quote, 1, 1);
1502
    }
1503
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1504
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1505
    if ($quotemeta) {
1506
        $q = quotemeta($q);
1507
        $p = quotemeta($p);
1508
    }
1509
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1510
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1511
}
1512

            
cleanup
Yuki Kimoto authored on 2011-04-02
1513
sub _remove_duplicate_table {
1514
    my ($self, $tables, $main_table) = @_;
1515
    
1516
    # Remove duplicate table
1517
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1518
    delete $tables{$main_table} if $main_table;
1519
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1520
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1521
    if (my $q = $self->_quote) {
1522
        $q = quotemeta($q);
1523
        $_ =~ s/[$q]//g for @$new_tables;
1524
    }
1525

            
1526
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1527
}
1528

            
cleanup
Yuki Kimoto authored on 2011-04-02
1529
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1530
    my ($self, $source) = @_;
1531
    
cleanup
Yuki Kimoto authored on 2011-04-02
1532
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1533
    my $tables = [];
1534
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1535
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1536
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1537
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1538
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1539
    while ($source =~ /$table_re/g) {
1540
        push @$tables, $1;
1541
    }
1542
    
1543
    return $tables;
1544
}
1545

            
cleanup
Yuki Kimoto authored on 2011-04-02
1546
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1547
    my ($self, $where) = @_;
1548
    
cleanup
Yuki Kimoto authored on 2011-04-02
1549
    my $obj;
1550
    
1551
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1552
    if (ref $where eq 'HASH') {
1553
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1554
        my $q = $self->_quote;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1555
        foreach my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1556
            my $table;
1557
            my $c;
1558
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1559
                $table = $1;
1560
                $c = $2;
1561
            }
1562
            
1563
            my $table_quote;
1564
            $table_quote = $self->_q($table) if defined $table;
1565
            my $column_quote = $self->_q($c);
1566
            $column_quote = $table_quote . '.' . $column_quote
1567
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1568
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1569
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1570
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1571
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1572
    
1573
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1574
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1575
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1576
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1577
    
updated pod
Yuki Kimoto authored on 2011-06-21
1578
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1579
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1580
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1581
            clause => $where->[0],
1582
            param  => $where->[1]
1583
        );
1584
    }
1585
    
cleanup
Yuki Kimoto authored on 2011-04-02
1586
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1587
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1588
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1589
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1590
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1591
    
cleanup
Yuki Kimoto authored on 2011-04-02
1592
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1593
}
1594

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

            
1598
    # Initialize filters
1599
    $self->{filter} ||= {};
micro optimization
Yuki Kimoto authored on 2011-07-30
1600
    $self->{filter}{on} = 1;
updated pod
Yuki Kimoto authored on 2011-06-21
1601
    $self->{filter}{out} ||= {};
1602
    $self->{filter}{in} ||= {};
1603
    $self->{filter}{end} ||= {};
1604
    
1605
    # Usage
1606
    my $usage = "Usage: \$dbi->apply_filter(" .
1607
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
1608
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
1609
    
1610
    # Apply filter
1611
    for (my $i = 0; $i < @cinfos; $i += 2) {
1612
        
1613
        # Column
1614
        my $column = $cinfos[$i];
1615
        if (ref $column eq 'ARRAY') {
1616
            foreach my $c (@$column) {
1617
                push @cinfos, $c, $cinfos[$i + 1];
1618
            }
1619
            next;
1620
        }
1621
        
1622
        # Filter infomation
1623
        my $finfo = $cinfos[$i + 1] || {};
1624
        croak "$usage (table: $table) " . _subname
1625
          unless  ref $finfo eq 'HASH';
1626
        foreach my $ftype (keys %$finfo) {
1627
            croak "$usage (table: $table) " . _subname
1628
              unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; 
1629
        }
1630
        
1631
        # Set filters
1632
        foreach my $way (qw/in out end/) {
1633
        
1634
            # Filter
1635
            my $filter = $finfo->{$way};
1636
            
1637
            # Filter state
1638
            my $state = !exists $finfo->{$way} ? 'not_exists'
1639
                      : !defined $filter        ? 'not_defined'
1640
                      : ref $filter eq 'CODE'   ? 'code'
1641
                      : 'name';
1642
            
1643
            # Filter is not exists
1644
            next if $state eq 'not_exists';
1645
            
1646
            # Check filter name
1647
            croak qq{Filter "$filter" is not registered } . _subname
1648
              if  $state eq 'name'
1649
               && ! exists $self->filters->{$filter};
1650
            
1651
            # Set filter
1652
            my $f = $state eq 'not_defined' ? undef
1653
                  : $state eq 'code'        ? $filter
1654
                  : $self->filters->{$filter};
1655
            $self->{filter}{$way}{$table}{$column} = $f;
1656
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
1657
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
1658
            $self->{filter}{$way}{$table}{"${table}-$column"} = $f;
1659
        }
1660
    }
1661
    
1662
    return $self;
1663
}
1664

            
1665
# DEPRECATED!
1666
sub create_query {
1667
    warn "create_query is DEPRECATED! use query option of each method";
1668
    shift->_create_query(@_);
1669
}
1670

            
cleanup
Yuki Kimoto authored on 2011-06-13
1671
# DEPRECATED!
1672
sub apply_filter {
1673
    my $self = shift;
1674
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1675
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1676
    return $self->_apply_filter(@_);
1677
}
1678

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1686
    # Arguments
1687
    my $primary_keys = delete $args{primary_key};
1688
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1689
    my $where = delete $args{where};
1690
    my $param = delete $args{param};
1691
    
1692
    # Check arguments
1693
    foreach my $name (keys %args) {
1694
        croak qq{"$name" is wrong option } . _subname
1695
          unless $SELECT_AT_ARGS{$name};
1696
    }
1697
    
1698
    # Table
1699
    croak qq{"table" option must be specified } . _subname
1700
      unless $args{table};
1701
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1702
    
1703
    # Create where parameter
1704
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1705
    
1706
    return $self->select(where => $where_param, %args);
1707
}
1708

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

            
1714
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1715
    
1716
    # Arguments
1717
    my $primary_keys = delete $args{primary_key};
1718
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1719
    my $where = delete $args{where};
1720
    
1721
    # Check arguments
1722
    foreach my $name (keys %args) {
1723
        croak qq{"$name" is wrong option } . _subname
1724
          unless $DELETE_AT_ARGS{$name};
1725
    }
1726
    
1727
    # Create where parameter
1728
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1729
    
1730
    return $self->delete(where => $where_param, %args);
1731
}
1732

            
cleanup
Yuki Kimoto authored on 2011-06-08
1733
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1734
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1735
sub update_at {
1736
    my $self = shift;
1737

            
1738
    warn "update_at is DEPRECATED! use update and id option instead";
1739
    
1740
    # Arguments
1741
    my $param;
1742
    $param = shift if @_ % 2;
1743
    my %args = @_;
1744
    my $primary_keys = delete $args{primary_key};
1745
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1746
    my $where = delete $args{where};
1747
    my $p = delete $args{param} || {};
1748
    $param  ||= $p;
1749
    
1750
    # Check arguments
1751
    foreach my $name (keys %args) {
1752
        croak qq{"$name" is wrong option } . _subname
1753
          unless $UPDATE_AT_ARGS{$name};
1754
    }
1755
    
1756
    # Create where parameter
1757
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1758
    
1759
    return $self->update(where => $where_param, param => $param, %args);
1760
}
1761

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1762
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1763
our %INSERT_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1764
sub insert_at {
1765
    my $self = shift;
1766
    
1767
    warn "insert_at is DEPRECATED! use insert and id option instead";
1768
    
1769
    # Arguments
1770
    my $param;
1771
    $param = shift if @_ % 2;
1772
    my %args = @_;
1773
    my $primary_key = delete $args{primary_key};
1774
    $primary_key = [$primary_key] unless ref $primary_key;
1775
    my $where = delete $args{where};
1776
    my $p = delete $args{param} || {};
1777
    $param  ||= $p;
1778
    
1779
    # Check arguments
1780
    foreach my $name (keys %args) {
1781
        croak qq{"$name" is wrong option } . _subname
1782
          unless $INSERT_AT_ARGS{$name};
1783
    }
1784
    
1785
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-06-08
1786
    my $where_param = $self->_create_param_from_id($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1787
    $param = $self->merge_param($where_param, $param);
1788
    
1789
    return $self->insert(param => $param, %args);
1790
}
1791

            
added warnings
Yuki Kimoto authored on 2011-06-07
1792
# DEPRECATED!
1793
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1794
    my $self = shift;
1795
    
added warnings
Yuki Kimoto authored on 2011-06-07
1796
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1797
    
1798
    # Merge tag
1799
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1800
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1801
    
1802
    return $self;
1803
}
1804

            
1805
# DEPRECATED!
1806
sub register_tag_processor {
1807
    my $self = shift;
1808
    warn "register_tag_processor is DEPRECATED!";
1809
    # Merge tag
1810
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1811
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1812
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1813
}
1814

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1815
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1816
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1817
has dbi_options => sub { {} };
1818
has filter_check  => 1;
1819
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1820

            
cleanup
Yuki Kimoto authored on 2011-01-25
1821
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1822
sub default_bind_filter {
1823
    my $self = shift;
1824
    
cleanup
Yuki Kimoto authored on 2011-06-13
1825
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1826
    
cleanup
Yuki Kimoto authored on 2011-01-12
1827
    if (@_) {
1828
        my $fname = $_[0];
1829
        
1830
        if (@_ && !$fname) {
1831
            $self->{default_out_filter} = undef;
1832
        }
1833
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1834
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1835
              unless exists $self->filters->{$fname};
1836
        
1837
            $self->{default_out_filter} = $self->filters->{$fname};
1838
        }
1839
        return $self;
1840
    }
1841
    
1842
    return $self->{default_out_filter};
1843
}
1844

            
cleanup
Yuki Kimoto authored on 2011-01-25
1845
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1846
sub default_fetch_filter {
1847
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1848

            
cleanup
Yuki Kimoto authored on 2011-06-13
1849
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1850
    
1851
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1852
        my $fname = $_[0];
1853

            
cleanup
Yuki Kimoto authored on 2011-01-12
1854
        if (@_ && !$fname) {
1855
            $self->{default_in_filter} = undef;
1856
        }
1857
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1858
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1859
              unless exists $self->filters->{$fname};
1860
        
1861
            $self->{default_in_filter} = $self->filters->{$fname};
1862
        }
1863
        
1864
        return $self;
1865
    }
1866
    
many changed
Yuki Kimoto authored on 2011-01-23
1867
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1868
}
1869

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1870
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1871
sub insert_param_tag {
1872
    warn "insert_param_tag is DEPRECATED! " .
1873
         "use insert_param instead!";
1874
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1875
}
1876

            
1877
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1878
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1879
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1880
         "use update_param instead";
1881
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1882
}
cleanup
Yuki Kimoto authored on 2011-03-08
1883
# DEPRECATED!
1884
sub _push_relation {
1885
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1886
    
1887
    if (keys %{$relation || {}}) {
1888
        push @$sql, $need_where ? 'where' : 'and';
1889
        foreach my $rcolumn (keys %$relation) {
1890
            my $table1 = (split (/\./, $rcolumn))[0];
1891
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1892
            push @$tables, ($table1, $table2);
1893
            push @$sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
1894
        }
1895
    }
1896
    pop @$sql if $sql->[-1] eq 'and';    
1897
}
1898

            
1899
# DEPRECATED!
1900
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1901
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1902
    
1903
    if (keys %{$relation || {}}) {
1904
        foreach my $rcolumn (keys %$relation) {
1905
            my $table1 = (split (/\./, $rcolumn))[0];
1906
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1907
            my $table1_exists;
1908
            my $table2_exists;
1909
            foreach my $table (@$tables) {
1910
                $table1_exists = 1 if $table eq $table1;
1911
                $table2_exists = 1 if $table eq $table2;
1912
            }
1913
            unshift @$tables, $table1 unless $table1_exists;
1914
            unshift @$tables, $table2 unless $table2_exists;
1915
        }
1916
    }
1917
}
1918

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1921
=head1 NAME
1922

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
1925
=head1 SYNOPSIS
cleanup
yuki-kimoto authored on 2010-08-05
1926

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1927
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1928
    
1929
    # Connect
1930
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1931
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1932
        user => 'ken',
1933
        password => '!LFKD%$&',
1934
        dbi_option => {mysql_enable_utf8 => 1}
1935
    );
cleanup
yuki-kimoto authored on 2010-08-05
1936

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1937
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1938
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1939
    
1940
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1941
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1942
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1943
    
1944
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1945
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1946

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1951
    # Select, more complex
1952
    my $result = $dbi->select(
1953
        table  => 'book',
1954
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1955
            {book => [qw/title author/]},
1956
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1957
        ],
1958
        where  => {'book.author' => 'Ken'},
1959
        join => ['left outer join company on book.company_id = company.id'],
1960
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1961
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1962
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1963
    # Fetch
1964
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1965
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1966
    }
1967
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1968
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
1969
    while (my $row = $result->fetch_hash) {
1970
        
1971
    }
1972
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1973
    # Execute SQL with parameter.
1974
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1975
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
1976
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1977
    );
1978
    
fix heading typos
Terrence Brannon authored on 2011-08-17
1979
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
1980

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1996
Named place holder support
1997

            
1998
=item *
1999

            
cleanup
Yuki Kimoto authored on 2011-07-29
2000
Model support
2001

            
2002
=item *
2003

            
2004
Connection manager support
2005

            
2006
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2007

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

            
2012
=item *
2013

            
2014
Filtering by data type or column name(EXPERIMENTAL)
2015

            
2016
=item *
2017

            
2018
Create C<order by> clause flexibly(EXPERIMENTAL)
2019

            
2020
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2021

            
fix heading typos
Terrence Brannon authored on 2011-08-17
2022
=head1 DOCUMENTATION
pod fix
Yuki Kimoto authored on 2011-01-21
2023

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2029
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2030
L<DBIx::Custom::Result>,
2031
L<DBIx::Custom::Query>,
2032
L<DBIx::Custom::Where>,
2033
L<DBIx::Custom::Model>,
2034
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2035

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

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

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

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

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

            
2049
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2050
        "dbi:mysql:database=$database",
2051
        $user,
2052
        $password,
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2053
        DBIx::Custom->new->default_dbi_option
2054
    );
2055
    
updated pod
Yuki Kimoto authored on 2011-06-21
2056
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2057

            
cleanup
Yuki Kimoto authored on 2011-08-16
2058
If C<connector> is set to 1 when connect method is called,
2059
L<DBIx::Connector> is automatically set to C<connector>
2060

            
2061
    my $dbi = DBIx::Custom->connect(
2062
      dsn => $dsn, user => $user, password => $password, connector => 1);
2063
    
2064
    my $connector = $dbi->connector; # DBIx::Connector
2065

            
2066
Note that L<DBIx::Connector> must be installed.
2067

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

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

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

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

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

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

            
2083
=head2 C<default_dbi_option>
2084

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2091
    {
2092
        RaiseError => 1,
2093
        PrintError => 0,
2094
        AutoCommit => 1,
2095
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2096

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

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

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

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

            
2106
    my $last_sql = $dbi->last_sql;
2107
    $dbi = $dbi->last_sql($last_sql);
2108

            
2109
Get last successed SQL executed by C<execute> method.
2110

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2118
=head2 C<password>
2119

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2140
You can set quote pair.
2141

            
2142
    $dbi->quote('[]');
2143

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

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

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

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

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

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

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

            
2161
    my $separator = $self->separator;
2162
    $dbi = $self->separator($separator);
2163

            
2164
Separator whichi join table and column.
2165
This is used by C<column> and C<mycolumn> method.
2166

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

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

            
2172
Regex matching system table.
2173
this regex match is used by C<each_table> method and C<each_column> method
2174
System table is ignored.
2175
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2176
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2177
The performance is up.
2178

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

            
2181
    my $tag_parse = $dbi->tag_parse(0);
2182
    $dbi = $dbi->tag_parse;
2183

            
2184
Enable DEPRECATED tag parsing functionality, default to 1.
2185
If you want to disable tag parsing functionality, set to 0.
2186

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

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2194
=head2 C<user_column_info EXPERIMENTAL>
2195

            
2196
    my $user_column_info = $dbi->user_column_info;
2197
    $dbi = $dbi->user_column_info($user_column_info);
2198

            
2199
You can set the following data.
2200

            
2201
    [
2202
        {table => 'book', column => 'title', info => {...}},
2203
        {table => 'author', column => 'name', info => {...}}
2204
    ]
2205

            
2206
Usually, you can set return value of C<get_column_info>.
2207

            
2208
    my $user_column_info
2209
      = $dbi->get_column_info(exclude_table => qr/^system/);
2210
    $dbi->user_column_info($user_column_info);
2211

            
2212
If C<user_column_info> is set, C<each_column> use C<user_column_info>
2213
to find column info.
2214

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

            
2217
    my $user_table_info = $dbi->user_table_info;
2218
    $dbi = $dbi->user_table_info($user_table_info);
2219

            
2220
You can set the following data.
2221

            
2222
    [
2223
        {table => 'book', info => {...}},
2224
        {table => 'author', info => {...}}
2225
    ]
2226

            
2227
Usually, you can set return value of C<get_table_info>.
2228

            
2229
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2230
    $dbi->user_table_info($user_table_info);
2231

            
2232
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2233
to find table info.
2234

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2269
Create column clause. The follwoing column clause is created.
2270

            
2271
    book.author as "book.author",
2272
    book.title as "book.title"
2273

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2276
    # Separator is double underbar
2277
    $dbi->separator('__');
2278
    
2279
    book.author as "book__author",
2280
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2281

            
cleanup
Yuki Kimoto authored on 2011-06-13
2282
    # Separator is hyphen
2283
    $dbi->separator('-');
2284
    
2285
    book.author as "book-author",
2286
    book.title as "book-title"
2287
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2288
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2289

            
update pod
Yuki Kimoto authored on 2011-03-13
2290
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2291
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2292
        user => 'ken',
2293
        password => '!LFKD%$&',
2294
        dbi_option => {mysql_enable_utf8 => 1}
2295
    );
2296

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2303
=head2 C<count> EXPERIMENTAL
2304

            
2305
    my $count = $model->count(table => 'book');
2306

            
2307
Get rows count.
2308

            
2309
Options is same as C<select> method's ones.
2310

            
2311
=head2 C<create_model>
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2312

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2313
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2314
        table => 'book',
2315
        primary_key => 'id',
2316
        join => [
2317
            'inner join company on book.comparny_id = company.id'
2318
        ],
2319
    );
2320

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

            
2324
   $dbi->model('book')->select(...);
2325

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

            
2328
    my $dbh = $dbi->dbh;
2329

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

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

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

            
2337
Execute delete statement.
2338

            
2339
The following opitons are available.
2340

            
2341
=over 4
2342

            
2343
=item C<append>
2344

            
2345
Same as C<select> method's C<append> option.
2346

            
2347
=item C<filter>
2348

            
2349
Same as C<execute> method's C<filter> option.
2350

            
2351
=item C<id>
2352

            
2353
    id => 4
2354
    id => [4, 5]
2355

            
2356
ID corresponding to C<primary_key>.
2357
You can delete rows by C<id> and C<primary_key>.
2358

            
2359
    $dbi->delete(
2360
        parimary_key => ['id1', 'id2'],
2361
        id => [4, 5],
2362
        table => 'book',
2363
    );
2364

            
2365
The above is same as the followin one.
2366

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

            
2369
=item C<prefix>
2370

            
2371
    prefix => 'some'
2372

            
2373
prefix before table name section.
2374

            
2375
    delete some from book
2376

            
2377
=item C<query>
2378

            
2379
Same as C<execute> method's C<query> option.
2380

            
2381
=item C<sqlfilter EXPERIMENTAL>
2382

            
2383
Same as C<execute> method's C<sqlfilter> option.
2384

            
2385
=item C<table>
2386

            
2387
    table => 'book'
2388

            
2389
Table name.
2390

            
2391
=item C<where>
2392

            
2393
Same as C<select> method's C<where> option.
2394

            
2395
=item C<primary_key>
2396

            
2397
See C<id> option.
2398

            
2399
=item C<bind_type>
2400

            
2401
Same as C<execute> method's C<bind_type> option.
2402

            
2403
=item C<type_rule_off> EXPERIMENTAL
2404

            
2405
Same as C<execute> method's C<type_rule_off> option.
2406

            
2407
=item C<type_rule1_off> EXPERIMENTAL
2408

            
2409
    type_rule1_off => 1
2410

            
2411
Same as C<execute> method's C<type_rule1_off> option.
2412

            
2413
=item C<type_rule2_off> EXPERIMENTAL
2414

            
2415
    type_rule2_off => 1
2416

            
2417
Same as C<execute> method's C<type_rule2_off> option.
2418

            
2419
=back
2420

            
2421
=head2 C<delete_all>
2422

            
2423
    $dbi->delete_all(table => $table);
2424

            
2425
Execute delete statement for all rows.
2426
Options is same as C<delete>.
2427

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

            
2430
    $dbi->each_column(
2431
        sub {
2432
            my ($dbi, $table, $column, $column_info) = @_;
2433
            
2434
            my $type = $column_info->{TYPE_NAME};
2435
            
2436
            if ($type eq 'DATE') {
2437
                # ...
2438
            }
2439
        }
2440
    );
2441

            
2442
Iterate all column informations of all table from database.
2443
Argument is callback when one column is found.
2444
Callback receive four arguments, dbi object, table name,
2445
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2446

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

            
2449
    $dbi->each_table(
2450
        sub {
2451
            my ($dbi, $table, $table_info) = @_;
2452
            
2453
            my $table_name = $table_info->{TABLE_NAME};
2454
        }
2455
    );
2456

            
2457
Iterate all table informationsfrom database.
2458
Argument is callback when one table is found.
2459
Callback receive three arguments, dbi object, table name,
2460
table information.
2461

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

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

            
2469
    my $result = $dbi->execute(
2470
      "select * from book where title = :book.title and author like :book.author",
2471
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2472
    );
2473

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2480
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2481
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2482
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2483
    select * from book where title = :title and author like :author
2484
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2485
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2486
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2487

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2491
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2492
    select * from book where :title{=} and :author{like}
2493
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2494
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2495
    select * from where title = ? and author like ?;
2496

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

            
2501
    select * from where title = "aa\\:bb";
2502

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

            
2505
=over 4
2506

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

            
2509
Specify database bind data type.
2510

            
2511
    bind_type => [image => DBI::SQL_BLOB]
2512
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2513

            
2514
This is used to bind parameter by C<bind_param> of statment handle.
2515

            
2516
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2517

            
update pod
Yuki Kimoto authored on 2011-03-13
2518
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2519
    
2520
    filter => {
2521
        title  => sub { uc $_[0] }
2522
        author => sub { uc $_[0] }
2523
    }
update pod
Yuki Kimoto authored on 2011-03-13
2524

            
updated pod
Yuki Kimoto authored on 2011-06-09
2525
    # Filter name
2526
    filter => {
2527
        title  => 'upper_case',
2528
        author => 'upper_case'
2529
    }
2530
        
2531
    # At once
2532
    filter => [
2533
        [qw/title author/]  => sub { uc $_[0] }
2534
    ]
2535

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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2541
=item C<id>
2542

            
2543
    id => 4
2544
    id => [4, 5]
2545

            
2546
ID corresponding to C<primary_key>.
2547
You can delete rows by C<id> and C<primary_key>.
2548

            
2549
    $dbi->execute(
2550
        "select * from book where id1 = :id1 and id2 = :id2",
2551
        {},
2552
        parimary_key => ['id1', 'id2'],
2553
        id => [4, 5],
2554
    );
2555

            
2556
The above is same as the followin one.
2557

            
2558
    $dbi->execute(
2559
        "select * from book where id1 = :id1 and id2 = :id2",
2560
        {id1 => 4, id2 => 5}
2561
    );
2562

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

            
2565
    query => 1
2566

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

            
2570
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2571
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2572
    my $columns = $query->columns;
2573
    
2574
If you want to execute SQL fast, you can do the following way.
2575

            
2576
    my $query;
2577
    foreach my $row (@$rows) {
2578
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2579
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2580
    }
2581

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

            
2585
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
2586
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2587
    
2588
    my $query;
2589
    my $sth;
2590
    foreach my $row (@$rows) {
2591
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2592
      $sth ||= $query->sth;
2593
      $sth->execute(map { $row->{$_} } sort keys %$row);
2594
    }
2595

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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2600
=item C<primary_key>
2601

            
2602
See C<id> option.
2603

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

            
2606
SQL filter function.
2607

            
2608
    sqlfilter => $code_ref
2609

            
2610
This option is generally for Oracle and SQL Server paging process.
2611
    
2612
    my $limit = sub {
2613
        my ($sql, $count, $offset) = @_;
2614
        
2615
        my $min = $offset + 1;
2616
        my $max = $offset + $count;
2617
        
2618
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2619
        
2620
        return $sql;
2621
    }
2622
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2623
        my $sql = shift;
2624
        return $limit->($sql, 100, 50);
2625
    })
2626

            
updated pod
Yuki Kimoto authored on 2011-06-09
2627
=item C<table>
2628
    
2629
    table => 'author'
2630

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2638
    # Same
2639
    $dbi->execute(
2640
      "select * from book where title = :book.title and author = :book.author",
2641
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2642

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

            
2645
    table_alias => {user => 'hiker'}
2646

            
2647
Table alias. Key is real table name, value is alias table name.
2648
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2649
on alias table name.
2650

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

            
2653
    type_rule_off => 1
2654

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

            
2657
=item C<type_rule1_off> EXPERIMENTAL
2658

            
2659
    type_rule1_off => 1
2660

            
2661
Turn C<into1> type rule off.
2662

            
2663
=item C<type_rule2_off> EXPERIMENTAL
2664

            
2665
    type_rule2_off => 1
2666

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2671
=head2 C<get_column_info EXPERIMENTAL>
2672

            
2673
    my $tables = $self->get_column_info(exclude_table => qr/^system_/);
2674

            
2675
get column infomation except for one which match C<exclude_table> pattern.
2676

            
2677
    [
2678
        {table => 'book', column => 'title', info => {...}},
2679
        {table => 'author', column => 'name' info => {...}}
2680
    ]
2681

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

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

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

            
2688
    [
2689
        {table => 'book', info => {...}},
2690
        {table => 'author', info => {...}}
2691
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2692

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2695
=head2 C<insert>
2696

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

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

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

            
2705
    {date => \"NOW()"}
2706

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

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

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

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

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

            
2717
Same as C<execute> method's C<bind_type> option.
2718

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

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

            
2723
=item C<id>
2724

            
updated document
Yuki Kimoto authored on 2011-06-09
2725
    id => 4
2726
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2727

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2731
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2732
        {title => 'Perl', author => 'Ken'}
2733
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2734
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2735
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2736
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2737

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

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

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

            
2747
    prefix => 'or replace'
2748

            
2749
prefix before table name section
2750

            
2751
    insert or replace into book
2752

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

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

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

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

            
2762
Same as C<execute> method's C<query> option.
2763

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

            
2766
Same as C<execute> method's C<sqlfilter> option.
2767

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

            
2770
    table => 'book'
2771

            
2772
Table name.
2773

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

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

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

            
2780
    type_rule1_off => 1
2781

            
2782
Same as C<execute> method's C<type_rule1_off> option.
2783

            
2784
=item C<type_rule2_off> EXPERIMENTAL
2785

            
2786
    type_rule2_off => 1
2787

            
2788
Same as C<execute> method's C<type_rule2_off> option.
2789

            
update pod
Yuki Kimoto authored on 2011-03-13
2790
=back
2791

            
2792
=over 4
2793

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2809
    lib / MyModel.pm
2810
        / MyModel / book.pm
2811
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2812

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

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

            
2817
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2818
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2819
    
2820
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2821

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2826
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2827
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2828
    
2829
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2830

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2833
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2834
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2835
    
2836
    1;
2837
    
updated pod
Yuki Kimoto authored on 2011-06-21
2838
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2839

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

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

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

            
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2847
=head2 C<mapper EXPERIMETNAL>
2848

            
2849
    my $mapper = $dbi->mapper(param => $param);
2850

            
2851
Create a new L<DBIx::Custom::Mapper> object.
2852

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

            
2855
    my $map_param = $dbi->map_param(
2856
        {id => 1, authro => 'Ken', price => 1900},
2857
        'id' => 'book.id',
2858
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2859
        'price' => [
2860
            'book.price', {if => sub { length $_[0] }}
2861
        ]
2862
    );
2863

            
2864
Map paramters to other key and value. First argument is original
2865
parameter. this is hash reference. Rest argument is mapping.
2866
By default, Mapping is done if the value length is not zero.
2867

            
2868
=over 4
2869

            
2870
=item Key mapping
2871

            
2872
    'id' => 'book.id'
2873

            
2874
This is only key mapping. Value is same as original one.
2875

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

            
2878
=item Key and value mapping
2879

            
2880
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2881

            
2882
This is key and value mapping. Frist element of array reference
2883
is mapped key name, second element is code reference to map the value.
2884

            
2885
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2886
      if value length is not zero.
2887

            
2888
=item Condition
2889

            
2890
    'price' => ['book.price', {if => 'exists'}]
2891
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2892
    'price' => ['book.price', {if => sub { defined shift }}]
2893

            
2894
If you need condition, you can sepecify it. this is code reference
2895
or 'exists'. By default, condition is the following one.
2896

            
2897
    sub { defined $_[0] && length $_[0] }
2898

            
2899
=back
2900

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

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

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

            
2907
    {key1 => [1, 1], key2 => 2}
2908

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

            
2911
    $dbi->method(
2912
        update_or_insert => sub {
2913
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2914
            
2915
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2916
        },
2917
        find_or_create   => sub {
2918
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2919
            
2920
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2921
        }
2922
    );
2923

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

            
2926
    $dbi->update_or_insert;
2927
    $dbi->find_or_create;
2928

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

            
2931
    my $model = $dbi->model('book');
2932

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

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

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

            
2939
Create column clause for myself. The follwoing column clause is created.
2940

            
2941
    book.author as author,
2942
    book.title as title
2943

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2946
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2947
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2948
        user => 'ken',
2949
        password => '!LFKD%$&',
2950
        dbi_option => {mysql_enable_utf8 => 1}
2951
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2952

            
2953
Create a new L<DBIx::Custom> object.
2954

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

            
2957
    my $not_exists = $dbi->not_exists;
2958

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

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

            
2964
    my $order = $dbi->order;
2965

            
2966
Create a new L<DBIx::Custom::Order> object.
2967

            
cleanup
yuki-kimoto authored on 2010-10-17
2968
=head2 C<register_filter>
2969

            
update pod
Yuki Kimoto authored on 2011-03-13
2970
    $dbi->register_filter(
2971
        # Time::Piece object to database DATE format
2972
        tp_to_date => sub {
2973
            my $tp = shift;
2974
            return $tp->strftime('%Y-%m-%d');
2975
        },
2976
        # database DATE format to Time::Piece object
2977
        date_to_tp => sub {
2978
           my $date = shift;
2979
           return Time::Piece->strptime($date, '%Y-%m-%d');
2980
        }
2981
    );
cleanup
yuki-kimoto authored on 2010-10-17
2982
    
update pod
Yuki Kimoto authored on 2011-03-13
2983
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2984

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

            
2987
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2988
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2989
            date => sub { ... },
2990
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2991
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2992
        into2 => {
2993
            date => sub { ... },
2994
            datetime => sub { ... }
2995
        },
2996
        from1 => {
2997
            # DATE
2998
            9 => sub { ... },
2999
            # DATETIME or TIMESTAMP
3000
            11 => sub { ... },
3001
        }
3002
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3003
            # DATE
3004
            9 => sub { ... },
3005
            # DATETIME or TIMESTAMP
3006
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3007
        }
3008
    );
3009

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3025
=over 4
3026

            
3027
=item 1. column name
3028

            
3029
    issue_date
3030
    issue_datetime
3031

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

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

            
3036
    book.issue_date
3037
    book.issue_datetime
3038

            
3039
=back
3040

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

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

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

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

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

            
3053
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3054
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3055
            [qw/DATE DATETIME/] => sub { ... },
3056
        ],
3057
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3058

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3061
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3062
        table  => 'book',
3063
        column => ['author', 'title'],
3064
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3065
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3066
    
updated document
Yuki Kimoto authored on 2011-06-09
3067
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3068

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

            
3071
=over 4
3072

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

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

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

            
3079
=item C<bind_type>
3080

            
3081
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3082
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3083
=item C<column>
3084
    
updated document
Yuki Kimoto authored on 2011-06-09
3085
    column => 'author'
3086
    column => ['author', 'title']
3087

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3096
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3097
        {book => [qw/author title/]},
3098
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3099
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3100

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

            
3103
    book.author as "book.author",
3104
    book.title as "book.title",
3105
    person.name as "person.name",
3106
    person.age as "person.age"
3107

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

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

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

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

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

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

            
3123
=item C<id>
3124

            
3125
    id => 4
3126
    id => [4, 5]
3127

            
3128
ID corresponding to C<primary_key>.
3129
You can select rows by C<id> and C<primary_key>.
3130

            
3131
    $dbi->select(
3132
        parimary_key => ['id1', 'id2'],
3133
        id => [4, 5],
3134
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3135
    );
3136

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3139
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3140
        where => {id1 => 4, id2 => 5},
3141
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3142
    );
3143
    
updated document
Yuki Kimoto authored on 2011-06-09
3144
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3145

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

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

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

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

            
3158
    prefix => 'SQL_CALC_FOUND_ROWS'
3159

            
3160
Prefix of column cluase
3161

            
3162
    select SQL_CALC_FOUND_ROWS title, author from book;
3163

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

            
3166
    join => [
3167
        'left outer join company on book.company_id = company_id',
3168
        'left outer join location on company.location_id = location.id'
3169
    ]
3170
        
3171
Join clause. If column cluase or where clause contain table name like "company.name",
3172
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3173

            
3174
    $dbi->select(
3175
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3176
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3177
        where => {'company.name' => 'Orange'},
3178
        join => [
3179
            'left outer join company on book.company_id = company.id',
3180
            'left outer join location on company.location_id = location.id'
3181
        ]
3182
    );
3183

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3187
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3188
    from book
3189
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3190
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3191

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

            
3195
    $dbi->select(
3196
        table => 'book',
3197
        column => ['company.location_id as location_id'],
3198
        where => {'company.name' => 'Orange'},
3199
        join => [
3200
            {
3201
                clause => 'left outer join location on company.location_id = location.id',
3202
                table => ['company', 'location']
3203
            }
3204
        ]
3205
    );
3206

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3226
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3227

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

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

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

            
3234
    type_rule1_off => 1
3235

            
3236
Same as C<execute> method's C<type_rule1_off> option.
3237

            
3238
=item C<type_rule2_off> EXPERIMENTAL
3239

            
3240
    type_rule2_off => 1
3241

            
3242
Same as C<execute> method's C<type_rule2_off> option.
3243

            
updated document
Yuki Kimoto authored on 2011-06-09
3244
=item C<where>
3245
    
3246
    # Hash refrence
3247
    where => {author => 'Ken', 'title' => 'Perl'}
3248
    
3249
    # DBIx::Custom::Where object
3250
    where => $dbi->where(
3251
        clause => ['and', 'author = :author', 'title like :title'],
3252
        param  => {author => 'Ken', title => '%Perl%'}
3253
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3254
    
3255
    # Array reference 1 (array reference, hash referenc). same as above
3256
    where => [
3257
        ['and', 'author = :author', 'title like :title'],
3258
        {author => 'Ken', title => '%Perl%'}
3259
    ];    
3260
    
3261
    # Array reference 2 (String, hash reference)
3262
    where => [
3263
        'title like :title',
3264
        {title => '%Perl%'}
3265
    ]
3266
    
3267
    # String
3268
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3269

            
updated document
Yuki Kimoto authored on 2011-06-09
3270
Where clause.
3271
    
improved pod
Yuki Kimoto authored on 2011-04-19
3272
=item C<wrap> EXPERIMENTAL
3273

            
3274
Wrap statement. This is array reference.
3275

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

            
3278
This option is for Oracle and SQL Server paging process.
3279

            
update pod
Yuki Kimoto authored on 2011-03-12
3280
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3281

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

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

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

            
3288
If you want to set constant value to row data, use scalar reference
3289
as parameter value.
3290

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3295
=over 4
3296

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

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

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

            
3303
Same as C<execute> method's C<bind_type> option.
3304

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3311
    id => 4
3312
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3313

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3317
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3318
        {title => 'Perl', author => 'Ken'}
3319
        parimary_key => ['id1', 'id2'],
3320
        id => [4, 5],
3321
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3322
    );
update pod
Yuki Kimoto authored on 2011-03-13
3323

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3326
    $dbi->update(
3327
        {title => 'Perl', author => 'Ken'}
3328
        where => {id1 => 4, id2 => 5},
3329
        table => 'book'
3330
    );
update pod
Yuki Kimoto authored on 2011-03-13
3331

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

            
3334
    prefix => 'or replace'
3335

            
3336
prefix before table name section
3337

            
3338
    update or replace book
3339

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

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

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

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

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

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

            
3353
Same as C<execute> method's C<sqlfilter> option.
3354

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

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

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

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

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

            
3365
=item C<type_rule1_off> EXPERIMENTAL
3366

            
3367
    type_rule1_off => 1
3368

            
3369
Same as C<execute> method's C<type_rule1_off> option.
3370

            
3371
=item C<type_rule2_off> EXPERIMENTAL
3372

            
3373
    type_rule2_off => 1
3374

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

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

            
3379
Same as C<select> method's C<where> option.
3380

            
updated pod
Yuki Kimoto authored on 2011-06-08
3381
=back
update pod
Yuki Kimoto authored on 2011-03-13
3382

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

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

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

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

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

            
3394
Create update parameter tag.
3395

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

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

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

            
3405
Create a new L<DBIx::Custom::Where> object.
3406

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

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

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3414
=head1 ENVIRONMENTAL VARIABLES
added environment variable D...
Yuki Kimoto authored on 2011-04-02
3415

            
3416
=head2 C<DBIX_CUSTOM_DEBUG>
3417

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

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

            
3423
    $dbi->show_datatype($table);
3424

            
3425
Show data type of the columns of specified table.
3426

            
3427
    book
3428
    title: 5
3429
    issue_date: 91
3430

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

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

            
3435
    $dbi->show_tables;
3436

            
3437
Show tables.
3438

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

            
3441
    $dbi->show_typename($table);
3442

            
3443
Show type name of the columns of specified table.
3444

            
3445
    book
3446
    title: varchar
3447
    issue_date: date
3448

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

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

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3455
=head1 DEPRECATED FUNCTIONALITY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3456

            
3457
L<DBIx::Custom>
3458

            
3459
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3460
    data_source # will be removed at 2017/1/1
3461
    dbi_options # will be removed at 2017/1/1
3462
    filter_check # will be removed at 2017/1/1
3463
    reserved_word_quote # will be removed at 2017/1/1
3464
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3465
    
3466
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3467
    create_query # will be removed at 2017/1/1
3468
    apply_filter # will be removed at 2017/1/1
3469
    select_at # will be removed at 2017/1/1
3470
    delete_at # will be removed at 2017/1/1
3471
    update_at # will be removed at 2017/1/1
3472
    insert_at # will be removed at 2017/1/1
3473
    register_tag # will be removed at 2017/1/1
3474
    default_bind_filter # will be removed at 2017/1/1
3475
    default_fetch_filter # will be removed at 2017/1/1
3476
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3477
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3478
    register_tag_processor # will be removed at 2017/1/1
3479
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3480
    
3481
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3482
    select method relation option # will be removed at 2017/1/1
3483
    select method param option # will be removed at 2017/1/1
3484
    select method column option [COLUMN, as => ALIAS] format
3485
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3486
    
3487
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3488
    execute("select * from {= title}"); # execute method's
3489
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3490
                                        # will be removed at 2017/1/1
3491
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3492

            
3493
L<DBIx::Custom::Model>
3494

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3495
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3496
    filter # will be removed at 2017/1/1
3497
    name # will be removed at 2017/1/1
3498
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3499

            
3500
L<DBIx::Custom::Query>
3501
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3502
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3503
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3504
    table # will be removed at 2017/1/1
3505
    filters # will be removed at 2017/1/1
3506
    
3507
    # Methods
3508
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3509

            
3510
L<DBIx::Custom::QueryBuilder>
3511
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3512
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3513
    tags # will be removed at 2017/1/1
3514
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3515
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3516
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3517
    register_tag # will be removed at 2017/1/1
3518
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3519
    
3520
    # Others
3521
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3522
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3523

            
3524
L<DBIx::Custom::Result>
3525
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3526
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3527
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3528
    
3529
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3530
    end_filter # will be removed at 2017/1/1
3531
    remove_end_filter # will be removed at 2017/1/1
3532
    remove_filter # will be removed at 2017/1/1
3533
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3534

            
3535
L<DBIx::Custom::Tag>
3536

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

            
fix heading typos
Terrence Brannon authored on 2011-08-17
3539
=head1 BACKWARDS COMPATIBILITY POLICY
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3540

            
3541
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3542
except for attribute method.
3543
You can check all DEPRECATED functionalities by document.
3544
DEPRECATED functionality is removed after five years,
3545
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
3546
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3547

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

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

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

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

            
3556
C<< <kimoto.yuki at gmail.com> >>
3557

            
3558
L<http://github.com/yuki-kimoto/DBIx-Custom>
3559

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3560
=head1 AUTHOR
3561

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

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

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

            
3568
This program is free software; you can redistribute it and/or modify it
3569
under the same terms as Perl itself.
3570

            
3571
=cut