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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
663
sub include_model {
664
    my ($self, $name_space, $model_infos) = @_;
665
    
cleanup
Yuki Kimoto authored on 2011-04-02
666
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
667
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
668
    
669
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
670
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
671

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
728
sub mapper {
729
    my $self = shift;
730
    return DBIx::Custom::Mapper->new(@_);
731
}
732

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

            
759
        # Map parameter
760
        my $value;
761
        if (ref $condition eq 'CODE') {
762
            $map_param->{$map_key} = $value_cb->($param->{$key})
763
              if $condition->($param->{$key});
764
        }
765
        elsif ($condition eq 'exists') {
766
            $map_param->{$map_key} = $value_cb->($param->{$key})
767
              if exists $param->{$key};
768
        }
769
        else { croak qq/Condition must be code reference or "exists" / . _subname }
770
    }
771
    
772
    return $map_param;
773
}
774

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

            
cleanup
Yuki Kimoto authored on 2011-03-21
799
sub method {
800
    my $self = shift;
801
    
cleanup
Yuki Kimoto authored on 2011-04-02
802
    # Register method
cleanup
Yuki Kimoto authored on 2011-03-21
803
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
804
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
805
    
806
    return $self;
807
}
808

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
809
sub model {
810
    my ($self, $name, $model) = @_;
811
    
cleanup
Yuki Kimoto authored on 2011-04-02
812
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
813
    if ($model) {
814
        $self->models->{$name} = $model;
815
        return $self;
816
    }
817
    
818
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
819
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
820
      unless $self->models->{$name};
821
    
cleanup
Yuki Kimoto authored on 2011-04-02
822
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
823
    return $self->models->{$name};
824
}
825

            
cleanup
Yuki Kimoto authored on 2011-03-21
826
sub mycolumn {
827
    my ($self, $table, $columns) = @_;
828
    
cleanup
Yuki Kimoto authored on 2011-04-02
829
    # Create column clause
830
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
831
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
832
    push @column, $self->_q($table) . "." . $self->_q($_) .
833
      " as " . $self->_q($_)
834
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
835
    
836
    return join (', ', @column);
837
}
838

            
added dbi_options attribute
kimoto authored on 2010-12-20
839
sub new {
840
    my $self = shift->SUPER::new(@_);
841
    
cleanup
Yuki Kimoto authored on 2011-04-02
842
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
843
    my @attrs = keys %$self;
844
    foreach my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
845
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
846
          unless $self->can($attr);
847
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
848

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
849
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
850
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
851
        '?'     => \&DBIx::Custom::Tag::placeholder,
852
        '='     => \&DBIx::Custom::Tag::equal,
853
        '<>'    => \&DBIx::Custom::Tag::not_equal,
854
        '>'     => \&DBIx::Custom::Tag::greater_than,
855
        '<'     => \&DBIx::Custom::Tag::lower_than,
856
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
857
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
858
        'like'  => \&DBIx::Custom::Tag::like,
859
        'in'    => \&DBIx::Custom::Tag::in,
860
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
861
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
862
    };
863
    
864
    return $self;
865
}
866

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

            
869
sub order {
870
    my $self = shift;
871
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
872
}
873

            
cleanup
yuki-kimoto authored on 2010-10-17
874
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
875
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
876
    
877
    # Register filter
878
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
879
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
880
    
cleanup
Yuki Kimoto authored on 2011-04-02
881
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
882
}
packaging one directory
yuki-kimoto authored on 2009-11-16
883

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

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1017
sub setup_model {
1018
    my $self = shift;
1019
    
cleanup
Yuki Kimoto authored on 2011-04-02
1020
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1021
    $self->each_column(
1022
        sub {
1023
            my ($self, $table, $column, $column_info) = @_;
1024
            if (my $model = $self->models->{$table}) {
1025
                push @{$model->columns}, $column;
1026
            }
1027
        }
1028
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
1029
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1030
}
1031

            
update pod
Yuki Kimoto authored on 2011-08-10
1032
sub show_datatype {
1033
    my ($self, $table) = @_;
1034
    croak "Table name must be specified" unless defined $table;
1035
    print "$table\n";
1036
    
1037
    my $result = $self->select(table => $table, where => "'0' <> '0'");
1038
    my $sth = $result->sth;
1039

            
1040
    my $columns = $sth->{NAME};
1041
    my $data_types = $sth->{TYPE};
1042
    
1043
    for (my $i = 0; $i < @$columns; $i++) {
1044
        my $column = $columns->[$i];
1045
        my $data_type = $data_types->[$i];
1046
        print "$column: $data_type\n";
1047
    }
1048
}
1049

            
1050
sub show_typename {
1051
    my ($self, $t) = @_;
1052
    croak "Table name must be specified" unless defined $t;
1053
    print "$t\n";
1054
    
1055
    $self->each_column(sub {
1056
        my ($self, $table, $column, $infos) = @_;
1057
        return unless $table eq $t;
1058
        my $typename = $infos->{TYPE_NAME};
1059
        print "$column: $typename\n";
1060
    });
1061
    
1062
    return $self;
1063
}
1064

            
test cleanup
Yuki Kimoto authored on 2011-08-15
1065
sub show_tables {
1066
    my $self = shift;
1067
    
1068
    my %tables;
1069
    $self->each_table(sub { $tables{$_[1]}++ });
1070
    print join("\n", sort keys %tables) . "\n";
1071
    return $self;
1072
}
1073

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1109
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1110
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1111
                }
1112
            });
1113
        }
1114

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1140
    # Arguments
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1141
    my $param;
1142
    $param = shift if @_ % 2;
1143
    my %args = @_;
cleanup
Yuki Kimoto authored on 2011-03-21
1144
    my $table = delete $args{table} || '';
cleanup
Yuki Kimoto authored on 2011-04-25
1145
    croak qq{"table" option must be specified } . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
1146
      unless $table;
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
1147
    my $p = delete $args{param} || {};
1148
    $param  ||= $p;
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1149
    my $where = delete $args{where} || {};
1150
    my $where_param = delete $args{where_param} || {};
1151
    my $append = delete $args{append} || '';
cleanup
Yuki Kimoto authored on 2011-03-21
1152
    my $allow_update_all = delete $args{allow_update_all};
