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

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

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

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
119
sub assign_clause {
updated pod
Yuki Kimoto authored on 2011-09-02
120
    my ($self, $param, $opts) = @_;
121
    
122
    my $wrap = $opts->{wrap} || {};
micro optimization
Yuki Kimoto authored on 2011-10-23
123
    my $safety = $self->{safety_character} || $self->safety_character;
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
124
    my $qp = $self->_q('');
125
    my $q = substr($qp, 0, 1) || '';
126
    my $p = substr($qp, 1, 1) || '';
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
127
    
micro optimization
Yuki Kimoto authored on 2011-10-23
128
    # Check unsafety keys
129
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
130
        for my $column (keys %$param) {
131
            croak qq{"$column" is not safety column name } . _subname
132
              unless $column =~ /^[$safety\.]+$/;
133
        }
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
134
    }
135
    
micro optimization
Yuki Kimoto authored on 2011-10-23
136
    # Assign clause (performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
137
    join(
138
      ', ',
139
      map {
140
          ref $param->{$_} eq 'SCALAR' ? "$q$_$p = " . ${$param->{$_}}
141
          : $wrap->{$_} ? "$q$_$p = " . $wrap->{$_}->(":$_")
142
          : "$q$_$p = :$_";
143
      } sort keys %$param
144
    );
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
145
}
146

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
234
sub delete {
235
    my ($self, %opt) = @_;
236
    warn "delete method where_param option is DEPRECATED!"
237
      if $opt{where_param};
238
    
cleanup
Yuki Kimoto authored on 2011-10-21
239
    # Don't allow delete all rows
cleanup
Yuki Kimoto authored on 2011-10-21
240
    croak qq{delete method where or id option must be specified } . _subname
241
      if !$opt{where} && !defined $opt{id} && !$opt{allow_delete_all};
242
    
243
    # Where
244
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
245
           ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
246
           : $opt{where};
247
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
248

            
cleanup
Yuki Kimoto authored on 2011-04-02
249
    # Delete statement
cleanup
Yuki Kimoto authored on 2011-10-21
250
    my $sql = "delete ";
cleanup
Yuki Kimoto authored on 2011-10-21
251
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
252
    $sql .= "from " . $self->_q($opt{table}) . " $w->{clause} ";
packaging one directory
yuki-kimoto authored on 2009-11-16
253
    
254
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
255
    $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
256
}
257

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

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

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

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
299
    my $user_column_info = $self->user_column_info;
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
300
    
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
301
    if ($user_column_info) {
302
        $self->$cb($_->{table}, $_->{column}, $_->{info}) for @$user_column_info;
303
    }
304
    else {
305
    
306
        my $re = $self->exclude_table || $options{exclude_table};
307
        # Tables
308
        my %tables;
309
        $self->each_table(sub { $tables{$_[1]}++ });
added SQL Server test
Yuki Kimoto authored on 2011-08-14
310

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

            
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
328
sub each_table {
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
329
    my ($self, $cb, %option) = @_;
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
330
    
cleanup test
Yuki Kimoto authored on 2011-08-16
331
    my $user_table_infos = $self->user_table_info;
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
332
    
added test
Yuki Kimoto authored on 2011-08-16
333
    # Iterate tables
334
    if ($user_table_infos) {
335
        $self->$cb($_->{table}, $_->{info}) for @$user_table_infos;
336
    }
337
    else {
338
        my $re = $self->exclude_table || $option{exclude};
339
        my $sth_tables = $self->dbh->table_info;
340
        while (my $table_info = $sth_tables->fetchrow_hashref) {
341
            
342
            # Table
343
            my $table = $table_info->{TABLE_NAME};
344
            next if defined $re && $table =~ /$re/;
345
            $self->$cb($table, $table_info);
346
        }
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
347
    }
348
}
349

            
cleanup
Yuki Kimoto authored on 2011-04-02
350
sub execute {
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
351
    my $self = shift;
cleanup
Yuki Kimoto authored on 2011-10-20
352
    my $sql = shift;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
353

            
354
    # Options
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
355
    my $param;
356
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
357
    my %opt = @_;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
358
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
359
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
360
    my $tables = $opt{table} || [];
cleanup
Yuki Kimoto authored on 2011-04-02
361
    $tables = [$tables] unless ref $tables eq 'ARRAY';
micro optimization
Yuki Kimoto authored on 2011-10-23
362
    my $filter = ref $opt{filter} eq 'ARRAY' ?
363
      _array_to_hash($opt{filter}) : $opt{filter};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
364
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
365
    # Append
366
    $sql .= $opt{append} if defined $opt{append} && !ref $sql;
367
    
368
    # Query
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
369
    my $query;
370
    if (ref $sql) { $query = $sql }
371
    else {
372
        $query = $opt{reuse}->{$sql} if $opt{reuse};
373
        $query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter})
374
          unless $query;
375
        $opt{reuse}->{$sql} = $query if $opt{reuse};
376
    }
377
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
378
    # Save query
micro optimization
Yuki Kimoto authored on 2011-10-23
379
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
380

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

            
cleanup
yuki-kimoto authored on 2010-10-17
458
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
459
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
460
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
461
    eval {
micro optimization
Yuki Kimoto authored on 2011-10-23
462
        if ($opt{bind_type} || $opt{type}) {
463
            $sth->bind_param($_ + 1, $bind->[$_],
464
                $bind_types->[$_] ? $bind_types->[$_] : ())
465
              for (0 .. @$bind - 1);
466
            $affected = $sth->execute;
467
        }
468
        else {
469
            $affected = $sth->execute(@$bind);
470
        }
cleanup
Yuki Kimoto authored on 2011-03-21
471
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
472
    
micro optimization
Yuki Kimoto authored on 2011-07-30
473
    $self->_croak($@, qq{. Following SQL is executed.\n}
474
      . qq{$query->{sql}\n} . _subname) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
475
    
improved debug message
Yuki Kimoto authored on 2011-05-23
476
    # DEBUG message
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
477
    if ($ENV{DBIX_CUSTOM_DEBUG}) {
478
        warn "SQL:\n" . $query->sql . "\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
479
        my @output;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
480
        for my $value (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
481
            $value = 'undef' unless defined $value;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
482
            $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
improved debug message
Yuki Kimoto authored on 2011-05-23
483
              if utf8::is_utf8($value);
484
            push @output, $value;
485
        }
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
486
        warn "Bind values: " . join(', ', @output) . "\n\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
487
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
488
    
micro optimization
Yuki Kimoto authored on 2011-10-23
489
    # Not select statement
490
    return $affected unless $sth->{NUM_OF_FIELDS};
491

            
492
    # Filter(DEPRECATED!)
493
    my $infilter = {};
494
    if ($self->{filter}{on}) {
495
        $infilter->{in}  = {};
496
        $infilter->{end} = {};
497
        push @$tables, $main_table if $main_table;
498
        for my $table (@$tables) {
499
            for my $way (qw/in end/) {
500
                $infilter->{$way} = {%{$infilter->{$way}},
501
                  %{$self->{filter}{$way}{$table} || {}}};
cleanup
Yuki Kimoto authored on 2011-04-02
502
            }
cleanup
Yuki Kimoto authored on 2011-01-12
503
        }
cleanup
yuki-kimoto authored on 2010-10-17
504
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
505
    
506
    # Result
507
    my $result = $self->result_class->new(
508
        sth => $sth,
509
        dbi => $self,
510
        default_filter => $self->{default_in_filter},
511
        filter => $infilter->{in} || {},
512
        end_filter => $infilter->{end} || {},
513
        type_rule => {
514
            from1 => $self->type_rule->{from1},
515
            from2 => $self->type_rule->{from2}
516
        },
517
    );
518
    $result;
cleanup
yuki-kimoto authored on 2010-10-17
519
}
520

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

            
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
536
sub get_column_info {
cleanup
Yuki Kimoto authored on 2011-10-21
537
    my ($self, %opt) = @_;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
538
    
cleanup
Yuki Kimoto authored on 2011-10-21
539
    my $exclude_table = delete $opt{exclude_table};
540
    croak qq/"$_" is wrong option/ for keys %opt;
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
541
    
542
    my $column_info = [];
543
    $self->each_column(
544
        sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } },
545
        exclude_table => $exclude_table
546
    );
547
    
548
    return [
549
      sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} }
cleanup
Yuki Kimoto authored on 2011-08-16
550
        @$column_info];
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
551
}
552

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
553
sub helper {
554
    my $self = shift;
555
    
556
    # Register method
557
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
558
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
559
    
560
    return $self;
561
}
562

            
cleanup
yuki-kimoto authored on 2010-10-17
563
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
564
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
565
    
cleanup
Yuki Kimoto authored on 2011-10-21
566
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
567
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
568
    my %opt = @_;
micro optimization
Yuki Kimoto authored on 2011-10-23
569
    warn "insert method param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
570
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
571
    
572
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
573
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
574
        my $columns = $insert_timestamp->[0];
575
        $columns = [$columns] unless ref $columns eq 'ARRAY';
576
        my $value = $insert_timestamp->[1];
577
        $value = $value->() if ref $value eq 'CODE';
578
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
579
    }
cleanup
Yuki Kimoto authored on 2011-10-21
580
    
581
    # Merge id to parameter
micro optimization
Yuki Kimoto authored on 2011-10-23
582
    if (defined $opt{id}) {
583
        croak "insert primary_key option must be specified with id option"
584
          unless $opt{primary_key};
585
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
586
        $opt{id} = [$opt{id}] unless ref $opt{id};
587
        for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
588
           my $key = $opt{primary_key}->[$i];
589
           croak "id already contain in parameter" if exists $param->{$key};
590
           $param->{$key} = $opt{id}->[$i];
591
        }
592
    }
cleanup
Yuki Kimoto authored on 2011-10-21
593
    
cleanup
Yuki Kimoto authored on 2011-04-02
594
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
595
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
596
    $sql .= "$opt{prefix} " if defined $opt{prefix};
