DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
3559 lines | 92.573kb
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

            
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
4
our $VERSION = '0.1720';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

            
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8
use DBI;
9
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
10
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
11
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
12
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
13
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
14
use DBIx::Custom::Tag;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
15
use DBIx::Custom::Order;
cleanup
Yuki Kimoto authored on 2011-04-25
16
use DBIx::Custom::Util qw/_array_to_hash _subname/;
improved debug message
Yuki Kimoto authored on 2011-05-23
17
use Encode qw/encode encode_utf8 decode_utf8/;
cleanup
Yuki Kimoto authored on 2011-08-13
18
use Scalar::Util qw/weaken/;
packaging one directory
yuki-kimoto authored on 2009-11-16
19

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
743
        # Map parameter
744
        my $value;
745
        if (ref $condition eq 'CODE') {
746
            $map_param->{$map_key} = $value_cb->($param->{$key})
747
              if $condition->($param->{$key});
748
        }
749
        elsif ($condition eq 'exists') {
750
            $map_param->{$map_key} = $value_cb->($param->{$key})
751
              if exists $param->{$key};
752
        }
753
        else { croak qq/Condition must be code reference or "exists" / . _subname }
754
    }
755
    
756
    return $map_param;
757
}
758

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
783
sub method {
784
    my $self = shift;
785
    
cleanup
Yuki Kimoto authored on 2011-04-02
786
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
787
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
788
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
789
    
790
    return $self;
791
}
792

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

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

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

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

            
851
my $not_exists = bless {}, 'DBIx::Custom::NotExists';
852
sub not_exists { $not_exists }
853

            
854
sub order {
855
    my $self = shift;
856
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
857
}
858

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-08-10
1017
sub show_datatype {
1018
    my ($self, $table) = @_;
1019
    croak "Table name must be specified" unless defined $table;
1020
    print "$table\n";
1021
    
1022
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1023
    my $sth = $result->sth;
1024

            
1025
    my $columns = $sth->{NAME};
1026
    my $data_types = $sth->{TYPE};
1027
    
1028
    for (my $i = 0; $i < @$columns; $i++) {
1029
        my $column = $columns->[$i];
1030
        my $data_type = $data_types->[$i];
1031
        print "$column: $data_type\n";
1032
    }
1033
}
1034

            
1035
sub show_typename {
1036
    my ($self, $t) = @_;
1037
    croak "Table name must be specified" unless defined $t;
1038
    print "$t\n";
1039
    
1040
    $self->each_column(sub {
1041
        my ($self, $table, $column, $infos) = @_;
1042
        return unless $table eq $t;
1043
        my $typename = $infos->{TYPE_NAME};
1044
        print "$column: $typename\n";
1045
    });
1046
    
1047
    return $self;
1048
}
1049

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1050
sub show_tables {
1051
    my $self = shift;
1052
    
1053
    my %tables;
1054
    $self->each_table(sub { $tables{$_[1]}++ });
1055
    print join("\n", sort keys %tables) . "\n";
1056
    return $self;
1057
}
1058

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1094
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1095
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1096
                }
1097
            });
1098
        }
1099

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-04-02
1195
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1196
}
1197

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

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

            
1226
        # Create query
1227
        my $builder = $self->query_builder;
1228
        $query = $builder->build_query($source);