cleanup
Yuki Kimoto authored on 2011-06-08
1153
    my $id = delete $args{id};
1154
    my $primary_key = delete $args{primary_key};
1155
    croak "update method primary_key option " .
1156
          "must be specified when id is specified " . _subname
1157
      if defined $id && !defined $primary_key;
1158
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
added EXPERIMENTAL insert, u...
Yuki Kimoto authored on 2011-06-21
1159
    my $prefix = delete $args{prefix};
updated pod
Yuki Kimoto authored on 2011-09-02
1160
    my $wrap = delete $args{wrap};
update_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1161

            
cleanup
yuki-kimoto authored on 2010-10-17
1162
    # Update clause
updated pod
Yuki Kimoto authored on 2011-09-02
1163
    my $update_clause = $self->update_param($param, {wrap => $wrap});
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1164

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

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

            
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1204
sub update_param {
updated pod
Yuki Kimoto authored on 2011-09-02
1205
    my ($self, $param, $opts) = @_;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
1206
    
cleanup
Yuki Kimoto authored on 2011-04-02
1207
    # Create update parameter tag
updated pod
Yuki Kimoto authored on 2011-09-02
1208
    my $tag = $self->assign_param($param, $opts);
1209
    $tag = "set $tag" unless $opts->{no_set};
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
1210

            
cleanup
Yuki Kimoto authored on 2011-04-02
1211
    return $tag;
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
1212
}
1213

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1216
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1217
    
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1218
    my ($self, $source, $sqlfilter) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1219
    
updated pod
Yuki Kimoto authored on 2011-06-21
1220
    # Cache
1221
    my $cache = $self->cache;
1222
    
1223
    # Query
1224
    my $query;
1225
    
1226
    # Get cached query
1227
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1228
        
updated pod
Yuki Kimoto authored on 2011-06-21
1229
        # Get query
1230
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1231
        
updated pod
Yuki Kimoto authored on 2011-06-21
1232
        # Create query
1233
        if ($q) {
1234
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1235
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1236
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1237
    }
1238
    
1239
    # Create query