597
    $sql .= "into " . $self->_q($opt{table}) . " "
598
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
micro optimization
Yuki Kimoto authored on 2011-10-23
599

            
600
    # Remove id from parameter
601
    if (defined $opt{id}) { delete $param->{$_} for @{$opt{primary_key}} }
packaging one directory
yuki-kimoto authored on 2009-11-16
602
    
603
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
604
    $opt{statement} = 'insert';
micro optimization
Yuki Kimoto authored on 2011-10-23
605
    $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
606
}
607

            
micro optimization
Yuki Kimoto authored on 2011-10-23
608
sub _merge_id_to_param {
609
    my ($self, $id, $primary_keys, $param) = @_;
610
    
611
    # Create parameter
612
    $id = [$id] unless ref $id;
613
    
614
    return $param;
615
}
616

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
617
sub insert_timestamp {
618
    my $self = shift;
619
    
620
    if (@_) {
621
        $self->{insert_timestamp} = [@_];
622
        
623
        return $self;
624
    }
625
    return $self->{insert_timestamp};
626
}
627

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
628
sub include_model {
629
    my ($self, $name_space, $model_infos) = @_;
630
    
cleanup
Yuki Kimoto authored on 2011-04-02
631
    # Name space
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
632
    $name_space ||= '';
cleanup
Yuki Kimoto authored on 2011-04-02
633
    
634
    # Get Model infomations
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
635
    unless ($model_infos) {
cleanup
Yuki Kimoto authored on 2011-04-02
636

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
637
        # Load name space module
cleanup
Yuki Kimoto authored on 2011-04-25
638
        croak qq{"$name_space" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
639
          if $name_space =~ /[^\w:]/;
640
        eval "use $name_space";
cleanup
Yuki Kimoto authored on 2011-04-25
641
        croak qq{Name space module "$name_space.pm" is needed. $@ }
642
            . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
643
          if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
644
        
645
        # Search model modules
646
        my $path = $INC{"$name_space.pm"};
647
        $path =~ s/\.pm$//;
648
        opendir my $dh, $path
cleanup
Yuki Kimoto authored on 2011-04-25
649
          or croak qq{Can't open directory "$path": $! } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
650
        $model_infos = [];
651
        while (my $module = readdir $dh) {
652
            push @$model_infos, $module
653
              if $module =~ s/\.pm$//;
654
        }
655
        close $dh;
656
    }
657
    
cleanup
Yuki Kimoto authored on 2011-04-02
658
    # Include models
cleanup
Yuki Kimoto authored on 2011-10-21
659
    for my $model_info (@$model_infos) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
660
        
cleanup
Yuki Kimoto authored on 2011-04-02
661
        # Load model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
662
        my $model_class;
663
        my $model_name;
664
        my $model_table;
665
        if (ref $model_info eq 'HASH') {
666
            $model_class = $model_info->{class};
667
            $model_name  = $model_info->{name};
668
            $model_table = $model_info->{table};
669
            
670
            $model_name  ||= $model_class;
671
            $model_table ||= $model_name;
672
        }
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
673
        else { $model_class = $model_name = $model_table = $model_info }
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
674
        my $mclass = "${name_space}::$model_class";
cleanup
Yuki Kimoto authored on 2011-04-25
675
        croak qq{"$mclass" is invalid class name } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
676
          if $mclass =~ /[^\w:]/;
677
        unless ($mclass->can('isa')) {
678
            eval "use $mclass";
cleanup
Yuki Kimoto authored on 2011-04-25
679
            croak "$@ " . _subname if $@;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
680
        }
681
        
cleanup
Yuki Kimoto authored on 2011-04-02
682
        # Create model
cleanup
Yuki Kimoto authored on 2011-10-21
683
        my $opt = {};
684
        $opt->{model_class} = $mclass if $mclass;
685
        $opt->{name}        = $model_name if $model_name;
686
        $opt->{table}       = $model_table if $model_table;
687
        $self->create_model($opt);
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
688
    }
689
    
690
    return $self;
691
}
692

            
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
693
sub like_value { sub { "%$_[0]%" } }
694

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
695
sub mapper {
696
    my $self = shift;
697
    return DBIx::Custom::Mapper->new(@_);
698
}
699

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

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
724
sub model {
725
    my ($self, $name, $model) = @_;
726
    
cleanup
Yuki Kimoto authored on 2011-04-02
727
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
728
    if ($model) {
729
        $self->models->{$name} = $model;
730
        return $self;
731
    }
732
    
733
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
734
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
735
      unless $self->models->{$name};
736
    
cleanup
Yuki Kimoto authored on 2011-04-02
737
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
738
    return $self->models->{$name};
739
}
740

            
cleanup
Yuki Kimoto authored on 2011-03-21
741
sub mycolumn {
742
    my ($self, $table, $columns) = @_;
743
    
cleanup
Yuki Kimoto authored on 2011-04-02
744
    # Create column clause
745
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
746
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
747
    push @column, $self->_q($table) . "." . $self->_q($_) .
748
      " as " . $self->_q($_)
749
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
750
    
751
    return join (', ', @column);
752
}
753

            
added dbi_options attribute
kimoto authored on 2010-12-20
754
sub new {
755
    my $self = shift->SUPER::new(@_);
756
    
cleanup
Yuki Kimoto authored on 2011-04-02
757
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
758
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
759
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
760
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
761
          unless $self->can($attr);
762
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
763

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
764
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
765
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
766
        '?'     => \&DBIx::Custom::Tag::placeholder,
767
        '='     => \&DBIx::Custom::Tag::equal,
768
        '<>'    => \&DBIx::Custom::Tag::not_equal,
769
        '>'     => \&DBIx::Custom::Tag::greater_than,
770
        '<'     => \&DBIx::Custom::Tag::lower_than,
771
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
772
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
773
        'like'  => \&DBIx::Custom::Tag::like,
774
        'in'    => \&DBIx::Custom::Tag::in,
775
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
776
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
777
    };
778
    
779
    return $self;
780
}
781

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

            
784
sub order {
785
    my $self = shift;
786
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
787
}
788

            
cleanup
yuki-kimoto authored on 2010-10-17
789
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
790
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
791
    
792
    # Register filter
793
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
794
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
795
    
cleanup
Yuki Kimoto authored on 2011-04-02
796
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
797
}
packaging one directory
yuki-kimoto authored on 2009-11-16
798

            
799
sub select {
cleanup
Yuki Kimoto authored on 2011-10-21
800
    my ($self, %opt) = @_;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
801

            
cleanup
Yuki Kimoto authored on 2011-10-21
802
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
803
    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
804
               : defined $opt{table} ? [$opt{table}]
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
805
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
806
    $opt{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
807
    my $where_param = $opt{where_param} || delete $opt{param} || {};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
808
    
cleanup
Yuki Kimoto authored on 2011-03-09
809
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
810
    if ($opt{relation}) {
811
        warn "select() relation option is DEPRECATED!";
812
        $self->_add_relation_table($tables, $opt{relation});
813
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
814
    
cleanup
Yuki Kimoto authored on 2011-04-02
815
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
816
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
817
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
818
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
819
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
820
    
cleanup
Yuki Kimoto authored on 2011-10-21
821
    # Column
cleanup
Yuki Kimoto authored on 2011-10-21
822
    if (defined $opt{column}) {
823
        my $columns
824
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
cleanup
Yuki Kimoto authored on 2011-10-21
825
        for my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
826
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
827
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
828
            }
829
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
830
                if (@$column == 3 && $column->[1] eq 'as') {
831
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
832
                    splice @$column, 1, 1;
833
                }
834
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
835
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
836
            }
cleanup
Yuki Kimoto authored on 2011-04-02
837
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
838
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
839
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
840
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
841
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
842
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
843
    
844
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
845
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
846
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
847
        my $found = {};
cleanup
Yuki Kimoto authored on 2011-10-21
848
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
849
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
850
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
851
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
852
    }
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
853
    else { $sql .= $self->_q($tables->[-1] || '') . ' ' }
micro optimization
Yuki Kimoto authored on 2011-09-30
854
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-10-21
855
    croak "select method table option must be specified " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
856
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
857

            
cleanup
Yuki Kimoto authored on 2011-04-02
858
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
859
    unshift @$tables,
860
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
861
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
862
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
863
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
864
              ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $tables->[-1])
cleanup
Yuki Kimoto authored on 2011-10-21
865
              : $opt{where};
866
    my $w = $self->_where_clause_and_param($where, $where_param);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
867
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
868
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
869
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
870
    
cleanup
Yuki Kimoto authored on 2011-10-21
871
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
872
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
873
    
cleanup
Yuki Kimoto authored on 2011-03-09
874
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
875
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
876
    
cleanup
Yuki Kimoto authored on 2011-03-08
877
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
878
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
879
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
880
    
packaging one directory
yuki-kimoto authored on 2009-11-16
881
    # Execute query
cleanup
Yuki Kimoto authored on 2011-10-21
882
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
883
    
micro optimization
Yuki Kimoto authored on 2011-10-23
884
    $result;