1229

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

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

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

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

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

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

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

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

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

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1480
sub _quote {
1481
    my $self = shift;
1482
    
1483
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1484
         : defined $self->quote ? $self->quote
1485
         : '';
1486
}
1487

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

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

            
1520
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1521
}
1522

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

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

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

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

            
1659
# DEPRECATED!
1660
sub create_query {
1661
    warn "create_query is DEPRECATED! use query option of each method";
1662
    shift->_create_query(@_);
1663
}
1664

            
cleanup
Yuki Kimoto authored on 2011-06-13
1665
# DEPRECATED!
1666
sub apply_filter {
1667
    my $self = shift;
1668
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1669
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1670
    return $self->_apply_filter(@_);
1671
}
1672

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1727
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1728
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1729
sub update_at {
1730
    my $self = shift;
1731

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

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

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

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

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1809
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1810
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1811
has dbi_options => sub { {} };
1812
has filter_check  => 1;
1813
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1814

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1839
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1840
sub default_fetch_filter {
1841
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1842

            
cleanup
Yuki Kimoto authored on 2011-06-13
1843
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1844
    
1845
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1846
        my $fname = $_[0];
1847

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

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1864
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1865
sub insert_param_tag {
1866
    warn "insert_param_tag is DEPRECATED! " .
1867
         "use insert_param instead!";
1868
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1869
}
1870

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1915
=head1 NAME
1916

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1990
Named place holder support
1991

            
1992
=item *
1993

            
cleanup
Yuki Kimoto authored on 2011-07-29
1994
Model support
1995

            
1996
=item *
1997

            
1998
Connection manager support
1999

            
2000
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2001

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

            
2006
=item *
2007

            
2008
Filtering by data type or column name(EXPERIMENTAL)
2009

            
2010
=item *
2011

            
2012
Create C<order by> clause flexibly(EXPERIMENTAL)
2013

            
2014
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2015

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2023
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2024
L<DBIx::Custom::Result>,
2025
L<DBIx::Custom::Query>,
2026
L<DBIx::Custom::Where>,
2027
L<DBIx::Custom::Model>,
2028
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2029

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

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

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

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

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

            
2043
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2044
        "dbi:mysql:database=$database",
2045
        $user,
2046
        $password,
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2047
        DBIx::Custom->new->default_dbi_option
2048
    );
2049
    
updated pod
Yuki Kimoto authored on 2011-06-21
2050
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2051

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

            
2055
    my $dbi = DBIx::Custom->connect(
2056
      dsn => $dsn, user => $user, password => $password, connector => 1);
2057
    
2058
    my $connector = $dbi->connector; # DBIx::Connector
2059

            
2060
Note that L<DBIx::Connector> must be installed.
2061

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

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

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

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

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

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

            
2077
=head2 C<default_dbi_option>
2078

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2085
    {
2086
        RaiseError => 1,
2087
        PrintError => 0,
2088
        AutoCommit => 1,
2089
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2090

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

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

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

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

            
2100
    my $last_sql = $dbi->last_sql;
2101
    $dbi = $dbi->last_sql($last_sql);
2102

            
2103
Get last successed SQL executed by C<execute> method.
2104

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2112
=head2 C<password>
2113

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2134
You can set quote pair.
2135

            
2136
    $dbi->quote('[]');
2137

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

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

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

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

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

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

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

            
2155
    my $separator = $self->separator;
2156
    $dbi = $self->separator($separator);
2157

            
2158
Separator whichi join table and column.
2159
This is used by C<column> and C<mycolumn> method.
2160

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

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

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

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

            
2175
    my $tag_parse = $dbi->tag_parse(0);
2176
    $dbi = $dbi->tag_parse;
2177

            
2178
Enable DEPRECATED tag parsing functionality, default to 1.
2179
If you want to disable tag parsing functionality, set to 0.
2180

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

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

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

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

            
2190
    my $user_column_info = $dbi->user_column_info;
2191
    $dbi = $dbi->user_column_info($user_column_info);
2192

            
2193
You can set the following data.
2194

            
2195
    [
2196
        {table => 'book', column => 'title', info => {...}},
2197
        {table => 'author', column => 'name', info => {...}}
2198
    ]
2199

            
2200
Usually, you can set return value of C<get_column_info>.
2201

            
2202
    my $user_column_info
2203
      = $dbi->get_column_info(exclude_table => qr/^system/);
2204
    $dbi->user_column_info($user_column_info);
2205

            
2206
If C<user_column_info> is set, C<each_column> use C<user_column_info>
2207
to find column info.
2208

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

            
2211
    my $user_table_info = $dbi->user_table_info;
2212
    $dbi = $dbi->user_table_info($user_table_info);
2213

            
2214
You can set the following data.
2215

            
2216
    [
2217
        {table => 'book', info => {...}},
2218
        {table => 'author', info => {...}}
2219
    ]
2220

            
2221
Usually, you can set return value of C<get_table_info>.
2222

            
2223
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2224
    $dbi->user_table_info($user_table_info);
2225

            
2226
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2227
to find table info.
2228

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2263
Create column clause. The follwoing column clause is created.
2264

            
2265
    book.author as "book.author",
2266
    book.title as "book.title"
2267

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2270
    # Separator is double underbar
2271
    $dbi->separator('__');
2272
    
2273
    book.author as "book__author",
2274
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2275

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

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

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

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

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

            
2299
    my $count = $model->count(table => 'book');
2300

            
2301
Get rows count.
2302

            
2303
Options is same as C<select> method's ones.
2304

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2307
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2308
        table => 'book',
2309
        primary_key => 'id',
2310
        join => [
2311
            'inner join company on book.comparny_id = company.id'
2312
        ],
2313
    );
2314

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

            
2318
   $dbi->model('book')->select(...);
2319

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

            
2322
    my $dbh = $dbi->dbh;
2323

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

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

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

            
2331
Execute delete statement.
2332

            
2333
The following opitons are available.
2334

            
2335
=over 4
2336

            
2337
=item C<append>
2338

            
2339
Same as C<select> method's C<append> option.
2340

            
2341
=item C<filter>
2342

            
2343
Same as C<execute> method's C<filter> option.
2344

            
2345
=item C<id>
2346

            
2347
    id => 4
2348
    id => [4, 5]
2349

            
2350
ID corresponding to C<primary_key>.
2351
You can delete rows by C<id> and C<primary_key>.
2352

            
2353
    $dbi->delete(
2354
        parimary_key => ['id1', 'id2'],
2355
        id => [4, 5],
2356
        table => 'book',
2357
    );
2358

            
2359
The above is same as the followin one.
2360

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

            
2363
=item C<prefix>
2364

            
2365
    prefix => 'some'
2366

            
2367
prefix before table name section.
2368

            
2369
    delete some from book
2370

            
2371
=item C<query>
2372

            
2373
Same as C<execute> method's C<query> option.
2374

            
2375
=item C<sqlfilter EXPERIMENTAL>
2376

            
2377
Same as C<execute> method's C<sqlfilter> option.
2378

            
2379
=item C<table>
2380

            
2381
    table => 'book'
2382

            
2383
Table name.
2384

            
2385
=item C<where>
2386

            
2387
Same as C<select> method's C<where> option.
2388

            
2389
=item C<primary_key>
2390

            
2391
See C<id> option.
2392

            
2393
=item C<bind_type>
2394

            
2395
Same as C<execute> method's C<bind_type> option.
2396

            
2397
=item C<type_rule_off> EXPERIMENTAL
2398

            
2399
Same as C<execute> method's C<type_rule_off> option.
2400

            
2401
=item C<type_rule1_off> EXPERIMENTAL
2402

            
2403
    type_rule1_off => 1
2404

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

            
2407
=item C<type_rule2_off> EXPERIMENTAL
2408

            
2409
    type_rule2_off => 1
2410

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

            
2413
=back
2414

            
2415
=head2 C<delete_all>
2416

            
2417
    $dbi->delete_all(table => $table);
2418

            
2419
Execute delete statement for all rows.
2420
Options is same as C<delete>.
2421

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

            
2424
    $dbi->each_column(
2425
        sub {
2426
            my ($dbi, $table, $column, $column_info) = @_;
2427
            
2428
            my $type = $column_info->{TYPE_NAME};
2429
            
2430
            if ($type eq 'DATE') {
2431
                # ...
2432
            }
2433
        }
2434
    );
2435

            
2436
Iterate all column informations of all table from database.
2437
Argument is callback when one column is found.
2438
Callback receive four arguments, dbi object, table name,
2439
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2440

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

            
2443
    $dbi->each_table(
2444
        sub {
2445
            my ($dbi, $table, $table_info) = @_;
2446
            
2447
            my $table_name = $table_info->{TABLE_NAME};
2448
        }
2449
    );
2450

            
2451
Iterate all table informationsfrom database.
2452
Argument is callback when one table is found.
2453
Callback receive three arguments, dbi object, table name,
2454
table information.
2455

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2485
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2486
    select * from book where :title{=} and :author{like}
2487
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2488
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2489
    select * from where title = ? and author like ?;
2490

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

            
2495
    select * from where title = "aa\\:bb";
2496

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

            
2499
=over 4
2500

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

            
2503
Specify database bind data type.
2504

            
2505
    bind_type => [image => DBI::SQL_BLOB]
2506
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2507

            
2508
This is used to bind parameter by C<bind_param> of statment handle.
2509

            
2510
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2511

            
update pod
Yuki Kimoto authored on 2011-03-13
2512
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2513
    
2514
    filter => {
2515
        title  => sub { uc $_[0] }
2516
        author => sub { uc $_[0] }
2517
    }
update pod
Yuki Kimoto authored on 2011-03-13
2518

            
updated pod
Yuki Kimoto authored on 2011-06-09
2519
    # Filter name
2520
    filter => {
2521
        title  => 'upper_case',
2522
        author => 'upper_case'
2523
    }
2524
        
2525
    # At once
2526
    filter => [
2527
        [qw/title author/]  => sub { uc $_[0] }
2528
    ]
2529

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

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

            
2537
    id => 4
2538
    id => [4, 5]
2539

            
2540
ID corresponding to C<primary_key>.
2541
You can delete rows by C<id> and C<primary_key>.
2542

            
2543
    $dbi->execute(
2544
        "select * from book where id1 = :id1 and id2 = :id2",
2545
        {},
2546
        parimary_key => ['id1', 'id2'],
2547
        id => [4, 5],
2548
    );
2549

            
2550
The above is same as the followin one.
2551

            
2552
    $dbi->execute(
2553
        "select * from book where id1 = :id1 and id2 = :id2",
2554
        {id1 => 4, id2 => 5}
2555
    );
2556

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

            
2559
    query => 1
2560

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

            
2564
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2565
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2566
    my $columns = $query->columns;
2567
    
2568
If you want to execute SQL fast, you can do the following way.
2569

            
2570
    my $query;
2571
    foreach my $row (@$rows) {
2572
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2573
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2574
    }
2575

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

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

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

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

            
2596
See C<id> option.
2597

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

            
2600
SQL filter function.
2601

            
2602
    sqlfilter => $code_ref
2603

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2621
=item C<table>
2622
    
2623
    table => 'author'
2624

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2632
    # Same
2633
    $dbi->execute(
2634
      "select * from book where title = :book.title and author = :book.author",
2635
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2636

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

            
2639
    table_alias => {user => 'hiker'}
2640

            
2641
Table alias. Key is real table name, value is alias table name.
2642
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2643
on alias table name.
2644

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

            
2647
    type_rule_off => 1
2648

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

            
2651
=item C<type_rule1_off> EXPERIMENTAL
2652

            
2653
    type_rule1_off => 1
2654

            
2655
Turn C<into1> type rule off.
2656

            
2657
=item C<type_rule2_off> EXPERIMENTAL
2658

            
2659
    type_rule2_off => 1
2660

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

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

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

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

            
2669
get column infomation except for one which match C<exclude_table> pattern.
2670

            
2671
    [
2672
        {table => 'book', column => 'title', info => {...}},
2673
        {table => 'author', column => 'name' info => {...}}
2674
    ]
2675

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

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

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

            
2682
    [
2683
        {table => 'book', info => {...}},
2684
        {table => 'author', info => {...}}
2685
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2686

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2689
=head2 C<insert>
2690

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

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

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

            
2699
    {date => \"NOW()"}
2700

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

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

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

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

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

            
2711
Same as C<execute> method's C<bind_type> option.
2712

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

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

            
2717
=item C<id>
2718

            
updated document
Yuki Kimoto authored on 2011-06-09
2719
    id => 4
2720
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2721

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2725
    $dbi->insert(
updated document
Yuki Kimoto authored on 2011-06-09
2726
        {title => 'Perl', author => 'Ken'}
2727
        parimary_key => ['id1', 'id2'],
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2728
        id => [4, 5],
updated document
Yuki Kimoto authored on 2011-06-09
2729
        table => 'book'
update pod
Yuki Kimoto authored on 2011-03-13
2730
    );
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2731

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

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

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

            
2741
    prefix => 'or replace'
2742

            
2743
prefix before table name section
2744

            
2745
    insert or replace into book
2746

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

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

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

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

            
2756
Same as C<execute> method's C<query> option.
2757

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

            
2760
Same as C<execute> method's C<sqlfilter> option.
2761

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

            
2764
    table => 'book'
2765

            
2766
Table name.
2767

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

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

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

            
2774
    type_rule1_off => 1
2775

            
2776
Same as C<execute> method's C<type_rule1_off> option.
2777

            
2778
=item C<type_rule2_off> EXPERIMENTAL
2779

            
2780
    type_rule2_off => 1
2781

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2784
=back
2785

            
2786
=over 4
2787

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2803
    lib / MyModel.pm
2804
        / MyModel / book.pm
2805
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2806

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

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

            
2811
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2812
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2813
    
2814
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2815

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2820
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2821
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2822
    
2823
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2824

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2827
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2828
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2829
    
2830
    1;
2831
    
updated pod
Yuki Kimoto authored on 2011-06-21
2832
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2833

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

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

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

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

            
2843
    my $map_param = $dbi->map_param(
2844
        {id => 1, authro => 'Ken', price => 1900},
2845
        'id' => 'book.id',
2846
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2847
        'price' => [
2848
            'book.price', {if => sub { length $_[0] }}
2849
        ]
2850
    );
2851

            
2852
Map paramters to other key and value. First argument is original
2853
parameter. this is hash reference. Rest argument is mapping.
2854
By default, Mapping is done if the value length is not zero.
2855

            
2856
=over 4
2857

            
2858
=item Key mapping
2859

            
2860
    'id' => 'book.id'
2861

            
2862
This is only key mapping. Value is same as original one.
2863

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

            
2866
=item Key and value mapping
2867

            
2868
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2869

            
2870
This is key and value mapping. Frist element of array reference
2871
is mapped key name, second element is code reference to map the value.
2872

            
2873
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2874
      if value length is not zero.
2875

            
2876
=item Condition
2877

            
2878
    'price' => ['book.price', {if => 'exists'}]
2879
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2880
    'price' => ['book.price', {if => sub { defined shift }}]
2881

            
2882
If you need condition, you can sepecify it. this is code reference
2883
or 'exists'. By default, condition is the following one.
2884

            
2885
    sub { defined $_[0] && length $_[0] }
2886

            
2887
=back
2888

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

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

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

            
2895
    {key1 => [1, 1], key2 => 2}
2896

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

            
2899
    $dbi->method(
2900
        update_or_insert => sub {
2901
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2902
            
2903
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2904
        },
2905
        find_or_create   => sub {
2906
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2907
            
2908
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2909
        }
2910
    );
2911

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

            
2914
    $dbi->update_or_insert;
2915
    $dbi->find_or_create;
2916

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

            
2919
    my $model = $dbi->model('book');
2920

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

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

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

            
2927
Create column clause for myself. The follwoing column clause is created.
2928

            
2929
    book.author as author,
2930
    book.title as title
2931

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2934
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2935
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2936
        user => 'ken',
2937
        password => '!LFKD%$&',
2938
        dbi_option => {mysql_enable_utf8 => 1}
2939
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2940

            
2941
Create a new L<DBIx::Custom> object.
2942

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

            
2945
    my $not_exists = $dbi->not_exists;
2946

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

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

            
2952
    my $order = $dbi->order;
2953

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2956
=head2 C<register_filter>
2957

            
update pod
Yuki Kimoto authored on 2011-03-13
2958
    $dbi->register_filter(
2959
        # Time::Piece object to database DATE format
2960
        tp_to_date => sub {
2961
            my $tp = shift;
2962
            return $tp->strftime('%Y-%m-%d');
2963
        },
2964
        # database DATE format to Time::Piece object
2965
        date_to_tp => sub {
2966
           my $date = shift;
2967
           return Time::Piece->strptime($date, '%Y-%m-%d');
2968
        }
2969
    );
cleanup
yuki-kimoto authored on 2010-10-17
2970
    
update pod
Yuki Kimoto authored on 2011-03-13
2971
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2972

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

            
2975
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2976
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
2977
            date => sub { ... },
2978
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2979
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2980
        into2 => {
2981
            date => sub { ... },
2982
            datetime => sub { ... }
2983
        },
2984
        from1 => {
2985
            # DATE
2986
            9 => sub { ... },
2987
            # DATETIME or TIMESTAMP
2988
            11 => sub { ... },
2989
        }
2990
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2991
            # DATE
2992
            9 => sub { ... },
2993
            # DATETIME or TIMESTAMP
2994
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
2995
        }
2996
    );
2997

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3013
=over 4
3014

            
3015
=item 1. column name
3016

            
3017
    issue_date
3018
    issue_datetime
3019

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

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

            
3024
    book.issue_date
3025
    book.issue_datetime
3026

            
3027
=back
3028

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

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

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

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

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

            
3041
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3042
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3043
            [qw/DATE DATETIME/] => sub { ... },
3044
        ],