1240
    unless ($query) {
1241

            
1242
        # Create query
1243
        my $builder = $self->query_builder;
1244
        $query = $builder->build_query($source);
1245

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

            
1252
        # Save query to cache
1253
        $self->cache_method->(
1254
            $self, $source,
1255
            {
1256
                sql     => $query->sql, 
1257
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1258
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1259
            }
1260
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1261
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1262

            
1263
    # Filter SQL
1264
    if ($sqlfilter) {
1265
        my $sql = $query->sql;
1266
        $sql = $sqlfilter->($sql);
1267
        $query->sql($sql);
1268
    }
1269
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1270
    # Save sql
1271
    $self->last_sql($query->sql);
1272
    
updated pod
Yuki Kimoto authored on 2011-06-21
1273
    # Prepare statement handle
1274
    my $sth;
1275
    eval { $sth = $self->dbh->prepare($query->{sql})};
1276
    
1277
    if ($@) {
1278
        $self->_croak($@, qq{. Following SQL is executed.\n}
1279
                        . qq{$query->{sql}\n} . _subname);
1280
    }
1281
    
1282
    # Set statement handle
1283
    $query->sth($sth);
1284
    
1285
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1286
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1287
    
1288
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1289
}
1290

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1397
sub _croak {
1398
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1399
    
1400
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1401
    $append ||= "";
1402
    
1403
    # Verbose
1404
    if ($Carp::Verbose) { croak $error }
1405
    
1406
    # Not verbose
1407
    else {
1408
        
1409
        # Remove line and module infromation
1410
        my $at_pos = rindex($error, ' at ');
1411
        $error = substr($error, 0, $at_pos);
1412
        $error =~ s/\s+$//;
1413
        croak "$error$append";
1414
    }
1415
}
1416

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1419
sub _need_tables {
1420
    my ($self, $tree, $need_tables, $tables) = @_;
1421
    
cleanup
Yuki Kimoto authored on 2011-04-02
1422
    # Get needed tables
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1423
    foreach my $table (@$tables) {
1424
        if ($tree->{$table}) {
1425
            $need_tables->{$table} = 1;
1426
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1427
        }
1428
    }
1429
}
1430

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1431
sub _push_join {
1432
    my ($self, $sql, $join, $join_tables) = @_;
1433
    
cleanup
Yuki Kimoto authored on 2011-04-02
1434
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1435
    return unless @$join;
1436
    
cleanup
Yuki Kimoto authored on 2011-04-02
1437
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1438
    my $tree = {};
1439
    for (my $i = 0; $i < @$join; $i++) {
1440
        
cleanup
Yuki Kimoto authored on 2011-07-28
1441
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1442
        my $join_clause;;
1443
        my $option;
1444
        if (ref $join->[$i] eq 'HASH') {
1445
            $join_clause = $join->[$i]->{clause};
1446
            $option = {table => $join->[$i]->{table}};
1447
        }
1448
        else {
1449
            $join_clause = $join->[$i];
1450
            $option = {};
1451
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1452

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1496
sub _quote {
1497
    my $self = shift;
1498
    
1499
    return defined $self->reserved_word_quote ? $self->reserved_word_quote
1500
         : defined $self->quote ? $self->quote
1501
         : '';
1502
}
1503

            
cleanup
Yuki Kimoto authored on 2011-07-29
1504
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1505
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1506
    
1507
    my $quote = $self->_quote;
1508
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1509
    my $p;
1510
    if (defined $quote && length $quote > 1) {
1511
        $p = substr($quote, 1, 1);
1512
    }
1513
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1514
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1515
    if ($quotemeta) {
1516
        $q = quotemeta($q);
1517
        $p = quotemeta($p);
1518
    }
1519
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1520
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1521
}
1522

            
cleanup
Yuki Kimoto authored on 2011-04-02
1523
sub _remove_duplicate_table {
1524
    my ($self, $tables, $main_table) = @_;
1525
    
1526
    # Remove duplicate table
1527
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1528
    delete $tables{$main_table} if $main_table;
1529
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1530
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1531
    if (my $q = $self->_quote) {
1532
        $q = quotemeta($q);
1533
        $_ =~ s/[$q]//g for @$new_tables;
1534
    }
1535

            
1536
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1537
}
1538

            
cleanup
Yuki Kimoto authored on 2011-04-02
1539
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1540
    my ($self, $source) = @_;
1541
    
cleanup
Yuki Kimoto authored on 2011-04-02
1542
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1543
    my $tables = [];
1544
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1545
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1546
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1547
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1548
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1549
    while ($source =~ /$table_re/g) {
1550
        push @$tables, $1;
1551
    }
1552
    
1553
    return $tables;
1554
}
1555

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

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

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

            
1675
# DEPRECATED!
1676
sub create_query {
1677
    warn "create_query is DEPRECATED! use query option of each method";
1678
    shift->_create_query(@_);
1679
}
1680

            
cleanup
Yuki Kimoto authored on 2011-06-13
1681
# DEPRECATED!
1682
sub apply_filter {
1683
    my $self = shift;
1684
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1685
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1686
    return $self->_apply_filter(@_);
1687
}
1688

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

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

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1696
    # Arguments
1697
    my $primary_keys = delete $args{primary_key};
1698
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1699
    my $where = delete $args{where};
1700
    my $param = delete $args{param};
1701
    
1702
    # Check arguments
1703
    foreach my $name (keys %args) {
1704
        croak qq{"$name" is wrong option } . _subname
1705
          unless $SELECT_AT_ARGS{$name};
1706
    }
1707
    
1708
    # Table
1709
    croak qq{"table" option must be specified } . _subname
1710
      unless $args{table};
1711
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
1712
    
1713
    # Create where parameter
1714
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1715
    
1716
    return $self->select(where => $where_param, %args);
1717
}
1718

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

            
1724
    warn "delete_at is DEPRECATED! use update and id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1725
    
1726
    # Arguments
1727
    my $primary_keys = delete $args{primary_key};
1728
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1729
    my $where = delete $args{where};
1730
    
1731
    # Check arguments
1732
    foreach my $name (keys %args) {
1733
        croak qq{"$name" is wrong option } . _subname
1734
          unless $DELETE_AT_ARGS{$name};
1735
    }
1736
    
1737
    # Create where parameter
1738
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1739
    
1740
    return $self->delete(where => $where_param, %args);
1741
}
1742

            
cleanup
Yuki Kimoto authored on 2011-06-08
1743
# DEPRECATED!
simplified arguments check
Yuki Kimoto authored on 2011-07-11
1744
our %UPDATE_AT_ARGS = (%VALID_ARGS, where => 1, primary_key => 1);
cleanup
Yuki Kimoto authored on 2011-06-08
1745
sub update_at {
1746
    my $self = shift;
1747

            
1748
    warn "update_at is DEPRECATED! use update and id option instead";
1749
    
1750
    # Arguments
1751
    my $param;
1752
    $param = shift if @_ % 2;
1753
    my %args = @_;
1754
    my $primary_keys = delete $args{primary_key};
1755
    $primary_keys = [$primary_keys] unless ref $primary_keys;
1756
    my $where = delete $args{where};
1757
    my $p = delete $args{param} || {};
1758
    $param  ||= $p;
1759
    
1760
    # Check arguments
1761
    foreach my $name (keys %args) {
1762
        croak qq{"$name" is wrong option } . _subname
1763
          unless $UPDATE_AT_ARGS{$name};
1764
    }
1765
    
1766
    # Create where parameter
1767
    my $where_param = $self->_create_param_from_id($where, $primary_keys);
1768
    
1769
    return $self->update(where => $where_param, param => $param, %args);
1770
}
1771

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

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

            
1815
# DEPRECATED!
1816
sub register_tag_processor {
1817
    my $self = shift;
1818
    warn "register_tag_processor is DEPRECATED!";
1819
    # Merge tag
1820
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1821
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1822
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1823
}
1824

            
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1825
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-06-13
1826
has 'data_source';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1827
has dbi_options => sub { {} };
1828
has filter_check  => 1;
1829
has 'reserved_word_quote';
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1830

            
cleanup
Yuki Kimoto authored on 2011-01-25
1831
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1832
sub default_bind_filter {
1833
    my $self = shift;
1834
    
cleanup
Yuki Kimoto authored on 2011-06-13
1835
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1836
    
cleanup
Yuki Kimoto authored on 2011-01-12
1837
    if (@_) {
1838
        my $fname = $_[0];
1839
        
1840
        if (@_ && !$fname) {
1841
            $self->{default_out_filter} = undef;
1842
        }
1843
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1844
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1845
              unless exists $self->filters->{$fname};
1846
        
1847
            $self->{default_out_filter} = $self->filters->{$fname};
1848
        }
1849
        return $self;
1850
    }
1851
    
1852
    return $self->{default_out_filter};
1853
}
1854

            
cleanup
Yuki Kimoto authored on 2011-01-25
1855
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1856
sub default_fetch_filter {
1857
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1858

            
cleanup
Yuki Kimoto authored on 2011-06-13
1859
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1860
    
1861
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1862
        my $fname = $_[0];
1863

            
cleanup
Yuki Kimoto authored on 2011-01-12
1864
        if (@_ && !$fname) {
1865
            $self->{default_in_filter} = undef;
1866
        }
1867
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1868
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1869
              unless exists $self->filters->{$fname};
1870
        
1871
            $self->{default_in_filter} = $self->filters->{$fname};
1872
        }
1873
        
1874
        return $self;
1875
    }
1876
    
many changed
Yuki Kimoto authored on 2011-01-23
1877
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1878
}
1879

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1880
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1881
sub insert_param_tag {
1882
    warn "insert_param_tag is DEPRECATED! " .
1883
         "use insert_param instead!";
1884
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1885
}
1886

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

            
1909
# DEPRECATED!
1910
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1911
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1912
    
1913
    if (keys %{$relation || {}}) {
1914
        foreach my $rcolumn (keys %$relation) {
1915
            my $table1 = (split (/\./, $rcolumn))[0];
1916
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1917
            my $table1_exists;
1918
            my $table2_exists;
1919
            foreach my $table (@$tables) {
1920
                $table1_exists = 1 if $table eq $table1;
1921
                $table2_exists = 1 if $table eq $table2;
1922
            }
1923
            unshift @$tables, $table1 unless $table1_exists;
1924
            unshift @$tables, $table2 unless $table2_exists;
1925
        }
1926
    }
1927
}
1928

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1931
=head1 NAME
1932

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1937
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1938
    