packaging one directory
yuki-kimoto authored on 2009-11-16
885
}
886

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
887
sub setup_model {
888
    my $self = shift;
889
    
cleanup
Yuki Kimoto authored on 2011-04-02
890
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
891
    $self->each_column(
892
        sub {
893
            my ($self, $table, $column, $column_info) = @_;
894
            if (my $model = $self->models->{$table}) {
895
                push @{$model->columns}, $column;
896
            }
897
        }
898
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
899
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
900
}
901

            
update pod
Yuki Kimoto authored on 2011-08-10
902
sub show_datatype {
903
    my ($self, $table) = @_;
904
    croak "Table name must be specified" unless defined $table;
905
    print "$table\n";
906
    
907
    my $result = $self->select(table => $table, where => "'0' <> '0'");
908
    my $sth = $result->sth;
909

            
910
    my $columns = $sth->{NAME};
911
    my $data_types = $sth->{TYPE};
912
    
913
    for (my $i = 0; $i < @$columns; $i++) {
914
        my $column = $columns->[$i];
915
        my $data_type = $data_types->[$i];
916
        print "$column: $data_type\n";
917
    }
918
}
919

            
920
sub show_typename {
921
    my ($self, $t) = @_;
922
    croak "Table name must be specified" unless defined $t;
923
    print "$t\n";
924
    
925
    $self->each_column(sub {
926
        my ($self, $table, $column, $infos) = @_;
927
        return unless $table eq $t;
928
        my $typename = $infos->{TYPE_NAME};
929
        print "$column: $typename\n";
930
    });
931
    
932
    return $self;
933
}
934

            
test cleanup
Yuki Kimoto authored on 2011-08-15
935
sub show_tables {
936
    my $self = shift;
937
    
938
    my %tables;
939
    $self->each_table(sub { $tables{$_[1]}++ });
940
    print join("\n", sort keys %tables) . "\n";
941
    return $self;
942
}
943

            
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
944
sub type_rule {
945
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-23
946

            
947
    $self->{_type_rule_is_called} = 1;
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
948
    
949
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
950
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
951
        
952
        # Into
cleanup
Yuki Kimoto authored on 2011-10-21
953
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
954
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
955
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
956
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
957
            $self->{type_rule} = $type_rule;
958
            $self->{"_$into"} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
959
            for my $type_name (keys %{$type_rule->{$into} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
960
                croak qq{type name of $into section must be lower case}
961
                  if $type_name =~ /[A-Z]/;
962
            }
cleanup
Yuki Kimoto authored on 2011-08-16
963
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
964
            $self->each_column(sub {
965
                my ($dbi, $table, $column, $column_info) = @_;
966
                
967
                my $type_name = lc $column_info->{TYPE_NAME};
968
                if ($type_rule->{$into} &&
969
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
970
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
971
                    return unless exists $type_rule->{$into}->{$type_name};
972
                    if  (defined $filter && ref $filter ne 'CODE') 
973
                    {
974
                        my $fname = $filter;
975
                        croak qq{Filter "$fname" is not registered" } . _subname
976
                          unless exists $self->filters->{$fname};
977
                        
978
                        $filter = $self->filters->{$fname};
979
                    }
980

            
micro optimization
Yuki Kimoto authored on 2011-07-30
981
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
982
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
983
                }
984
            });
985
        }
986

            
987
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
988
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
989
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
990
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
991
                croak qq{data type of from$i section must be lower case or number}
992
                  if $data_type =~ /[A-Z]/;
993
                my $fname = $type_rule->{"from$i"}{$data_type};
994
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
995
                    croak qq{Filter "$fname" is not registered" } . _subname
996
                      unless exists $self->filters->{$fname};
997
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
998
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
999
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1000
            }
1001
        }
1002
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1003
        return $self;
1004
    }
1005
    
1006
    return $self->{type_rule} || {};
1007
}
1008

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1012
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1013
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1014
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1015
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1016
    warn "update method where_param option is DEPRECATED!"
1017
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1018
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1019
    
cleanup
Yuki Kimoto authored on 2011-10-21
1020
    # Don't allow update all rows
1021
    croak qq{update method where option must be specified } . _subname
1022
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1023
    
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1024
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1025
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1026
        my $columns = $update_timestamp->[0];
1027
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1028
        my $value = $update_timestamp->[1];
1029
        $value = $value->() if ref $value eq 'CODE';
1030
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1031
    }
1032

            
cleanup
Yuki Kimoto authored on 2011-10-21
1033
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1034
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1035
    
1036
    # Convert id to where parameter
1037
    my $where = defined $opt{id}
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1038
      ? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table})
cleanup
Yuki Kimoto authored on 2011-10-21
1039
      : $opt{where};
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1040

            
1041
    # Where
cleanup
Yuki Kimoto authored on 2011-10-21
1042
    my $w = $self->_where_clause_and_param($where, $opt{where_param});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1043
    
cleanup
Yuki Kimoto authored on 2011-10-21
1044
    # Merge where parameter to parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1045
    $param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}};
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
1046
    
cleanup
Yuki Kimoto authored on 2011-04-02
1047
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1048
    my $sql = "update ";
1049
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
1050
    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1051
    
cleanup
yuki-kimoto authored on 2010-10-17
1052
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
1053
    $self->execute($sql, $param, %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1054
}
1055

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1058
sub update_or_insert {
1059
    my $self = shift;
1060

            
cleanup
Yuki Kimoto authored on 2011-10-21
1061
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1062
    my $param  = shift;
1063
    my %opt = @_;
1064
    my $id = $opt{id};
1065
    my $primary_key = $opt{primary_key};
1066
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1067
    croak "update_or_insert method need primary_key option " .
1068
          "when id is specified" . _subname
1069
      if defined $id && !defined $primary_key;
1070
    my $table  = $opt{table};
1071
    croak qq{"table" option must be specified } . _subname
1072
      unless defined $table;
1073
    my $select_option = $opt{select_option};
1074
    
1075
    my $rows = $self->select(table => $table, id => $id,
1076
        primary_key => $primary_key, %$select_option)->all;
1077
    
1078
    croak "selected row count must be one or zero" . _subname
1079
      if @$rows > 1;
1080
    
1081
    my $row = $rows->[0];
1082
    my @opt = (table => $table);
1083
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1084
    push @opt, %opt;
1085
    
1086
    if ($row) {
1087
        return $self->update($param, @opt);
1088
    }
1089
    else {
1090
        return $self->insert($param, @opt);
1091
    }
1092
}
1093

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1094
sub update_timestamp {
1095
    my $self = shift;
1096
    
1097
    if (@_) {
1098
        $self->{update_timestamp} = [@_];
1099
        
1100
        return $self;
1101
    }
1102
    return $self->{update_timestamp};
1103
}
1104

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1105
sub values_clause {
1106
    my ($self, $param, $opts) = @_;
1107
    
1108
    my $wrap = $opts->{wrap} || {};
1109
    
1110
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-10-23
1111
    my $safety = $self->{safety_character} || $self->safety_character;
improved performance
Yuki Kimoto authored on 2011-10-22
1112
    my $qp = $self->_q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1113
    my $q = substr($qp, 0, 1) || '';
1114
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1115
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1116
    # Check unsafety keys
1117
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
1118
        for my $column (keys %$param) {
1119
            croak qq{"$column" is not safety column name } . _subname
1120
              unless $column =~ /^[$safety\.]+$/;
1121
        }
1122
    }
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1123
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1124
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1125
    '(' .
1126
    join(
1127
      ', ',
1128
      map { "$q$_$p" } sort keys %$param
1129
    ) .
1130
    ') values (' .
1131
    join(
1132
      ', ',
1133
      map {
1134
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1135
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1136
          ":$_";
1137
      } sort keys %$param
1138
    ) .
1139
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1140
}
1141

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1275
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1276
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1277
    
1278
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1279
    croak "primary_key option " .
1280
          "must be specified with id option " . _subname
1281
      unless defined $primary_keys;
1282
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1283
    
cleanup
Yuki Kimoto authored on 2011-06-08
1284
    # Create parameter
1285
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1286
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1287
        $id = [$id] unless ref $id;
1288
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1289
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1290
          unless !ref $id || ref $id eq 'ARRAY';
1291
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1292
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1293
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1294
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1295
           my $key = $primary_keys->[$i];
1296
           $key = "$table." . $key if $table;
1297
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1298
        }
1299
    }
1300
    