3045
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3046

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3049
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3050
        table  => 'book',
3051
        column => ['author', 'title'],
3052
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3053
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3054
    
updated document
Yuki Kimoto authored on 2011-06-09
3055
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3056

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

            
3059
=over 4
3060

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

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

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

            
3067
=item C<bind_type>
3068

            
3069
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3070
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3071
=item C<column>
3072
    
updated document
Yuki Kimoto authored on 2011-06-09
3073
    column => 'author'
3074
    column => ['author', 'title']
3075

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3084
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3085
        {book => [qw/author title/]},
3086
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3087
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3088

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

            
3091
    book.author as "book.author",
3092
    book.title as "book.title",
3093
    person.name as "person.name",
3094
    person.age as "person.age"
3095

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

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

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

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

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

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

            
3111
=item C<id>
3112

            
3113
    id => 4
3114
    id => [4, 5]
3115

            
3116
ID corresponding to C<primary_key>.
3117
You can select rows by C<id> and C<primary_key>.
3118

            
3119
    $dbi->select(
3120
        parimary_key => ['id1', 'id2'],
3121
        id => [4, 5],
3122
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3123
    );
3124

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3127
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3128
        where => {id1 => 4, id2 => 5},
3129
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3130
    );
3131
    
updated document
Yuki Kimoto authored on 2011-06-09
3132
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3133

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

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

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

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

            
3146
    prefix => 'SQL_CALC_FOUND_ROWS'