1939
    # Connect
1940
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1941
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1942
        user => 'ken',
1943
        password => '!LFKD%$&',
1944
        dbi_option => {mysql_enable_utf8 => 1}
1945
    );
cleanup
yuki-kimoto authored on 2010-08-05
1946

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1947
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1948
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1949
    
1950
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1951
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1952
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1953
    
1954
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1955
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1956

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2006
Named place holder support
2007

            
2008
=item *
2009

            
cleanup
Yuki Kimoto authored on 2011-07-29
2010
Model support
2011

            
2012
=item *
2013

            
2014
Connection manager support
2015

            
2016
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2017

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

            
2022
=item *
2023

            
2024
Filtering by data type or column name(EXPERIMENTAL)
2025

            
2026
=item *
2027

            
2028
Create C<order by> clause flexibly(EXPERIMENTAL)
2029

            
2030
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2031

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2039
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2040
L<DBIx::Custom::Result>,
2041
L<DBIx::Custom::Query>,
2042
L<DBIx::Custom::Where>,
2043
L<DBIx::Custom::Model>,
2044
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2045

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

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

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

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

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

            
2059
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2060
        "dbi:mysql:database=$database",
2061
        $user,
2062
        $password,
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2063
        DBIx::Custom->new->default_dbi_option
2064
    );
2065
    
updated pod
Yuki Kimoto authored on 2011-06-21
2066
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2067

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

            
2071
    my $dbi = DBIx::Custom->connect(
2072
      dsn => $dsn, user => $user, password => $password, connector => 1);
2073
    
2074
    my $connector = $dbi->connector; # DBIx::Connector
2075

            
2076
Note that L<DBIx::Connector> must be installed.
2077

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

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

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

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

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

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

            
2093
=head2 C<default_dbi_option>
2094

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2101
    {
2102
        RaiseError => 1,
2103
        PrintError => 0,
2104
        AutoCommit => 1,
2105
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2106

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

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

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

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

            
2116
    my $last_sql = $dbi->last_sql;
2117
    $dbi = $dbi->last_sql($last_sql);
2118

            
2119
Get last successed SQL executed by C<execute> method.
2120

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2128
=head2 C<password>
2129

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2150
You can set quote pair.
2151

            
2152
    $dbi->quote('[]');
2153

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

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

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

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

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

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

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

            
2171
    my $separator = $self->separator;
2172
    $dbi = $self->separator($separator);
2173

            
2174
Separator whichi join table and column.
2175
This is used by C<column> and C<mycolumn> method.
2176

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

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

            
2182
Regex matching system table.
2183
this regex match is used by C<each_table> method and C<each_column> method
2184
System table is ignored.
2185
C<type_rule> method and C<setup_model> method call
renamed system_table to excl...
Yuki Kimoto authored on 2011-08-10
2186
C<each_table>, so if you set C<exclude_table> properly,
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
2187
The performance is up.
2188

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

            
2191
    my $tag_parse = $dbi->tag_parse(0);
2192
    $dbi = $dbi->tag_parse;
2193

            
2194
Enable DEPRECATED tag parsing functionality, default to 1.
2195
If you want to disable tag parsing functionality, set to 0.
2196

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

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

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

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

            
2206
    my $user_column_info = $dbi->user_column_info;
2207
    $dbi = $dbi->user_column_info($user_column_info);
2208

            
2209
You can set the following data.
2210

            
2211
    [
2212
        {table => 'book', column => 'title', info => {...}},
2213
        {table => 'author', column => 'name', info => {...}}
2214
    ]
2215

            
2216
Usually, you can set return value of C<get_column_info>.
2217

            
2218
    my $user_column_info
2219
      = $dbi->get_column_info(exclude_table => qr/^system/);
2220
    $dbi->user_column_info($user_column_info);
2221

            
2222
If C<user_column_info> is set, C<each_column> use C<user_column_info>
2223
to find column info.
2224

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

            
2227
    my $user_table_info = $dbi->user_table_info;
2228
    $dbi = $dbi->user_table_info($user_table_info);
2229

            
2230
You can set the following data.
2231

            
2232
    [
2233
        {table => 'book', info => {...}},
2234
        {table => 'author', info => {...}}
2235
    ]
2236

            
2237
Usually, you can set return value of C<get_table_info>.
2238

            
2239
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2240
    $dbi->user_table_info($user_table_info);
2241

            
2242
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2243
to find table info.
2244

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2279
Create column clause. The follwoing column clause is created.
2280

            
2281
    book.author as "book.author",
2282
    book.title as "book.title"
2283

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2286
    # Separator is double underbar
2287
    $dbi->separator('__');
2288
    
2289
    book.author as "book__author",
2290
    book.title as "book__title"
- select() EXPERIMETNAL colu...
Yuki Kimoto authored on 2011-06-08
2291

            
cleanup
Yuki Kimoto authored on 2011-06-13
2292
    # Separator is hyphen
2293
    $dbi->separator('-');
2294
    
2295
    book.author as "book-author",
2296
    book.title as "book-title"
2297
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2298
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2299

            
update pod
Yuki Kimoto authored on 2011-03-13
2300
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2301
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2302
        user => 'ken',
2303
        password => '!LFKD%$&',
2304
        dbi_option => {mysql_enable_utf8 => 1}
2305
    );
2306

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

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

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

            
2315
    my $count = $model->count(table => 'book');
2316

            
2317
Get rows count.
2318

            
2319
Options is same as C<select> method's ones.
2320

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2323
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2324
        table => 'book',
2325
        primary_key => 'id',
2326
        join => [
2327
            'inner join company on book.comparny_id = company.id'
2328
        ],
2329
    );
2330

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

            
2334
   $dbi->model('book')->select(...);
2335

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

            
2338
    my $dbh = $dbi->dbh;
2339

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

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

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

            
2347
Execute delete statement.
2348

            
2349
The following opitons are available.
2350

            
2351
=over 4
2352

            
2353
=item C<append>
2354

            
2355
Same as C<select> method's C<append> option.
2356

            
2357
=item C<filter>
2358

            
2359
Same as C<execute> method's C<filter> option.
2360

            
2361
=item C<id>
2362

            
2363
    id => 4
2364
    id => [4, 5]