cleanup
Yuki Kimoto authored on 2011-06-08
1301
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1302
}
1303

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1304
sub _connect {
1305
    my $self = shift;
1306
    
1307
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1308
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1309
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1310
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1311
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1312
    croak qq{"dsn" must be specified } . _subname
1313
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1314
    my $user        = $self->user;
1315
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1316
    my $option = $self->_option;
1317
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1318
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1319
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1320
    my $dbh;
1321
    eval {
1322
        $dbh = DBI->connect(
1323
            $dsn,
1324
            $user,
1325
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1326
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1327
        );
1328
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1329
    
1330
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1331
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1332
    
1333
    return $dbh;
1334
}
1335

            
cleanup
yuki-kimoto authored on 2010-10-17
1336
sub _croak {
1337
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1338
    
1339
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1340
    $append ||= "";
1341
    
1342
    # Verbose
1343
    if ($Carp::Verbose) { croak $error }
1344
    
1345
    # Not verbose
1346
    else {
1347
        
1348
        # Remove line and module infromation
1349
        my $at_pos = rindex($error, ' at ');
1350
        $error = substr($error, 0, $at_pos);
1351
        $error =~ s/\s+$//;
1352
        croak "$error$append";
1353
    }
1354
}
1355

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1358
sub _need_tables {
1359
    my ($self, $tree, $need_tables, $tables) = @_;
1360
    
cleanup
Yuki Kimoto authored on 2011-04-02
1361
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1362
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1363
        if ($tree->{$table}) {
1364
            $need_tables->{$table} = 1;
1365
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1366
        }
1367
    }
1368
}
1369

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1370
sub _option {
1371
    my $self = shift;
1372
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1373
    warn "dbi_options is DEPRECATED! use option instead\n"
1374
      if keys %{$self->dbi_options};
1375
    warn "dbi_option is DEPRECATED! use option instead\n"
1376
      if keys %{$self->dbi_option};
1377
    return $option;
1378
}
1379

            
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1380
sub _push_join {
1381
    my ($self, $sql, $join, $join_tables) = @_;
1382
    
cleanup
Yuki Kimoto authored on 2011-10-21
1383
    $join = [$join] unless ref $join eq 'ARRAY';
cleanup
Yuki Kimoto authored on 2011-10-21
1384
    
cleanup
Yuki Kimoto authored on 2011-04-02
1385
    # No join
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1386
    return unless @$join;
1387
    
cleanup
Yuki Kimoto authored on 2011-04-02
1388
    # Push join clause
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1389
    my $tree = {};
1390
    for (my $i = 0; $i < @$join; $i++) {
1391
        
cleanup
Yuki Kimoto authored on 2011-07-28
1392
        # Arrange
added join new syntax
Yuki Kimoto authored on 2011-07-28
1393
        my $join_clause;;
1394
        my $option;
1395
        if (ref $join->[$i] eq 'HASH') {
1396
            $join_clause = $join->[$i]->{clause};
1397
            $option = {table => $join->[$i]->{table}};
1398
        }
1399
        else {
1400
            $join_clause = $join->[$i];
1401
            $option = {};
1402
        };
cleanup
Yuki Kimoto authored on 2011-07-28
1403

            
1404
        # Find tables in join clause
added join new syntax
Yuki Kimoto authored on 2011-07-28
1405
        my $table1;
1406
        my $table2;
1407
        if (my $table = $option->{table}) {
1408
            $table1 = $table->[0];
1409
            $table2 = $table->[1];
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1410
        }
cleanup
Yuki Kimoto authored on 2011-07-28
1411
        else {
1412
            my $q = $self->_quote;
1413
            my $j_clause = (split /\s+on\s+/, $join_clause)[-1];
1414
            $j_clause =~ s/'.+?'//g;
1415
            my $q_re = quotemeta($q);
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1416
            $j_clause =~ s/[$q_re]//g;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1417
            
1418
            my @j_clauses = reverse split /\s(and|on)\s/, $j_clause;
cleanup
Yuki Kimoto authored on 2011-07-28
1419
            my $c = $self->safety_character;
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1420
            my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm;
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
1421
            for my $clause (@j_clauses) {
1422
                if ($clause =~ $join_re) {
1423
                    $table1 = $1;
1424
                    $table2 = $2;
1425
                    last;
1426
                }                
cleanup
Yuki Kimoto authored on 2011-07-28
1427
            }
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1428
        }
added join new syntax
Yuki Kimoto authored on 2011-07-28
1429
        croak qq{join clause must have two table name after "on" keyword. } .
1430
              qq{"$join_clause" is passed }  . _subname
1431
          unless defined $table1 && defined $table2;
1432
        croak qq{right side table of "$join_clause" must be unique }
1433
            . _subname
1434
          if exists $tree->{$table2};
1435
        croak qq{Same table "$table1" is specified} . _subname
1436
          if $table1 eq $table2;
1437
        $tree->{$table2}
1438
          = {position => $i, parent => $table1, join => $join_clause};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1439
    }
1440
    
cleanup
Yuki Kimoto authored on 2011-04-02
1441
    # Search need tables
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1442
    my $need_tables = {};
1443
    $self->_need_tables($tree, $need_tables, $join_tables);
cleanup
Yuki Kimoto authored on 2011-10-21
1444
    my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} }
1445
      keys %$need_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1446
    
1447
    # Add join clause
cleanup
Yuki Kimoto authored on 2011-10-21
1448
    $$sql .= $tree->{$_}{join} . ' ' for @need_tables;
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
1449
}
cleanup
Yuki Kimoto authored on 2011-03-08
1450

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1451
sub _quote {
1452
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1453
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1454
}
1455

            
cleanup
Yuki Kimoto authored on 2011-07-29
1456
sub _q {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1457
    my ($self, $value, $quotemeta) = @_;
cleanup
Yuki Kimoto authored on 2011-07-29
1458
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1459
    my $quote = $self->{reserved_word_quote}
1460
      || $self->{quote} || $self->quote || '';
1461
    return "$quote$value$quote"
1462
      if !$quotemeta && ($quote eq '`' || $quote eq '"');
1463
    
cleanup
Yuki Kimoto authored on 2011-07-29
1464
    my $q = substr($quote, 0, 1) || '';
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1465
    my $p;
1466
    if (defined $quote && length $quote > 1) {
1467
        $p = substr($quote, 1, 1);
1468
    }
1469
    else { $p = $q }
cleanup
Yuki Kimoto authored on 2011-07-29
1470
    
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1471
    if ($quotemeta) {
1472
        $q = quotemeta($q);
1473
        $p = quotemeta($p);
1474
    }
1475
    
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
1476
    return "$q$value$p";
cleanup
Yuki Kimoto authored on 2011-07-29
1477
}
1478

            
cleanup
Yuki Kimoto authored on 2011-04-02
1479
sub _remove_duplicate_table {
1480
    my ($self, $tables, $main_table) = @_;
1481
    
1482
    # Remove duplicate table
1483
    my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables;
1484
    delete $tables{$main_table} if $main_table;
1485
    
micro optimization
Yuki Kimoto authored on 2011-07-30
1486
    my $new_tables = [keys %tables, $main_table ? $main_table : ()];
1487
    if (my $q = $self->_quote) {
1488
        $q = quotemeta($q);
1489
        $_ =~ s/[$q]//g for @$new_tables;
1490
    }
1491

            
1492
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1493
}
1494

            
cleanup
Yuki Kimoto authored on 2011-04-02
1495
sub _search_tables {
cleanup
Yuki Kimoto authored on 2011-04-02
1496
    my ($self, $source) = @_;
1497
    
cleanup
Yuki Kimoto authored on 2011-04-02
1498
    # Search tables
cleanup
Yuki Kimoto authored on 2011-04-02
1499
    my $tables = [];
1500
    my $safety_character = $self->safety_character;
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1501
    my $q = $self->_quote;
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1502
    my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1);
1503
    my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./
improved table search in col...
Yuki Kimoto authored on 2011-04-12
1504
                      : qr/(?:^|[^$safety_character])([$safety_character]+)\./;
cleanup
Yuki Kimoto authored on 2011-04-02
1505
    while ($source =~ /$table_re/g) {
1506
        push @$tables, $1;
1507
    }
1508
    
1509
    return $tables;