3147

            
3148
Prefix of column cluase
3149

            
3150
    select SQL_CALC_FOUND_ROWS title, author from book;
3151

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

            
3154
    join => [
3155
        'left outer join company on book.company_id = company_id',
3156
        'left outer join location on company.location_id = location.id'
3157
    ]
3158
        
3159
Join clause. If column cluase or where clause contain table name like "company.name",
3160
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3161

            
3162
    $dbi->select(
3163
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3164
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3165
        where => {'company.name' => 'Orange'},
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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3175
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3176
    from book
3177
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3178
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3179

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

            
3183
    $dbi->select(
3184
        table => 'book',
3185
        column => ['company.location_id as location_id'],
3186
        where => {'company.name' => 'Orange'},
3187
        join => [
3188
            {
3189
                clause => 'left outer join location on company.location_id = location.id',
3190
                table => ['company', 'location']
3191
            }
3192
        ]
3193
    );
3194

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3214
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3215

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

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

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

            
3222
    type_rule1_off => 1
3223

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

            
3226
=item C<type_rule2_off> EXPERIMENTAL
3227

            
3228
    type_rule2_off => 1
3229

            
3230
Same as C<execute> method's C<type_rule2_off> option.
3231

            
updated document
Yuki Kimoto authored on 2011-06-09
3232
=item C<where>
3233
    
3234
    # Hash refrence
3235
    where => {author => 'Ken', 'title' => 'Perl'}
3236
    
3237
    # DBIx::Custom::Where object
3238
    where => $dbi->where(
3239
        clause => ['and', 'author = :author', 'title like :title'],
3240
        param  => {author => 'Ken', title => '%Perl%'}
3241
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3242
    
3243
    # Array reference 1 (array reference, hash referenc). same as above
3244
    where => [
3245
        ['and', 'author = :author', 'title like :title'],
3246
        {author => 'Ken', title => '%Perl%'}
3247
    ];    
3248
    
3249
    # Array reference 2 (String, hash reference)
3250
    where => [
3251
        'title like :title',
3252
        {title => '%Perl%'}
3253
    ]
3254
    
3255
    # String
3256
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3257

            
updated document
Yuki Kimoto authored on 2011-06-09
3258
Where clause.
3259
    
improved pod
Yuki Kimoto authored on 2011-04-19
3260
=item C<wrap> EXPERIMENTAL
3261

            
3262
Wrap statement. This is array reference.
3263

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

            
3266
This option is for Oracle and SQL Server paging process.
3267

            
update pod
Yuki Kimoto authored on 2011-03-12
3268
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3269

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

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

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

            
3276
If you want to set constant value to row data, use scalar reference
3277
as parameter value.
3278

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3283
=over 4
3284

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

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

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

            
3291
Same as C<execute> method's C<bind_type> option.
3292

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3299
    id => 4
3300
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3301

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3305
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3306
        {title => 'Perl', author => 'Ken'}
3307
        parimary_key => ['id1', 'id2'],
3308
        id => [4, 5],
3309
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3310
    );
update pod
Yuki Kimoto authored on 2011-03-13
3311

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3314
    $dbi->update(
3315
        {title => 'Perl', author => 'Ken'}
3316
        where => {id1 => 4, id2 => 5},
3317
        table => 'book'
3318
    );
update pod
Yuki Kimoto authored on 2011-03-13
3319

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

            
3322
    prefix => 'or replace'
3323

            
3324
prefix before table name section
3325

            
3326
    update or replace book
3327

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

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

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

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

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

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

            
3341
Same as C<execute> method's C<sqlfilter> option.
3342

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

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

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

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

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

            
3353
=item C<type_rule1_off> EXPERIMENTAL
3354

            
3355
    type_rule1_off => 1
3356

            
3357
Same as C<execute> method's C<type_rule1_off> option.
3358

            
3359
=item C<type_rule2_off> EXPERIMENTAL
3360

            
3361
    type_rule2_off => 1
3362

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

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

            
3367
Same as C<select> method's C<where> option.
3368

            
updated pod
Yuki Kimoto authored on 2011-06-08
3369
=back
update pod
Yuki Kimoto authored on 2011-03-13
3370

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

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

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

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

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

            
3382
Create update parameter tag.
3383

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

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

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

            
3393
Create a new L<DBIx::Custom::Where> object.
3394

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

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

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

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

            
3404
=head2 C<DBIX_CUSTOM_DEBUG>
3405

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

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

            
3411
    $dbi->show_datatype($table);
3412

            
3413
Show data type of the columns of specified table.
3414

            
3415
    book
3416
    title: 5
3417
    issue_date: 91
3418

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

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

            
3423
    $dbi->show_tables;
3424

            
3425
Show tables.
3426

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

            
3429
    $dbi->show_typename($table);
3430

            
3431
Show type name of the columns of specified table.
3432

            
3433
    book
3434
    title: varchar
3435
    issue_date: date
3436

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

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

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

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

            
3445
L<DBIx::Custom>
3446

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

            
3481
L<DBIx::Custom::Model>
3482

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3483
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3484
    filter # will be removed at 2017/1/1
3485
    name # will be removed at 2017/1/1
3486
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487

            
3488
L<DBIx::Custom::Query>
3489
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3490
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3491
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3492
    table # will be removed at 2017/1/1
3493
    filters # will be removed at 2017/1/1
3494
    
3495
    # Methods
3496
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3497

            
3498
L<DBIx::Custom::QueryBuilder>
3499
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3500
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3501
    tags # will be removed at 2017/1/1
3502
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3503
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3504
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3505
    register_tag # will be removed at 2017/1/1
3506
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3507
    
3508
    # Others
3509
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3510
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3511

            
3512
L<DBIx::Custom::Result>
3513
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3514
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3515
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3516
    
3517
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3518
    end_filter # will be removed at 2017/1/1
3519
    remove_end_filter # will be removed at 2017/1/1
3520
    remove_filter # will be removed at 2017/1/1
3521
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3522

            
3523
L<DBIx::Custom::Tag>
3524

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

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

            
3529
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3530
except for attribute method.
3531
You can check all DEPRECATED functionalities by document.
3532
DEPRECATED functionality is removed after five years,
3533
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
3534
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3535

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

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

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

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

            
3544
C<< <kimoto.yuki at gmail.com> >>
3545

            
3546
L<http://github.com/yuki-kimoto/DBIx-Custom>
3547

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3548
=head1 AUTHOR
3549

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

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

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

            
3556
This program is free software; you can redistribute it and/or modify it
3557
under the same terms as Perl itself.
3558

            
3559
=cut