2365

            
2366
ID corresponding to C<primary_key>.
2367
You can delete rows by C<id> and C<primary_key>.
2368

            
2369
    $dbi->delete(
2370
        parimary_key => ['id1', 'id2'],
2371
        id => [4, 5],
2372
        table => 'book',
2373
    );
2374

            
2375
The above is same as the followin one.
2376

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

            
2379
=item C<prefix>
2380

            
2381
    prefix => 'some'
2382

            
2383
prefix before table name section.
2384

            
2385
    delete some from book
2386

            
2387
=item C<query>
2388

            
2389
Same as C<execute> method's C<query> option.
2390

            
2391
=item C<sqlfilter EXPERIMENTAL>
2392

            
2393
Same as C<execute> method's C<sqlfilter> option.
2394

            
2395
=item C<table>
2396

            
2397
    table => 'book'
2398

            
2399
Table name.
2400

            
2401
=item C<where>
2402

            
2403
Same as C<select> method's C<where> option.
2404

            
2405
=item C<primary_key>
2406

            
2407
See C<id> option.
2408

            
2409
=item C<bind_type>
2410

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

            
2413
=item C<type_rule_off> EXPERIMENTAL
2414

            
2415
Same as C<execute> method's C<type_rule_off> option.
2416

            
2417
=item C<type_rule1_off> EXPERIMENTAL
2418

            
2419
    type_rule1_off => 1
2420

            
2421
Same as C<execute> method's C<type_rule1_off> option.
2422

            
2423
=item C<type_rule2_off> EXPERIMENTAL
2424

            
2425
    type_rule2_off => 1
2426

            
2427
Same as C<execute> method's C<type_rule2_off> option.
2428

            
2429
=back
2430

            
2431
=head2 C<delete_all>
2432

            
2433
    $dbi->delete_all(table => $table);
2434

            
2435
Execute delete statement for all rows.
2436
Options is same as C<delete>.
2437

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

            
2440
    $dbi->each_column(
2441
        sub {
2442
            my ($dbi, $table, $column, $column_info) = @_;
2443
            
2444
            my $type = $column_info->{TYPE_NAME};
2445
            
2446
            if ($type eq 'DATE') {
2447
                # ...
2448
            }
2449
        }
2450
    );
2451

            
2452
Iterate all column informations of all table from database.
2453
Argument is callback when one column is found.
2454
Callback receive four arguments, dbi object, table name,
2455
column name and column information.
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2456

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

            
2459
    $dbi->each_table(
2460
        sub {
2461
            my ($dbi, $table, $table_info) = @_;
2462
            
2463
            my $table_name = $table_info->{TABLE_NAME};
2464
        }
2465
    );
2466

            
2467
Iterate all table informationsfrom database.
2468
Argument is callback when one table is found.
2469
Callback receive three arguments, dbi object, table name,
2470
table information.
2471

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

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

            
2479
    my $result = $dbi->execute(
2480
      "select * from book where title = :book.title and author like :book.author",
2481
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2482
    );
2483

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2490
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2491
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2492
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2493
    select * from book where title = :title and author like :author
2494
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2495
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2496
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2497

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2501
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2502
    select * from book where :title{=} and :author{like}
2503
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2504
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2505
    select * from where title = ? and author like ?;
2506

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

            
2511
    select * from where title = "aa\\:bb";
2512

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

            
2515
=over 4
2516

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

            
2519
Specify database bind data type.
2520

            
2521
    bind_type => [image => DBI::SQL_BLOB]
2522
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2523

            
2524
This is used to bind parameter by C<bind_param> of statment handle.
2525

            
2526
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2527

            
update pod
Yuki Kimoto authored on 2011-03-13
2528
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2529
    
2530
    filter => {
2531
        title  => sub { uc $_[0] }
2532
        author => sub { uc $_[0] }
2533
    }
update pod
Yuki Kimoto authored on 2011-03-13
2534

            
updated pod
Yuki Kimoto authored on 2011-06-09
2535
    # Filter name
2536
    filter => {
2537
        title  => 'upper_case',
2538
        author => 'upper_case'
2539
    }
2540
        
2541
    # At once
2542
    filter => [
2543
        [qw/title author/]  => sub { uc $_[0] }
2544
    ]
2545

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

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

            
2553
    id => 4
2554
    id => [4, 5]
2555

            
2556
ID corresponding to C<primary_key>.
2557
You can delete rows by C<id> and C<primary_key>.
2558

            
2559
    $dbi->execute(
2560
        "select * from book where id1 = :id1 and id2 = :id2",
2561
        {},
2562
        parimary_key => ['id1', 'id2'],
2563
        id => [4, 5],
2564
    );
2565

            
2566
The above is same as the followin one.
2567

            
2568
    $dbi->execute(
2569
        "select * from book where id1 = :id1 and id2 = :id2",
2570
        {id1 => 4, id2 => 5}
2571
    );
2572

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

            
2575
    query => 1
2576

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

            
2580
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2581
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2582
    my $columns = $query->columns;
2583
    
2584
If you want to execute SQL fast, you can do the following way.
2585

            
2586
    my $query;
2587
    foreach my $row (@$rows) {
2588
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
2589
      $dbi->execute($query, $row, filter => {ab => sub { $_[0] * 2 }});
2590
    }
2591

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

            
2595
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
2596
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2597
    
2598
    my $query;
2599
    my $sth;
2600
    foreach my $row (@$rows) {
2601
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2602
      $sth ||= $query->sth;
2603
      $sth->execute(map { $row->{$_} } sort keys %$row);
2604
    }
2605

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

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

            
2612
See C<id> option.
2613

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

            
2616
SQL filter function.
2617

            
2618
    sqlfilter => $code_ref
2619

            
2620
This option is generally for Oracle and SQL Server paging process.
2621
    
2622
    my $limit = sub {
2623
        my ($sql, $count, $offset) = @_;
2624
        
2625
        my $min = $offset + 1;
2626
        my $max = $offset + $count;
2627
        
2628
        $sql = "select * from ( $sql ) as t where rnum >= $min rnum <= $max";
2629
        
2630
        return $sql;
2631
    }
2632
    $dbi->select(... column => ['ROWNUM rnom'], sqlfilter => sub {
2633
        my $sql = shift;
2634
        return $limit->($sql, 100, 50);
2635
    })