1510
}
1511

            
cleanup
Yuki Kimoto authored on 2011-04-02
1512
sub _where_to_obj {
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1513
    my ($self, $where) = @_;
1514
    
cleanup
Yuki Kimoto authored on 2011-04-02
1515
    my $obj;
1516
    
1517
    # Hash
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1518
    if (ref $where eq 'HASH') {
1519
        my $clause = ['and'];
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1520
        my $q = $self->_quote;
cleanup
Yuki Kimoto authored on 2011-10-21
1521
        for my $column (keys %$where) {
fixex [] reserved_word_quote...
Yuki Kimoto authored on 2011-08-14
1522
            my $table;
1523
            my $c;
1524
            if ($column =~ /(?:(.*?)\.)?(.*)/) {
1525
                $table = $1;
1526
                $c = $2;
1527
            }
1528
            
1529
            my $table_quote;
1530
            $table_quote = $self->_q($table) if defined $table;
1531
            my $column_quote = $self->_q($c);
1532
            $column_quote = $table_quote . '.' . $column_quote
1533
              if defined $table_quote;
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1534
            push @$clause, "$column_quote = :$column" for keys %$where;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
1535
        }
cleanup
Yuki Kimoto authored on 2011-04-02
1536
        $obj = $self->where(clause => $clause, param => $where);
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1537
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1538
    
1539
    # DBIx::Custom::Where object
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1540
    elsif (ref $where eq 'DBIx::Custom::Where') {
cleanup
Yuki Kimoto authored on 2011-04-02
1541
        $obj = $where;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1542
    }
cleanup
Yuki Kimoto authored on 2011-04-02
1543
    
updated pod
Yuki Kimoto authored on 2011-06-21
1544
    # Array
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1545
    elsif (ref $where eq 'ARRAY') {
cleanup
Yuki Kimoto authored on 2011-04-02
1546
        $obj = $self->where(
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1547
            clause => $where->[0],
1548
            param  => $where->[1]
1549
        );
1550
    }
1551
    
cleanup
Yuki Kimoto authored on 2011-04-02
1552
    # Check where argument
improved error messages
Yuki Kimoto authored on 2011-04-18
1553
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
DBIx::Custom::Model type att...
Yuki Kimoto authored on 2011-06-17
1554
        . qq{or array reference, which contains where clause and parameter}
cleanup
Yuki Kimoto authored on 2011-04-25
1555
        . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
1556
      unless ref $obj eq 'DBIx::Custom::Where';
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1557
    
cleanup
Yuki Kimoto authored on 2011-04-02
1558
    return $obj;
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
1559
}
1560

            
cleanup
Yuki Kimoto authored on 2011-10-21
1561
sub _where_clause_and_param {
1562
    my ($self, $where, $param) = @_;
1563
 
1564
    $where ||= {};
1565
    $param ||= {};
1566
    my $w = {};
1567
    my $where_clause = '';
1568
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1569
        $w->{clause} = "where " . $where->[0];
1570
        $w->{param} = $where->[1];
1571
    }
1572
    elsif (ref $where) {
1573
        $where = $self->_where_to_obj($where);
1574
        $w->{param} = keys %$param
1575
                    ? $self->merge_param($param, $where->param)
1576
                    : $where->param;
1577
        $w->{clause} = $where->to_string;
1578
    }
1579
    elsif ($where) {
1580
        $w->{clause} = "where $where";
1581
        $w->{param} = $param;
1582
    }
1583
    
1584
    return $w;
1585
}
1586

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1657
# DEPRECATED!
1658
has 'data_source';
1659
has dbi_options => sub { {} };
1660
has filter_check  => 1;
1661
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1662
has dbi_option => sub { {} };
1663
has default_dbi_option => sub {
1664
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1665
    return shift->default_option;
1666
};
1667

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1668
# DEPRECATED!
1669
sub method {
1670
    warn "method is DEPRECATED! use helper instead";
1671
    return shift->helper(@_);
1672
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1673

            
1674
# DEPRECATED!
1675
sub assign_param {
1676
    my $self = shift;
1677
    warn "assing_param is DEPRECATED! use assign_clause instead";
1678
    return $self->assign_clause(@_);
1679
}
1680

            
1681
# DEPRECATED
1682
sub update_param {
1683
    my ($self, $param, $opts) = @_;
1684
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1685
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1686
    
1687
    # Create update parameter tag
1688
    my $tag = $self->assign_clause($param, $opts);
1689
    $tag = "set $tag" unless $opts->{no_set};
1690

            
1691
    return $tag;
1692
}
1693

            
updated pod
Yuki Kimoto authored on 2011-06-21
1694
# DEPRECATED!
1695
sub create_query {
1696
    warn "create_query is DEPRECATED! use query option of each method";
1697
    shift->_create_query(@_);
1698
}
1699

            
cleanup
Yuki Kimoto authored on 2011-06-13
1700
# DEPRECATED!
1701
sub apply_filter {
1702
    my $self = shift;
1703
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1704
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1705
    return $self->_apply_filter(@_);
1706
}
1707

            
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1708
# DEPRECATED!
1709
sub select_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1710
    my ($self, %opt) = @_;
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1711

            
cleanup
Yuki Kimoto authored on 2011-10-21
1712
    warn "select_at is DEPRECATED! use select method id option instead";
updated pod
Yuki Kimoto authored on 2011-06-08
1713

            
cleanup
Yuki Kimoto authored on 2011-10-21
1714
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1715
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1716
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1717
    my $where = delete $opt{where};
1718
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1719
    
1720
    # Table
1721
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1722
      unless $opt{table};
1723
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1724
    
1725
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1726
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1727
    
cleanup
Yuki Kimoto authored on 2011-10-21
1728
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1729
}
1730

            
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1731
# DEPRECATED!
1732
sub delete_at {
cleanup
Yuki Kimoto authored on 2011-10-21
1733
    my ($self, %opt) = @_;
updated pod
Yuki Kimoto authored on 2011-06-08
1734

            
cleanup
Yuki Kimoto authored on 2011-10-21
1735
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1736
    
cleanup
Yuki Kimoto authored on 2011-10-21
1737
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1738
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1739
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1740
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1741
    
1742
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1743
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1744
    
cleanup
Yuki Kimoto authored on 2011-10-21
1745
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1746
}
1747

            
cleanup
Yuki Kimoto authored on 2011-06-08
1748
# DEPRECATED!
1749
sub update_at {
1750
    my $self = shift;
1751

            
cleanup
Yuki Kimoto authored on 2011-10-21
1752
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1753
    
cleanup
Yuki Kimoto authored on 2011-10-21
1754
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1755
    my $param;
1756
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1757
    my %opt = @_;
1758
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1759
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1760
    my $where = delete $opt{where};
1761
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1762
    $param  ||= $p;
1763
    
1764
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1765
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1766
    
cleanup
Yuki Kimoto authored on 2011-10-21
1767
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1768
}
1769

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1770
# DEPRECATED!
1771
sub insert_at {
1772
    my $self = shift;
1773
    
cleanup
Yuki Kimoto authored on 2011-10-21
1774
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1775
    
cleanup
Yuki Kimoto authored on 2011-10-21
1776
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1777
    my $param;
1778
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1779
    my %opt = @_;
1780
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1781
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1782
    my $where = delete $opt{where};
1783
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1784
    $param  ||= $p;
1785
    
1786
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1787
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1788
    $param = $self->merge_param($where_param, $param);
1789
    
cleanup
Yuki Kimoto authored on 2011-10-21
1790
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1791
}
1792

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

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

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

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

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1865
# DEPRECATED!
1866
sub insert_param {
1867
    my $self = shift;
1868
    warn "insert_param is DEPRECATED! use values_clause instead";
1869
    return $self->values_clause(@_);
1870
}
1871

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1923
=head1 NAME
1924

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
1925
DBIx::Custom - DBI extension to execute insert, update, delete, and select easily
removed reconnect method
yuki-kimoto authored on 2010-05-28
1926

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-29
1994
Create C<where> clause flexibly
- 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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1998
Named place holder support
1999

            
2000
=item *
2001

            
cleanup
Yuki Kimoto authored on 2011-07-29
2002
Model support
2003

            
2004
=item *
2005

            
2006
Connection manager support
2007

            
2008
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2009

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

            
2014
=item *
2015

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2016
Filtering by data type or column name
cleanup
Yuki Kimoto authored on 2011-07-29
2017

            
2018
=item *
2019

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2020
Create C<order by> clause flexibly
cleanup
Yuki Kimoto authored on 2011-07-29
2021

            
2022
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2023

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

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

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

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

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

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

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

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

            
2048
This is L<DBIx::Connector> example. Please pass
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2049
C<default_option> to L<DBIx::Connector> C<new> method.
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2050

            
2051
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2052
        "dbi:mysql:database=$database",
2053
        $user,
2054
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2055
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2056
    );
2057
    
updated pod
Yuki Kimoto authored on 2011-06-21
2058
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2059

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

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

            
2068
Note that L<DBIx::Connector> must be installed.
2069

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

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

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

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2077
=head2 C<default_option>
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2078

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2079
    my $default_option = $dbi->default_option;
2080
    $dbi = $dbi->default_option($default_option);
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
2081

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2091
=head2 C<exclude_table>
2092

            
2093
    my $exclude_table = $dbi->exclude_table;
2094
    $dbi = $dbi->exclude_table(qr/pg_/);
2095

            
2096
Excluded table regex.
2097
C<each_column>, C<each_table>, C<type_rule>,
2098
and C<setup_model> methods ignore matching tables.
2099

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

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

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

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

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

            
2112
Get last successed SQL executed by C<execute> method.
2113

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2121
=head2 C<option>
2122

            
2123
    my $option = $dbi->option;
2124
    $dbi = $dbi->option($option);
2125

            
2126
L<DBI> option, used when C<connect> method is executed.
2127
Each value in option override the value of C<default_option>.
2128

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2164
    my $safety_character = $dbi->safety_character;
2165
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2166

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2172
    my $separator = $dbi->separator;
2173
    $dbi = $dbi->separator('-');
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2174

            
2175
Separator which join table name and column name.
2176
This have effect to C<column> and C<mycolumn> method,
2177
and C<select> method's column option.
cleanup test
Yuki Kimoto authored on 2011-08-10
2178

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-27
2179
Default to C<.>.
cleanup test
Yuki Kimoto authored on 2011-08-10
2180

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

            
2183
    my $tag_parse = $dbi->tag_parse(0);
2184
    $dbi = $dbi->tag_parse;
2185

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

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2196
=head2 C<user_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2197

            
2198
    my $user_column_info = $dbi->user_column_info;
2199
    $dbi = $dbi->user_column_info($user_column_info);
2200

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2201
You can set the date like the following one.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2202

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

            
improved join clause parsing
Yuki Kimoto authored on 2011-09-30
2208
Usually, you set return value of C<get_column_info>.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2209

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

            
2214
If C<user_column_info> is set, C<each_column> use C<user_column_info>
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2215
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2216

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2217
=head2 C<user_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2218

            
2219
    my $user_table_info = $dbi->user_table_info;
2220
    $dbi = $dbi->user_table_info($user_table_info);
2221

            
2222
You can set the following data.
2223

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

            
2229
Usually, you can set return value of C<get_table_info>.
2230

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

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2243
=head2 C<available_datatype>
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
2244

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2250
=head2 C<available_typename>
added EXPERIMENTAL available...
Yuki Kimoto authored on 2011-06-14
2251

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2257
=head2 C<assign_clause>
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2258

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2259
    my $assign_clause = $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2260

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2261
Create assign clause
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2262

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
2265
This is used to create update clause.
2266

            
2267
    "update book set " . $dbi->assign_clause({title => 'a', age => 2});
added EXPERIMENTAL assign_ta...
Yuki Kimoto authored on 2011-04-26
2268

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

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

            
2273
Create column clause. The follwoing column clause is created.
2274

            
2275
    book.author as "book.author",
2276
    book.title as "book.title"
2277

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

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

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

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2301
=head2 C<count>
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2302

            
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
2303
    my $count = $dbi->count(table => 'book');
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
2304

            
2305
Get rows count.
2306

            
2307
Options is same as C<select> method's ones.
2308

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

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

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

            
2322
   $dbi->model('book')->select(...);
2323

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

            
2326
    my $dbh = $dbi->dbh;
2327

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

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

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

            
2335
Execute delete statement.
2336

            
2337
The following opitons are available.
2338

            
cleanup
Yuki Kimoto authored on 2011-10-20
2339
B<OPTIONS>
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2340

            
cleanup
Yuki Kimoto authored on 2011-10-20
2341
C<delete> method use all of C<execute> method's options,
2342
and use the following new ones.
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2343

            
cleanup
Yuki Kimoto authored on 2011-10-20
2344
=over 4
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2345

            
2346
=item C<id>
2347

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

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

            
2354
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2355
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2356
        id => [4, 5],
2357
        table => 'book',
2358
    );
2359

            
2360
The above is same as the followin one.
2361

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

            
2364
=item C<prefix>
2365

            
2366
    prefix => 'some'
2367

            
2368
prefix before table name section.
2369

            
2370
    delete some from book
2371

            
2372
=item C<table>
2373

            
2374
    table => 'book'
2375

            
2376
Table name.
2377

            
2378
=item C<where>
2379

            
2380
Same as C<select> method's C<where> option.
2381

            
2382
=back
2383

            
2384
=head2 C<delete_all>
2385

            
2386
    $dbi->delete_all(table => $table);
2387

            
2388
Execute delete statement for all rows.
2389
Options is same as C<delete>.
2390

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

            
2393
    $dbi->each_column(
2394
        sub {
2395
            my ($dbi, $table, $column, $column_info) = @_;
2396
            
2397
            my $type = $column_info->{TYPE_NAME};
2398
            
2399
            if ($type eq 'DATE') {
2400
                # ...
2401
            }
2402
        }
2403
    );
2404

            
improved pod
Yuki Kimoto authored on 2011-10-14
2405
Iterate all column informations in database.
2406
Argument is callback which is executed when one column is found.
2407
Callback receive four arguments. C<DBIx::Custom object>, C<table name>,
2408
C<column name>, and C<column information>.
2409

            
2410
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2411
infromation, you can improve the performance of C<each_column> in
2412
the following way.
2413

            
2414
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
2415
    $dbi->user_column_info($column_info);
2416
    $dbi->each_column(sub { ... });
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
2417

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

            
2420
    $dbi->each_table(
2421
        sub {
2422
            my ($dbi, $table, $table_info) = @_;
2423
            
2424
            my $table_name = $table_info->{TABLE_NAME};
2425
        }
2426
    );
2427

            
improved pod
Yuki Kimoto authored on 2011-10-14
2428
Iterate all table informationsfrom in database.
2429
Argument is callback which is executed when one table is found.
2430
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2431
C<table information>.
2432

            
2433
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2434
infromation, you can improve the performance of C<each_table> in
2435
the following way.
2436

            
2437
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
2438
    $dbi->user_table_info($table_info);
2439
    $dbi->each_table(sub { ... });
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
2440

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

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

            
2448
    my $result = $dbi->execute(
2449
      "select * from book where title = :book.title and author like :book.author",
2450
      {'book.title' => 'Perl', 'book.author' => '%Ken%'}
update pod
Yuki Kimoto authored on 2011-03-13
2451
    );
2452

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

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2459
Named placeholder such as C<:title> is replaced by placeholder C<?>.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2460
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2461
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2462
    select * from book where title = :title and author like :author
2463
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2464
    # Replaced
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2465
    select * from where title = ? and author like ?;
update pod
Yuki Kimoto authored on 2011-03-13
2466

            
I call :title named placehol...
Yuki Kimoto authored on 2011-07-30
2467
You can specify operator with named placeholder
fixed pod
Yuki Kimoto authored on 2011-10-20
2468
by C<name{operator}> syntax.
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2469

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2470
    # Original
added EXPERIMENTAL parameter...
Yuki Kimoto authored on 2011-07-29
2471
    select * from book where :title{=} and :author{like}
2472
    
micro optimization
Yuki Kimoto authored on 2011-07-30
2473
    # Replaced
update pod
Yuki Kimoto authored on 2011-03-13
2474
    select * from where title = ? and author like ?;
2475

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

            
2480
    select * from where title = "aa\\:bb";
2481

            
cleanup
Yuki Kimoto authored on 2011-10-20
2482
B<OPTIONS>
2483

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

            
2486
=over 4
2487

            
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2488
=item C<after_build_sql> 
2489

            
2490
You can filter sql after the sql is build.
2491

            
2492
    after_build_sql => $code_ref
2493

            
2494
The following one is one example.
2495

            
2496
    $dbi->select(
2497
        table => 'book',
2498
        column => 'distinct(name)',
2499
        after_build_sql => sub {
2500
            "select count(*) from ($_[0]) as t1"
2501
        }
2502
    );
2503

            
2504
The following SQL is executed.
2505

            
2506
    select count(*) from (select distinct(name) from book) as t1;
2507

            
cleanup
Yuki Kimoto authored on 2011-10-20
2508
=item C<append>
2509

            
2510
    append => 'order by name'
2511

            
2512
Append some statement after SQL.
2513

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

            
2516
Specify database bind data type.
2517

            
2518
    bind_type => [image => DBI::SQL_BLOB]
2519
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2520

            
2521
This is used to bind parameter by C<bind_param> of statment handle.
2522

            
2523
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2524

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

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

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

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

            
2550
    id => 4
2551
    id => [4, 5]
2552

            
2553
ID corresponding to C<primary_key>.
2554
You can delete rows by C<id> and C<primary_key>.
2555

            
2556
    $dbi->execute(
2557
        "select * from book where id1 = :id1 and id2 = :id2",
2558
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2559
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2560
        id => [4, 5],
2561
    );
2562

            
2563
The above is same as the followin one.
2564

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

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

            
2572
    query => 1
2573

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

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

            
2583
    my $query;
cleanup
Yuki Kimoto authored on 2011-10-21
2584
    for my $row (@$rows) {
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2585
      $query ||= $dbi->insert($row, table => 'table1', query => 1);
cleanup
Yuki Kimoto authored on 2011-10-20
2586
      $dbi->execute($query, $row);
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2587
    }
2588

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2609
    primary_key => 'id'
2610
    primary_key => ['id1', 'id2']
2611

            
2612
Priamry key. This is used when C<id> option find primary key.
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2613

            
updated pod
Yuki Kimoto authored on 2011-06-09
2614
=item C<table>
2615
    
2616
    table => 'author'
2617

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

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
2625
    # Same
2626
    $dbi->execute(
2627
      "select * from book where title = :book.title and author = :book.author",
2628
      {title => 'Perl', author => 'Ken');
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2629

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2630
=item C<table_alias>
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2631

            
cleanup
Yuki Kimoto authored on 2011-10-20
2632
    table_alias => {user => 'worker'}
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-06-27
2633

            
2634
Table alias. Key is real table name, value is alias table name.
2635
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule
2636
on alias table name.
2637

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2638
=item C<reuse EXPERIMENTAL>
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2639
    
micro optimization
Yuki Kimoto authored on 2011-10-23
2640
    reuse => $has_ref
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2641

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2642
Reuse query object if the hash reference variable is set.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2643
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2644
    my $queries = {};
2645
    $dbi->execute($sql, $param, reuse => $queries);
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2646

            
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
2647
This will improved performance when you want to execute same query repeatedly
2648
because generally creating query object is slow.
added EXPERIMENTAL reuse_sth...
Yuki Kimoto authored on 2011-10-22
2649

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

            
2652
    type_rule_off => 1
2653

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2656
=item C<type_rule1_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2657

            
2658
    type_rule1_off => 1
2659

            
2660
Turn C<into1> type rule off.
2661

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2662
=item C<type_rule2_off>
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
2663

            
2664
    type_rule2_off => 1
2665

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2670
=head2 C<get_column_info>
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2671

            
improved pod
Yuki Kimoto authored on 2011-10-14
2672
    my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/);
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2673

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

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

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2681
=head2 C<get_table_info>
added test
Yuki Kimoto authored on 2011-08-16
2682

            
improved pod
Yuki Kimoto authored on 2011-10-14
2683
    my $table_infos = $dbi->get_table_info(exclude => qr/^system_/);
update pod
Yuki Kimoto authored on 2011-03-13
2684

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

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

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2694
=head2 C<helper>
2695

            
2696
    $dbi->helper(
2697
        update_or_insert => sub {
2698
            my $self = shift;
2699
            
2700
            # Process
2701
        },
2702
        find_or_create   => sub {
2703
            my $self = shift;
2704
            
2705
            # Process
2706
        }
2707
    );
2708

            
2709
Register helper. These helper is called directly from L<DBIx::Custom> object.
2710

            
2711
    $dbi->update_or_insert;
2712
    $dbi->find_or_create;
2713

            
cleanup
yuki-kimoto authored on 2010-10-17
2714
=head2 C<insert>
2715

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

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

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

            
2724
    {date => \"NOW()"}
2725

            
cleanup
Yuki Kimoto authored on 2011-10-20
2726
B<options>
2727

            
cleanup
Yuki Kimoto authored on 2011-10-20
2728
C<insert> method use all of C<execute> method's options,
cleanup
Yuki Kimoto authored on 2011-10-20
2729
and use the following new ones.
update pod
Yuki Kimoto authored on 2011-03-13
2730

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
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'}
fixed pod
Yuki Kimoto authored on 2011-10-20
2743
        primary_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

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

            
2765
    table => 'book'
2766

            
2767
Table name.
2768

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2769
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
2770

            
2771
    timestamp => 1
2772

            
2773
If this value is set to 1,
2774
automatically created timestamp column is set based on
2775
C<timestamp> attribute's C<insert> value.
2776

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2777
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
2778

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

            
2781
placeholder wrapped string.
2782

            
2783
If the following statement
2784

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

            
2788
is executed, the following SQL is executed.
2789

            
2790
    insert into book price values ( ? + 5 );
2791

            
update pod
Yuki Kimoto authored on 2011-03-13
2792
=back
2793

            
2794
=over 4
2795

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2841
=head2 C<insert_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2842

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
2843
    $dbi->insert_timestamp(
2844
      [qw/created_at updated_at/]
2845
        => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
2846
    );
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2847

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2848
Timestamp value when C<insert> method is executed
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
2849
with C<timestamp> option.
2850

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
2851
If C<insert_timestamp> is set and C<insert> method is executed
2852
with C<timestamp> option, column C<created_at> and C<update_at>
2853
is automatically set to the value like "2010-10-11 10:12:54".
2854

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
2855
    $dbi->insert($param, table => 'book', timestamp => 1);
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2856

            
cleanup
Yuki Kimoto authored on 2011-10-20
2857
=head2 C<like_value>
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2858

            
2859
    my $like_value = $dbi->like_value
2860

            
cleanup
Yuki Kimoto authored on 2011-10-20
2861
Code reference which return a value for the like value.
added EXPERIMENTAL like_valu...
Yuki Kimoto authored on 2011-09-16
2862

            
2863
    sub { "%$_[0]%" }
2864

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
2865
=head2 C<mapper>
- added EXPERIMENTAL pass at...
Yuki Kimoto authored on 2011-09-02
2866

            
2867
    my $mapper = $dbi->mapper(param => $param);
2868

            
2869
Create a new L<DBIx::Custom::Mapper> object.
2870

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2875
Merge parameters. The following new parameter is created.
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
2876

            
2877
    {key1 => [1, 1], key2 => 2}
2878

            
cleanup
Yuki Kimoto authored on 2011-10-20
2879
If same keys contains, the value is converted to array reference.
2880

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

            
2883
    my $model = $dbi->model('book');