2636

            
updated pod
Yuki Kimoto authored on 2011-06-09
2637
=item C<table>
2638
    
2639
    table => 'author'
2640

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2648
    # Same
2649
    $dbi->execute(
2650
      "select * from book where title = :book.title and author = :book.author",
2651
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2652

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

            
2655
    table_alias => {user => 'hiker'}
2656

            
2657
Table alias. Key is real table name, value is alias table name.
2658
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2659
on alias table name.
2660

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

            
2663
    type_rule_off => 1
2664

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

            
2667
=item C<type_rule1_off> EXPERIMENTAL
2668

            
2669
    type_rule1_off => 1
2670

            
2671
Turn C<into1> type rule off.
2672

            
2673
=item C<type_rule2_off> EXPERIMENTAL
2674

            
2675
    type_rule2_off => 1
2676

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

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

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

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

            
2685
get column infomation except for one which match C<exclude_table> pattern.
2686

            
2687
    [
2688
        {table => 'book', column => 'title', info => {...}},
2689
        {table => 'author', column => 'name' info => {...}}
2690
    ]
2691

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

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

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

            
2698
    [
2699
        {table => 'book', info => {...}},
2700
        {table => 'author', info => {...}}
2701
    ]
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
2702

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2705
=head2 C<insert>
2706

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

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

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

            
2715
    {date => \"NOW()"}
2716

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

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

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

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

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

            
2727
Same as C<execute> method's C<bind_type> option.
2728

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

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

            
2733
=item C<id>
2734

            
updated document
Yuki Kimoto authored on 2011-06-09
2735
    id => 4
2736
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2737

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

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

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

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

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

            
2757
    prefix => 'or replace'
2758

            
2759
prefix before table name section
2760

            
2761
    insert or replace into book
2762

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

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

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

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

            
2772
Same as C<execute> method's C<query> option.
2773

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

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

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

            
2780
    table => 'book'
2781

            
2782
Table name.
2783

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

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

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

            
2790
    type_rule1_off => 1
2791

            
2792
Same as C<execute> method's C<type_rule1_off> option.
2793

            
2794
=item C<type_rule2_off> EXPERIMENTAL
2795

            
2796
    type_rule2_off => 1
2797

            
2798
Same as C<execute> method's C<type_rule2_off> option.
2799

            
updated pod
Yuki Kimoto authored on 2011-09-02
2800
=item C<wrap EXPERIMENTAL>
2801

            
2802
    wrap => {price => sub { "max($_[0])" }}
2803

            
2804
placeholder wrapped string.
2805

            
2806
If the following statement
2807

            
2808
    $dbi->insert({price => 100}, table => 'book',
2809
      {price => sub { "$_[0] + 5" }});
2810

            
2811
is executed, the following SQL is executed.
2812

            
2813
    insert into book price values ( ? + 5 );
2814

            
update pod
Yuki Kimoto authored on 2011-03-13
2815
=back
2816

            
2817
=over 4
2818

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2834
    lib / MyModel.pm
2835
        / MyModel / book.pm
2836
                  / company.pm
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2837

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

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

            
2842
    package MyModel;
updated pod
Yuki Kimoto authored on 2011-06-21
2843
    use DBIx::Custom::Model -base;
update pod
Yuki Kimoto authored on 2011-03-13
2844
    
2845
    1;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
2846

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2851
    package MyModel::book;
updated pod
Yuki Kimoto authored on 2011-06-21
2852
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2853
    
2854
    1;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2855

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2858
    package MyModel::company;
updated pod
Yuki Kimoto authored on 2011-06-21
2859
    use MyModel -base;
update pod
Yuki Kimoto authored on 2011-03-13
2860
    
2861
    1;
2862
    
updated pod
Yuki Kimoto authored on 2011-06-21
2863
MyModel::book and MyModel::company is included by C<include_model>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
2864

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

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

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

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

            
2874
    my $mapper = $dbi->mapper(param => $param);
2875

            
2876
Create a new L<DBIx::Custom::Mapper> object.
2877

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

            
2880
    my $map_param = $dbi->map_param(
2881
        {id => 1, authro => 'Ken', price => 1900},
2882
        'id' => 'book.id',
2883
        'author' => ['book.author' => sub { '%' . $_[0] . '%' }],
2884
        'price' => [
2885
            'book.price', {if => sub { length $_[0] }}
2886
        ]
2887
    );
2888

            
2889
Map paramters to other key and value. First argument is original
2890
parameter. this is hash reference. Rest argument is mapping.
2891
By default, Mapping is done if the value length is not zero.
2892

            
2893
=over 4
2894

            
2895
=item Key mapping
2896

            
2897
    'id' => 'book.id'
2898

            
2899
This is only key mapping. Value is same as original one.
2900

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

            
2903
=item Key and value mapping
2904

            
2905
    'author' => ['book.author' => sub { '%' . $_[0] . '%' }]
2906

            
2907
This is key and value mapping. Frist element of array reference
2908
is mapped key name, second element is code reference to map the value.
2909

            
2910
    (author => 'Ken') is mapped to ('book.author' => '%Ken%')
2911
      if value length is not zero.
2912

            
2913
=item Condition
2914

            
2915
    'price' => ['book.price', {if => 'exists'}]
2916
    'price' => ['book.price', sub { '%' . $_[0] . '%' }, {if => 'exists'}]
2917
    'price' => ['book.price', {if => sub { defined shift }}]
2918

            
2919
If you need condition, you can sepecify it. this is code reference
2920
or 'exists'. By default, condition is the following one.
2921

            
2922
    sub { defined $_[0] && length $_[0] }
2923

            
2924
=back
2925

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

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

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

            
2932
    {key1 => [1, 1], key2 => 2}
2933

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

            
2936
    $dbi->method(
2937
        update_or_insert => sub {
2938
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2939
            
2940
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2941
        },
2942
        find_or_create   => sub {
2943
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-03-13
2944
            
2945
            # Process
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2946
        }
2947
    );
2948

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

            
2951
    $dbi->update_or_insert;
2952
    $dbi->find_or_create;
2953

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

            
2956
    my $model = $dbi->model('book');
2957

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

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

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

            
2964
Create column clause for myself. The follwoing column clause is created.
2965

            
2966
    book.author as author,
2967
    book.title as title
2968

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2971
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2972
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2973
        user => 'ken',
2974
        password => '!LFKD%$&',
2975
        dbi_option => {mysql_enable_utf8 => 1}
2976
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2977

            
2978
Create a new L<DBIx::Custom> object.
2979

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

            
2982
    my $not_exists = $dbi->not_exists;
2983

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

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

            
2989
    my $order = $dbi->order;
2990

            
2991
Create a new L<DBIx::Custom::Order> object.
2992

            
cleanup
yuki-kimoto authored on 2010-10-17
2993
=head2 C<register_filter>
2994

            
update pod
Yuki Kimoto authored on 2011-03-13
2995
    $dbi->register_filter(
2996
        # Time::Piece object to database DATE format
2997
        tp_to_date => sub {
2998
            my $tp = shift;
2999
            return $tp->strftime('%Y-%m-%d');
3000
        },
3001
        # database DATE format to Time::Piece object
3002
        date_to_tp => sub {
3003
           my $date = shift;
3004
           return Time::Piece->strptime($date, '%Y-%m-%d');
3005
        }
3006
    );
cleanup
yuki-kimoto authored on 2010-10-17
3007
    
update pod
Yuki Kimoto authored on 2011-03-13
3008
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
3009

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

            
3012
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3013
        into1 => {
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
3014
            date => sub { ... },
3015
            datetime => sub { ... }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3016
        },
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3017
        into2 => {
3018
            date => sub { ... },
3019
            datetime => sub { ... }
3020
        },
3021
        from1 => {
3022
            # DATE
3023
            9 => sub { ... },
3024
            # DATETIME or TIMESTAMP
3025
            11 => sub { ... },
3026
        }
3027
        from2 => {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3028
            # DATE
3029
            9 => sub { ... },
3030
            # DATETIME or TIMESTAMP
3031
            11 => sub { ... },
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3032
        }
3033
    );
3034

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3050
=over 4
3051

            
3052
=item 1. column name
3053

            
3054
    issue_date
3055
    issue_datetime
3056

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

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

            
3061
    book.issue_date
3062
    book.issue_datetime
3063

            
3064
=back
3065

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

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

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

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

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

            
3078
    $dbi->type_rule(
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
3079
        into1 => [
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
3080
            [qw/DATE DATETIME/] => sub { ... },
3081
        ],
3082
    );
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
3083

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
3086
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3087
        table  => 'book',
3088
        column => ['author', 'title'],
3089
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
3090
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3091
    
updated document
Yuki Kimoto authored on 2011-06-09
3092
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3093

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

            
3096
=over 4
3097

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

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

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

            
3104
=item C<bind_type>
3105

            
3106
Same as C<execute> method's C<bind_type> option.
updated document
Yuki Kimoto authored on 2011-06-09
3107
    
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3108
=item C<column>
3109
    
updated document
Yuki Kimoto authored on 2011-06-09
3110
    column => 'author'
3111
    column => ['author', 'title']
3112

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3121
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
3122
        {book => [qw/author title/]},
3123
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
3124
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
3125

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

            
3128
    book.author as "book.author",
3129
    book.title as "book.title",
3130
    person.name as "person.name",
3131
    person.age as "person.age"
3132

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

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

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

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

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

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

            
3148
=item C<id>
3149

            
3150
    id => 4
3151
    id => [4, 5]
3152

            
3153
ID corresponding to C<primary_key>.
3154
You can select rows by C<id> and C<primary_key>.
3155

            
3156
    $dbi->select(
3157
        parimary_key => ['id1', 'id2'],
3158
        id => [4, 5],
3159
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3160
    );
3161

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3164
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3165
        where => {id1 => 4, id2 => 5},
3166
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3167
    );
3168
    
updated document
Yuki Kimoto authored on 2011-06-09
3169
=item C<param> EXPERIMETNAL
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3170

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

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

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

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

            
3183
    prefix => 'SQL_CALC_FOUND_ROWS'
3184

            
3185
Prefix of column cluase
3186

            
3187
    select SQL_CALC_FOUND_ROWS title, author from book;
3188

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

            
3191
    join => [
3192
        'left outer join company on book.company_id = company_id',
3193
        'left outer join location on company.location_id = location.id'
3194
    ]
3195
        
3196
Join clause. If column cluase or where clause contain table name like "company.name",
3197
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3198

            
3199
    $dbi->select(
3200
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3201
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3202
        where => {'company.name' => 'Orange'},
3203
        join => [
3204
            'left outer join company on book.company_id = company.id',
3205
            'left outer join location on company.location_id = location.id'
3206
        ]
3207
    );
3208

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3212
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3213
    from book
3214
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3215
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3216

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

            
3220
    $dbi->select(
3221
        table => 'book',
3222
        column => ['company.location_id as location_id'],
3223
        where => {'company.name' => 'Orange'},
3224
        join => [
3225
            {
3226
                clause => 'left outer join location on company.location_id = location.id',
3227
                table => ['company', 'location']
3228
            }
3229
        ]
3230
    );
3231

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3251
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3252

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

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

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

            
3259
    type_rule1_off => 1
3260

            
3261
Same as C<execute> method's C<type_rule1_off> option.
3262

            
3263
=item C<type_rule2_off> EXPERIMENTAL
3264

            
3265
    type_rule2_off => 1
3266

            
3267
Same as C<execute> method's C<type_rule2_off> option.
3268

            
updated document
Yuki Kimoto authored on 2011-06-09
3269
=item C<where>
3270
    
3271
    # Hash refrence
3272
    where => {author => 'Ken', 'title' => 'Perl'}
3273
    
3274
    # DBIx::Custom::Where object