2884

            
cleanup
Yuki Kimoto authored on 2011-10-20
2885
Get a L<DBIx::Custom::Model> object
2886
create by C<create_model> or C<include_model>
update pod
Yuki Kimoto authored on 2011-03-13
2887

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2890
    my $column = $dbi->mycolumn(book => ['author', 'title']);
cleanup
Yuki Kimoto authored on 2011-03-21
2891

            
2892
Create column clause for myself. The follwoing column clause is created.
2893

            
2894
    book.author as author,
2895
    book.title as title
2896

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

            
update pod
Yuki Kimoto authored on 2011-03-13
2899
    my $dbi = DBIx::Custom->new(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2900
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2901
        user => 'ken',
2902
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2903
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2904
    );
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
2905

            
2906
Create a new L<DBIx::Custom> object.
2907

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

            
2910
    my $not_exists = $dbi->not_exists;
2911

            
update pod
Yuki Kimoto authored on 2011-03-13
2912
DBIx::Custom::NotExists object, indicating the column is not exists.
cleanup
Yuki Kimoto authored on 2011-10-20
2913
This is used in C<param> of L<DBIx::Custom::Where> .
experimental extended select...
Yuki Kimoto authored on 2011-01-17
2914

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
2915
=head2 C<order>
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
2916

            
2917
    my $order = $dbi->order;
2918

            
2919
Create a new L<DBIx::Custom::Order> object.
2920

            
cleanup
yuki-kimoto authored on 2010-10-17
2921
=head2 C<register_filter>
2922

            
update pod
Yuki Kimoto authored on 2011-03-13
2923
    $dbi->register_filter(
2924
        # Time::Piece object to database DATE format
2925
        tp_to_date => sub {
2926
            my $tp = shift;
2927
            return $tp->strftime('%Y-%m-%d');
2928
        },
2929
        # database DATE format to Time::Piece object
2930
        date_to_tp => sub {
2931
           my $date = shift;
2932
           return Time::Piece->strptime($date, '%Y-%m-%d');
2933
        }
2934
    );
cleanup
yuki-kimoto authored on 2010-10-17
2935
    
update pod
Yuki Kimoto authored on 2011-03-13
2936
Register filters, used by C<filter> option of many methods.
cleanup
yuki-kimoto authored on 2010-10-17
2937

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

            
select method column option ...
Yuki Kimoto authored on 2011-02-22
2940
    my $result = $dbi->select(
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2941
        table  => 'book',
2942
        column => ['author', 'title'],
2943
        where  => {author => 'Ken'},
select method column option ...
Yuki Kimoto authored on 2011-02-22
2944
    );
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2945
    
updated document
Yuki Kimoto authored on 2011-06-09
2946
Execute select statement.
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2947

            
cleanup
Yuki Kimoto authored on 2011-10-20
2948
B<OPTIONS>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2949

            
cleanup
Yuki Kimoto authored on 2011-10-20
2950
C<select> method use all of C<execute> method's options,
2951
and use the following new ones.
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2952

            
cleanup
Yuki Kimoto authored on 2011-10-20
2953
=over 4
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
2954

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
2955
=item C<column>
2956
    
updated document
Yuki Kimoto authored on 2011-06-09
2957
    column => 'author'
2958
    column => ['author', 'title']
2959

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
2968
    column => [
updated pod
Yuki Kimoto authored on 2011-06-07
2969
        {book => [qw/author title/]},
2970
        {person => [qw/name age/]}
updated document
Yuki Kimoto authored on 2011-06-09
2971
    ]
updated pod
Yuki Kimoto authored on 2011-06-07
2972

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

            
2975
    book.author as "book.author",
2976
    book.title as "book.title",
2977
    person.name as "person.name",
2978
    person.age as "person.age"
2979

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

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

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

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

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

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

            
2995
=item C<id>
2996

            
2997
    id => 4
2998
    id => [4, 5]
2999

            
3000
ID corresponding to C<primary_key>.
3001
You can select rows by C<id> and C<primary_key>.
3002

            
3003
    $dbi->select(
fixed pod
Yuki Kimoto authored on 2011-10-20
3004
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3005
        id => [4, 5],
3006
        table => 'book'
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3007
    );
3008

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

            
updated pod
Yuki Kimoto authored on 2011-04-25
3011
    $dbi->select(
updated document
Yuki Kimoto authored on 2011-06-09
3012
        where => {id1 => 4, id2 => 5},
3013
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3014
    );
3015
    
cleanup
Yuki Kimoto authored on 2011-10-20
3016
=item C<param>
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
3017

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

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

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

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

            
3030
    prefix => 'SQL_CALC_FOUND_ROWS'
3031

            
3032
Prefix of column cluase
3033

            
3034
    select SQL_CALC_FOUND_ROWS title, author from book;
3035

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

            
3038
    join => [
3039
        'left outer join company on book.company_id = company_id',
3040
        'left outer join location on company.location_id = location.id'
3041
    ]
3042
        
3043
Join clause. If column cluase or where clause contain table name like "company.name",
3044
join clausees needed when SQL is created is used automatically.
update pod
Yuki Kimoto authored on 2011-03-12
3045

            
3046
    $dbi->select(
3047
        table => 'book',
cleanup
Yuki Kimoto authored on 2011-06-13
3048
        column => ['company.location_id as location_id'],
update pod
Yuki Kimoto authored on 2011-03-12
3049
        where => {'company.name' => 'Orange'},
3050
        join => [
3051
            'left outer join company on book.company_id = company.id',
3052
            'left outer join location on company.location_id = location.id'
3053
        ]
3054
    );
3055

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
3059
    select company.location_id as location_id
update pod
Yuki Kimoto authored on 2011-03-12
3060
    from book
3061
      left outer join company on book.company_id = company.id
cleanup
Yuki Kimoto authored on 2011-06-13
3062
    where company.name = ?;
update pod
Yuki Kimoto authored on 2011-03-12
3063

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3064
You can specify two table by yourself. This is useful when join parser can't parse
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3065
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3066

            
3067
    $dbi->select(
3068
        table => 'book',
3069
        column => ['company.location_id as location_id'],
3070
        where => {'company.name' => 'Orange'},
3071
        join => [
3072
            {
3073
                clause => 'left outer join location on company.location_id = location.id',
3074
                table => ['company', 'location']
3075
            }
3076
        ]
3077
    );
3078

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3085
=item C<where>
3086
    
3087
    # Hash refrence
3088
    where => {author => 'Ken', 'title' => 'Perl'}
3089
    
3090
    # DBIx::Custom::Where object
3091
    where => $dbi->where(
3092
        clause => ['and', 'author = :author', 'title like :title'],
3093
        param  => {author => 'Ken', title => '%Perl%'}
3094
    );
updated pod
Yuki Kimoto authored on 2011-06-21
3095
    
3096
    # Array reference 1 (array reference, hash referenc). same as above
3097
    where => [
3098
        ['and', 'author = :author', 'title like :title'],
3099
        {author => 'Ken', title => '%Perl%'}
3100
    ];    
3101
    
3102
    # Array reference 2 (String, hash reference)
3103
    where => [
3104
        'title like :title',
3105
        {title => '%Perl%'}
3106
    ]
3107
    
3108
    # String
3109
    where => 'title is null'
update pod
Yuki Kimoto authored on 2011-03-12
3110

            
cleanup
Yuki Kimoto authored on 2011-10-20
3111
Where clause. See L<DBIx::Custom::Where>.
updated document
Yuki Kimoto authored on 2011-06-09
3112
    
update pod
Yuki Kimoto authored on 2011-03-12
3113
=back
cleanup
Yuki Kimoto authored on 2011-03-08
3114

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3115
=head2 C<setup_model>
3116

            
3117
    $dbi->setup_model;
3118

            
3119
Setup all model objects.
3120
C<columns> of model object is automatically set, parsing database information.
3121

            
3122
=head2 C<type_rule>
3123

            
3124
    $dbi->type_rule(
3125
        into1 => {
3126
            date => sub { ... },
3127
            datetime => sub { ... }
3128
        },
3129
        into2 => {
3130
            date => sub { ... },
3131
            datetime => sub { ... }
3132
        },
3133
        from1 => {
3134
            # DATE
3135
            9 => sub { ... },
3136
            # DATETIME or TIMESTAMP
3137
            11 => sub { ... },
3138
        }
3139
        from2 => {
3140
            # DATE
3141
            9 => sub { ... },
3142
            # DATETIME or TIMESTAMP
3143
            11 => sub { ... },
3144
        }
3145
    );
3146

            
3147
Filtering rule when data is send into and get from database.
3148
This has a little complex problem.
3149

            
3150
In C<into1> and C<into2> you can specify
3151
type name as same as type name defined
3152
by create table, such as C<DATETIME> or C<DATE>.
3153

            
3154
Note that type name and data type don't contain upper case.
3155
If these contain upper case charactor, you convert it to lower case.
3156

            
3157
C<into2> is executed after C<into1>.
3158

            
3159
Type rule of C<into1> and C<into2> is enabled on the following
3160
column name.
3161

            
3162
=over 4
3163

            
3164
=item 1. column name
3165

            
3166
    issue_date
3167
    issue_datetime
3168

            
3169
This need C<table> option in each method.
3170

            
3171
=item 2. table name and column name, separator is dot
3172

            
3173
    book.issue_date
3174
    book.issue_datetime
3175

            
3176
=back
3177

            
3178
You get all type name used in database by C<available_typename>.
3179

            
3180
    print $dbi->available_typename;
3181

            
3182
In C<from1> and C<from2> you specify data type, not type name.
3183
C<from2> is executed after C<from1>.
3184
You get all data type by C<available_datatype>.
3185

            
3186
    print $dbi->available_datatype;
3187

            
3188
You can also specify multiple types at once.
3189

            
3190
    $dbi->type_rule(
3191
        into1 => [
3192
            [qw/DATE DATETIME/] => sub { ... },
3193
        ],
3194
    );