3275
    where => $dbi->where(
3276
        clause => ['and', 'author = :author', 'title like :title'],
3277
        param  => {author => 'Ken', title => '%Perl%'}
3278
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3279
    
3280
    # Array reference 1 (array reference, hash referenc). same as above
3281
    where => [
3282
        ['and', 'author = :author', 'title like :title'],
3283
        {author => 'Ken', title => '%Perl%'}
3284
    ];    
3285
    
3286
    # Array reference 2 (String, hash reference)
3287
    where => [
3288
        'title like :title',
3289
        {title => '%Perl%'}
3290
    ]
3291
    
3292
    # String
3293
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3294

            
updated document
Yuki Kimoto authored on 2011-06-09
3295
Where clause.
3296
    
improved pod
Yuki Kimoto authored on 2011-04-19
3297
=item C<wrap> EXPERIMENTAL
3298

            
3299
Wrap statement. This is array reference.
3300

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

            
3303
This option is for Oracle and SQL Server paging process.
3304

            
update pod
Yuki Kimoto authored on 2011-03-12
3305
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3306

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

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

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

            
3313
If you want to set constant value to row data, use scalar reference
3314
as parameter value.
3315

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

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

            
update pod
Yuki Kimoto authored on 2011-03-13
3320
=over 4
3321

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

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

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

            
3328
Same as C<execute> method's C<bind_type> option.
3329

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3336
    id => 4
3337
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3338

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3342
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3343
        {title => 'Perl', author => 'Ken'}
3344
        parimary_key => ['id1', 'id2'],
3345
        id => [4, 5],
3346
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3347
    );
update pod
Yuki Kimoto authored on 2011-03-13
3348

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3351
    $dbi->update(
3352
        {title => 'Perl', author => 'Ken'}
3353
        where => {id1 => 4, id2 => 5},
3354
        table => 'book'
3355
    );
update pod
Yuki Kimoto authored on 2011-03-13
3356

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

            
3359
    prefix => 'or replace'
3360

            
3361
prefix before table name section
3362

            
3363
    update or replace book
3364

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

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

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

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

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

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

            
3378
Same as C<execute> method's C<sqlfilter> option.
3379

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

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

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

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

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

            
3390
=item C<type_rule1_off> EXPERIMENTAL
3391

            
3392
    type_rule1_off => 1
3393

            
3394
Same as C<execute> method's C<type_rule1_off> option.
3395

            
3396
=item C<type_rule2_off> EXPERIMENTAL
3397

            
3398
    type_rule2_off => 1
3399

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

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

            
3404
Same as C<select> method's C<where> option.
3405

            
updated pod
Yuki Kimoto authored on 2011-09-02
3406
=item C<wrap EXPERIMENTAL>
3407

            
3408
    wrap => {price => sub { "max($_[0])" }}
3409

            
3410
placeholder wrapped string.
3411

            
3412
If the following statement
3413

            
3414
    $dbi->update({price => 100}, table => 'book',
3415
      {price => sub { "$_[0] + 5" }});
3416

            
3417
is executed, the following SQL is executed.
3418

            
3419
    update book set price =  ? + 5;
3420

            
updated pod
Yuki Kimoto authored on 2011-06-08
3421
=back
update pod
Yuki Kimoto authored on 2011-03-13
3422

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

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

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

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

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

            
3434
Create update parameter tag.
3435

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

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

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

            
3445
Create a new L<DBIx::Custom::Where> object.
3446

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

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

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

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

            
3456
=head2 C<DBIX_CUSTOM_DEBUG>
3457

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

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

            
3463
    $dbi->show_datatype($table);
3464

            
3465
Show data type of the columns of specified table.
3466

            
3467
    book
3468
    title: 5
3469
    issue_date: 91
3470

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

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

            
3475
    $dbi->show_tables;
3476

            
3477
Show tables.
3478

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

            
3481
    $dbi->show_typename($table);
3482

            
3483
Show type name of the columns of specified table.
3484

            
3485
    book
3486
    title: varchar
3487
    issue_date: date
3488

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

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

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

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

            
3497
L<DBIx::Custom>
3498

            
3499
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3500
    data_source # will be removed at 2017/1/1
3501
    dbi_options # will be removed at 2017/1/1
3502
    filter_check # will be removed at 2017/1/1
3503
    reserved_word_quote # will be removed at 2017/1/1
3504
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3505
    
3506
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3507
    create_query # will be removed at 2017/1/1
3508
    apply_filter # will be removed at 2017/1/1
3509
    select_at # will be removed at 2017/1/1
3510
    delete_at # will be removed at 2017/1/1
3511
    update_at # will be removed at 2017/1/1
3512
    insert_at # will be removed at 2017/1/1
3513
    register_tag # will be removed at 2017/1/1
3514
    default_bind_filter # will be removed at 2017/1/1
3515
    default_fetch_filter # will be removed at 2017/1/1
3516
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3517
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3518
    register_tag_processor # will be removed at 2017/1/1
3519
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3520
    
3521
    # Options
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3522
    select method relation option # will be removed at 2017/1/1
3523
    select method param option # will be removed at 2017/1/1
3524
    select method column option [COLUMN, as => ALIAS] format
3525
      # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3526
    
3527
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3528
    execute("select * from {= title}"); # execute method's
3529
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3530
                                        # will be removed at 2017/1/1
3531
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3532

            
3533
L<DBIx::Custom::Model>
3534

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3535
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3536
    filter # will be removed at 2017/1/1
3537
    name # will be removed at 2017/1/1
3538
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3539

            
3540
L<DBIx::Custom::Query>
3541
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3542
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3543
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3544
    table # will be removed at 2017/1/1
3545
    filters # will be removed at 2017/1/1
3546
    
3547
    # Methods
3548
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3549

            
3550
L<DBIx::Custom::QueryBuilder>
3551
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3552
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3553
    tags # will be removed at 2017/1/1
3554
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3555
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3556
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3557
    register_tag # will be removed at 2017/1/1
3558
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3559
    
3560
    # Others
3561
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3562
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3563

            
3564
L<DBIx::Custom::Result>
3565
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3566
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3567
    filter_check # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3568
    
3569
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3570
    end_filter # will be removed at 2017/1/1
3571
    remove_end_filter # will be removed at 2017/1/1
3572
    remove_filter # will be removed at 2017/1/1
3573
    default_filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3574

            
3575
L<DBIx::Custom::Tag>
3576

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

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

            
3581
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3582
except for attribute method.
3583
You can check all DEPRECATED functionalities by document.
3584
DEPRECATED functionality is removed after five years,
3585
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
3586
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3587

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

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

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

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

            
3596
C<< <kimoto.yuki at gmail.com> >>
3597

            
3598
L<http://github.com/yuki-kimoto/DBIx-Custom>
3599

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3600
=head1 AUTHOR
3601

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

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

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

            
3608
This program is free software; you can redistribute it and/or modify it
3609
under the same terms as Perl itself.
3610

            
3611
=cut