3195

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

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

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

            
3202
If you want to set constant value to row data, use scalar reference
3203
as parameter value.
3204

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
3207
B<OPTIONS>
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3208

            
cleanup
Yuki Kimoto authored on 2011-10-20
3209
C<update> method use all of C<execute> method's options,
3210
and use the following new ones.
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3211

            
cleanup
Yuki Kimoto authored on 2011-10-20
3212
=over 4
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3213

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3216
    id => 4
3217
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3218

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

            
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
3222
    $dbi->update(
updated document
Yuki Kimoto authored on 2011-06-09
3223
        {title => 'Perl', author => 'Ken'}
fixed pod
Yuki Kimoto authored on 2011-10-20
3224
        primary_key => ['id1', 'id2'],
updated document
Yuki Kimoto authored on 2011-06-09
3225
        id => [4, 5],
3226
        table => 'book'
where can recieve array refr...
Yuki Kimoto authored on 2011-03-24
3227
    );
update pod
Yuki Kimoto authored on 2011-03-13
3228

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3231
    $dbi->update(
3232
        {title => 'Perl', author => 'Ken'}
3233
        where => {id1 => 4, id2 => 5},
3234
        table => 'book'
3235
    );
update pod
Yuki Kimoto authored on 2011-03-13
3236

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

            
3239
    prefix => 'or replace'
3240

            
3241
prefix before table name section
3242

            
3243
    update or replace book
3244

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

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

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

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3251
=item C<timestamp>
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
3252

            
3253
    timestamp => 1
3254

            
3255
If this value is set to 1,
3256
automatically updated timestamp column is set based on
3257
C<timestamp> attribute's C<update> value.
3258

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

            
3261
Same as C<select> method's C<where> option.
3262

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3263
=item C<wrap>
updated pod
Yuki Kimoto authored on 2011-09-02
3264

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

            
3267
placeholder wrapped string.
3268

            
3269
If the following statement
3270

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

            
3274
is executed, the following SQL is executed.
3275

            
3276
    update book set price =  ? + 5;
3277

            
updated pod
Yuki Kimoto authored on 2011-06-08
3278
=back
update pod
Yuki Kimoto authored on 2011-03-13
3279

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

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

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

            
- removed DEPRECATED status ...
Yuki Kimoto authored on 2011-10-11
3287
=head2 C<update_or_insert EXPERIMENTAL>
3288
    
3289
    # Where
3290
    $dbi->update_or_insert(
3291
        {id => 1, title => 'Perl'},
3292
        table => 'book',
3293
        where => {id => 1},
3294
        select_option => {append => 'for update'}
3295
    );
3296
    
3297
    # ID
3298
    $dbi->update_or_insert(
3299
        {title => 'Perl'},
3300
        table => 'book',
3301
        id => 1,
3302
        primary_key => 'id',
3303
        select_option => {append => 'for update'}
3304
    );
3305
    
3306
Update or insert.
3307

            
3308
In both examples, the following SQL is executed.
3309

            
3310
    # In case insert
3311
    insert into book (id, title) values (?, ?)
3312
    
3313
    # In case update
3314
    update book set (id = ?, title = ?) where book.id = ?
3315

            
3316
The following opitons are available adding to C<update> option.
3317

            
3318
=over 4
3319

            
3320
=item C<select_option>
3321

            
3322
    select_option => {append => 'for update'}
3323

            
3324
select method option,
3325
select method is used to check the row is already exists.
3326

            
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3327
=head2 C<update_timestamp>
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3328

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3329
    $dbi->update_timestamp(
3330
      updated_at
3331
        => sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") }
cleanup
Yuki Kimoto authored on 2011-03-09
3332
    );
fix tests
Yuki Kimoto authored on 2011-01-18
3333

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3334
Timestamp value when C<update> method is executed
3335
with C<timestamp> option.
cleanup
Yuki Kimoto authored on 2011-01-12
3336

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3337
If C<insert_timestamp> is set and C<insert> method is executed
3338
with C<timestamp> option, column C<update_at>
3339
is automatically set to the value like "2010-10-11 10:12:54".
cleanup
Yuki Kimoto authored on 2011-01-12
3340

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3341
>|perl|
3342
$dbi->update($param, table => 'book', timestamp => 1);
3343
||<
cleanup
Yuki Kimoto authored on 2011-01-12
3344

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3345
=head2 C<show_datatype>
update pod
Yuki Kimoto authored on 2011-08-10
3346

            
3347
    $dbi->show_datatype($table);
3348

            
3349
Show data type of the columns of specified table.
3350

            
3351
    book
3352
    title: 5
3353
    issue_date: 91
3354

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

            
- removed EXPERIMENTAL the f...
Yuki Kimoto authored on 2011-09-12
3357
=head2 C<show_tables>
test cleanup
Yuki Kimoto authored on 2011-08-15
3358

            
3359
    $dbi->show_tables;
3360

            
3361
Show tables.
3362

            
- removed EXPERIMENTAL flag ...
Yuki Kimoto authored on 2011-09-12
3363
=head2 C<show_typename>
update pod
Yuki Kimoto authored on 2011-08-10
3364

            
3365
    $dbi->show_typename($table);
3366

            
3367
Show type name of the columns of specified table.
3368

            
3369
    book
3370
    title: varchar
3371
    issue_date: date
3372

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

            
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-10-19
3375
=head2 C<values_clause>
3376

            
3377
    my $values_clause = $dbi->values_clause({title => 'a', age => 2});
3378

            
3379
Create values clause.
3380

            
3381
    (title, author) values (title = :title, age = :age);
3382

            
3383
You can use this in insert statement.
3384

            
3385
    my $insert_sql = "insert into book $values_clause";
3386

            
3387
=head2 C<where>
3388

            
3389
    my $where = $dbi->where(
3390
        clause => ['and', 'title = :title', 'author = :author'],
3391
        param => {title => 'Perl', author => 'Ken'}
3392
    );
3393

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

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
3396
=head1 ENVIRONMENTAL VARIABLES
3397

            
3398
=head2 C<DBIX_CUSTOM_DEBUG>
3399

            
3400
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3401
executed SQL and bind values are printed to STDERR.
3402

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

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

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

            
3409
L<DBIx::Custom>
3410

            
3411
    # Attribute methods
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
3412
    default_dbi_option # will be removed 2017/1/1
3413
    dbi_option # will be removed 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3414
    data_source # will be removed at 2017/1/1
3415
    dbi_options # will be removed at 2017/1/1
3416
    filter_check # will be removed at 2017/1/1
3417
    reserved_word_quote # will be removed at 2017/1/1
3418
    cache_method # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3419
    
3420
    # Methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3421
    method # will be removed at 2017/1/1
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
3422
    assign_param # will be removed at 2017/1/1
3423
    update_param # will be removed at 2017/1/1
3424
    insert_param # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3425
    create_query # will be removed at 2017/1/1
3426
    apply_filter # will be removed at 2017/1/1
3427
    select_at # will be removed at 2017/1/1
3428
    delete_at # will be removed at 2017/1/1
3429
    update_at # will be removed at 2017/1/1
3430
    insert_at # will be removed at 2017/1/1
3431
    register_tag # will be removed at 2017/1/1
3432
    default_bind_filter # will be removed at 2017/1/1
3433
    default_fetch_filter # will be removed at 2017/1/1
3434
    insert_param_tag # will be removed at 2017/1/1
update pod
Yuki Kimoto authored on 2011-08-10
3435
    register_tag # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3436
    register_tag_processor # will be removed at 2017/1/1
3437
    update_param_tag # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3438
    
3439
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
3440
    select method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3441
    delete method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3442
    update method where_param option # will be removed 2017/1/1
cleanup
Yuki Kimoto authored on 2011-10-21
3443
    insert method param option # will be removed at 2017/1/1
insert method's id option is...
Yuki Kimoto authored on 2011-10-10
3444
    insert method id option # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3445
    select method relation option # will be removed at 2017/1/1
3446
    select method column option [COLUMN, as => ALIAS] format
3447
      # will be removed at 2017/1/1
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
3448
    execute method's sqlfilter option # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3449
    
3450
    # Others
cleanup
Yuki Kimoto authored on 2011-07-28
3451
    execute("select * from {= title}"); # execute method's
3452
                                        # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3453
                                        # will be removed at 2017/1/1
3454
    Query caching # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3455

            
3456
L<DBIx::Custom::Model>
3457

            
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3458
    # Attribute methods
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
3459
    method # will be removed at 2017/1/1
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3460
    filter # will be removed at 2017/1/1
3461
    name # will be removed at 2017/1/1
3462
    type # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3463

            
3464
L<DBIx::Custom::Query>
3465
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3466
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3467
    default_filter # will be removed at 2017/1/1
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3468
    table # will be removed at 2017/1/1
3469
    filters # will be removed at 2017/1/1
3470
    
3471
    # Methods
3472
    filter # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3473

            
3474
L<DBIx::Custom::QueryBuilder>
3475
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3476
    # Attribute methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3477
    tags # will be removed at 2017/1/1
3478
    tag_processors # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3479
    
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
3480
    # Methods
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3481
    register_tag # will be removed at 2017/1/1
3482
    register_tag_processor # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3483
    
3484
    # Others
3485
    build_query("select * from {= title}"); # tag parsing functionality
added EXPERIMENTAL each_tabl...
Yuki Kimoto authored on 2011-07-11
3486
                                            # will be removed at 2017/1/1
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3487

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

            
3499
L<DBIx::Custom::Tag>
3500

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

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

            
3505
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings
3506
except for attribute method.
3507
You can check all DEPRECATED functionalities by document.
3508
DEPRECATED functionality is removed after five years,
3509
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
3510
I extend one year each time he tell me it.
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
3511

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

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

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

            
3518
C<< <kimoto.yuki at gmail.com> >>
3519

            
3520
L<http://github.com/yuki-kimoto/DBIx-Custom>
3521

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3522
=head1 AUTHOR
3523

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

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

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

            
3530
This program is free software; you can redistribute it and/or modify it
3531
under the same terms as Perl itself.
3532

            
3533
=cut