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

            
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
4
our $VERSION = '0.1738';
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
cleanup
Yuki Kimoto authored on 2011-10-25
244
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
cleanup
Yuki Kimoto authored on 2011-10-25
245
      delete $opt{id}, $opt{primary_key}, $opt{table});
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
246

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

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

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

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

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

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

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

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

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

            
353
    # Options
execute method can second ar...
Yuki Kimoto authored on 2011-06-09
354
    my $param;
355
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
356
    my %opt = @_;
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
357
    warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter};
358
    $param ||= $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-10-21
359
    my $tables = $opt{table} || [];
cleanup
Yuki Kimoto authored on 2011-04-02
360
    $tables = [$tables] unless ref $tables eq 'ARRAY';
micro optimization
Yuki Kimoto authored on 2011-10-23
361
    my $filter = ref $opt{filter} eq 'ARRAY' ?
362
      _array_to_hash($opt{filter}) : $opt{filter};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
363
    
micro optimization and
Yuki Kimoto authored on 2011-10-25
364
    # Merge second parameter
365
    my @cleanup;
366
    if (ref $param eq 'ARRAY') {
367
        my $param2 = $param->[1];
368
        $param = $param->[0];
369
        for my $column (keys %$param2) {
370
            if (!exists $param->{$column}) {
371
                $param->{$column} = $param2->{$column};
372
                push @cleanup, $column;
373
            }
374
            else {
375
                delete $param->{$_} for @cleanup;
376
                @cleanup = ();
377
                $param = $self->merge_param($param, $param2);
378
                last;
379
            }
380
        }
381
    }
382
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
383
    # Append
384
    $sql .= $opt{append} if defined $opt{append} && !ref $sql;
385
    
386
    # Query
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
387
    my $query;
micro optimization and
Yuki Kimoto authored on 2011-10-25
388
    if (ref $sql) {
389
        $query = $sql;
390
        warn "execute method receiving query object as first parameter is DEPRECATED!" .
391
             "because this is very buggy.";
392
    }
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
393
    else {
394
        $query = $opt{reuse}->{$sql} if $opt{reuse};
395
        $query = $self->_create_query($sql,$opt{after_build_sql} || $opt{sqlfilter})
396
          unless $query;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
397
        $query->statement($opt{statement} || '');
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
398
        $opt{reuse}->{$sql} = $query if $opt{reuse};
399
    }
400
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
401
    # Save query
micro optimization
Yuki Kimoto authored on 2011-10-23
402
    $self->{last_sql} = $query->{sql};
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
403

            
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
404
    # Return query
405
    return $query if $opt{query};
micro optimization
Yuki Kimoto authored on 2011-07-30
406
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
407
    # Merge query filter(DEPRECATED!)
DBIx::Custom::Query filter m...
Yuki Kimoto authored on 2011-07-30
408
    $filter ||= $query->{filter} || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
409
    
cleanup
Yuki Kimoto authored on 2011-04-02
410
    # Tables
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
411
    unshift @$tables, @{$query->{tables} || []};
micro optimization
Yuki Kimoto authored on 2011-07-30
412
    my $main_table = @{$tables}[-1];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
413

            
414
    # Merge id to parameter
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
415
    if (defined $opt{id}) {
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
416
        croak "execute id option must be specified with primary_key option"
417
          unless $opt{primary_key};
418
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
419
        $opt{id} = [$opt{id}] unless ref $opt{id};
420
        my $statement = $query->statement;
421
        for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
422
           my $key = $opt{primary_key}->[$i];
423
           $key = "$main_table.$key" if $statement eq 'update' ||
424
             $statement eq 'delete' || $statement eq 'select';
425
           next if exists $param->{$key};
426
           $param->{$key} = $opt{id}->[$i];
micro optimization and
Yuki Kimoto authored on 2011-10-25
427
           push @cleanup, $key;1
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
428
        }
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
429
    }
micro optimization
Yuki Kimoto authored on 2011-07-30
430
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
431
    # Cleanup tables(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
432
    $tables = $self->_remove_duplicate_table($tables, $main_table)
433
      if @$tables > 1;
cleanup
Yuki Kimoto authored on 2011-04-02
434
    
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
435
    # Type rule
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
436
    my $type_filters = {};
micro optimization
Yuki Kimoto authored on 2011-10-23
437
    if ($self->{_type_rule_is_called}) {
438
        unless ($opt{type_rule_off}) {
439
            my $type_rule_off_parts = {
440
                1 => $opt{type_rule1_off},
441
                2 => $opt{type_rule2_off}
442
            };
443
            for my $i (1, 2) {
444
                unless ($type_rule_off_parts->{$i}) {
445
                    $type_filters->{$i} = {};
446
                    my $table_alias = $opt{table_alias} || {};
447
                    for my $alias (keys %$table_alias) {
448
                        my $table = $table_alias->{$alias};
449
                        
450
                        for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) {
451
                            $type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column};
452
                        }
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
453
                    }
micro optimization
Yuki Kimoto authored on 2011-10-23
454
                    $type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}}
455
                      if $main_table;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
456
                }
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
457
            }
added type_rule into logic
Yuki Kimoto authored on 2011-06-09
458
        }
459
    }
cleanup
Yuki Kimoto authored on 2011-04-02
460
    
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
461
    # Applied filter(DEPRECATED!)
micro optimization
Yuki Kimoto authored on 2011-07-30
462
    if ($self->{filter}{on}) {
463
        my $applied_filter = {};
cleanup
Yuki Kimoto authored on 2011-10-21
464
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-07-30
465
            $applied_filter = {
466
                %$applied_filter,
467
                %{$self->{filter}{out}->{$table} || {}}
468
            }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
469
        }
micro optimization
Yuki Kimoto authored on 2011-07-30
470
        $filter = {%$applied_filter, %$filter};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
471
    }
472
    
cleanup
Yuki Kimoto authored on 2011-04-02
473
    # Replace filter name to code
cleanup
Yuki Kimoto authored on 2011-10-21
474
    for my $column (keys %$filter) {
cleanup
Yuki Kimoto authored on 2011-04-02
475
        my $name = $filter->{$column};
476
        if (!defined $name) {
477
            $filter->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
478
        }
cleanup
Yuki Kimoto authored on 2011-04-02
479
        elsif (ref $name ne 'CODE') {
cleanup
Yuki Kimoto authored on 2011-04-25
480
          croak qq{Filter "$name" is not registered" } . _subname
cleanup
Yuki Kimoto authored on 2011-04-02
481
            unless exists $self->filters->{$name};
482
          $filter->{$column} = $self->filters->{$name};
cleanup
Yuki Kimoto authored on 2010-12-21
483
        }
484
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
485
    
cleanup
Yuki Kimoto authored on 2011-04-02
486
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
487
    my ($bind, $bind_types) = $self->_create_bind_values($param, $query->columns,
488
      $filter, $type_filters, $opt{bind_type} || $opt{type} || {});
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
489

            
cleanup
yuki-kimoto authored on 2010-10-17
490
    # Execute
micro optimization
Yuki Kimoto authored on 2011-10-23
491
    my $sth = $query->{sth};
cleanup
yuki-kimoto authored on 2010-10-17
492
    my $affected;
cleanup
Yuki Kimoto authored on 2011-03-21
493
    eval {
micro optimization
Yuki Kimoto authored on 2011-10-23
494
        if ($opt{bind_type} || $opt{type}) {
495
            $sth->bind_param($_ + 1, $bind->[$_],
496
                $bind_types->[$_] ? $bind_types->[$_] : ())
497
              for (0 .. @$bind - 1);
498
            $affected = $sth->execute;
499
        }
500
        else {
501
            $affected = $sth->execute(@$bind);
502
        }
cleanup
Yuki Kimoto authored on 2011-03-21
503
    };
improved error messages
Yuki Kimoto authored on 2011-04-18
504
    
micro optimization
Yuki Kimoto authored on 2011-07-30
505
    $self->_croak($@, qq{. Following SQL is executed.\n}
506
      . qq{$query->{sql}\n} . _subname) if $@;
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
507

            
508
    # Remove id from parameter
509
    delete $param->{$_} for @cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
510

            
cleanup
yuki-kimoto authored on 2010-10-17
511
    
improved debug message
Yuki Kimoto authored on 2011-05-23
512
    # DEBUG message
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
513
    if ($ENV{DBIX_CUSTOM_DEBUG}) {
514
        warn "SQL:\n" . $query->sql . "\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
515
        my @output;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
516
        for my $value (@$bind) {
improved debug message
Yuki Kimoto authored on 2011-05-23
517
            $value = 'undef' unless defined $value;
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
518
            $value = encode($ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8', $value)
improved debug message
Yuki Kimoto authored on 2011-05-23
519
              if utf8::is_utf8($value);
520
            push @output, $value;
521
        }
fixed DEBUG messsage bug
Yuki Kimoto authored on 2011-10-24
522
        warn "Bind values: " . join(', ', @output) . "\n\n";
improved debug message
Yuki Kimoto authored on 2011-05-23
523
    }
added environment variable D...
Yuki Kimoto authored on 2011-04-02
524
    
micro optimization
Yuki Kimoto authored on 2011-10-23
525
    # Not select statement
526
    return $affected unless $sth->{NUM_OF_FIELDS};
527

            
528
    # Filter(DEPRECATED!)
529
    my $infilter = {};
530
    if ($self->{filter}{on}) {
531
        $infilter->{in}  = {};
532
        $infilter->{end} = {};
533
        push @$tables, $main_table if $main_table;
534
        for my $table (@$tables) {
535
            for my $way (qw/in end/) {
536
                $infilter->{$way} = {%{$infilter->{$way}},
537
                  %{$self->{filter}{$way}{$table} || {}}};
cleanup
Yuki Kimoto authored on 2011-04-02
538
            }
cleanup
Yuki Kimoto authored on 2011-01-12
539
        }
cleanup
yuki-kimoto authored on 2010-10-17
540
    }
micro optimization
Yuki Kimoto authored on 2011-10-23
541
    
542
    # Result
543
    my $result = $self->result_class->new(
544
        sth => $sth,
545
        dbi => $self,
546
        default_filter => $self->{default_in_filter},
547
        filter => $infilter->{in} || {},
548
        end_filter => $infilter->{end} || {},
549
        type_rule => {
550
            from1 => $self->type_rule->{from1},
551
            from2 => $self->type_rule->{from2}
552
        },
553
    );
554
    $result;
cleanup
yuki-kimoto authored on 2010-10-17
555
}
556

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

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

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
589
sub helper {
590
    my $self = shift;
591
    
592
    # Register method
593
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
594
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
595
    
596
    return $self;
597
}
598

            
cleanup
yuki-kimoto authored on 2010-10-17
599
sub insert {
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
600
    my $self = shift;
added EXPERIMENTAL reserved_...
Yuki Kimoto authored on 2011-03-30
601
    
cleanup
Yuki Kimoto authored on 2011-10-21
602
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
603
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
604
    my %opt = @_;
micro optimization
Yuki Kimoto authored on 2011-10-23
605
    warn "insert method param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
606
    $param ||= delete $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
607
    
608
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
609
    if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
610
        my $columns = $insert_timestamp->[0];
611
        $columns = [$columns] unless ref $columns eq 'ARRAY';
612
        my $value = $insert_timestamp->[1];
613
        $value = $value->() if ref $value eq 'CODE';
614
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
615
    }
cleanup
Yuki Kimoto authored on 2011-10-21
616
    
617
    # Merge id to parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
618
    my @cleanup;
micro optimization and
Yuki Kimoto authored on 2011-10-25
619
    my $id_param = {};
micro optimization
Yuki Kimoto authored on 2011-10-23
620
    if (defined $opt{id}) {
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
621
        croak "insert id option must be specified with primary_key option"
micro optimization
Yuki Kimoto authored on 2011-10-23
622
          unless $opt{primary_key};
623
        $opt{primary_key} = [$opt{primary_key}] unless ref $opt{primary_key};
624
        $opt{id} = [$opt{id}] unless ref $opt{id};
625
        for (my $i = 0; $i < @{$opt{primary_key}}; $i++) {
626
           my $key = $opt{primary_key}->[$i];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
627
           next if exists $param->{$key};
micro optimization
Yuki Kimoto authored on 2011-10-23
628
           $param->{$key} = $opt{id}->[$i];
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
629
           push @cleanup, $key;
micro optimization
Yuki Kimoto authored on 2011-10-23
630
        }
631
    }
cleanup
Yuki Kimoto authored on 2011-10-21
632
    
cleanup
Yuki Kimoto authored on 2011-04-02
633
    # Insert statement
cleanup
Yuki Kimoto authored on 2011-10-21
634
    my $sql = "insert ";
cleanup
Yuki Kimoto authored on 2011-10-21
635
    $sql .= "$opt{prefix} " if defined $opt{prefix};
636
    $sql .= "into " . $self->_q($opt{table}) . " "
637
      . $self->values_clause($param, {wrap => $opt{wrap}}) . " ";
micro optimization
Yuki Kimoto authored on 2011-10-23
638

            
639
    # Remove id from parameter
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
640
    delete $param->{$_} for @cleanup;
packaging one directory
yuki-kimoto authored on 2009-11-16
641
    
642
    # Execute query
micro optimization
Yuki Kimoto authored on 2011-10-23
643
    $opt{statement} = 'insert';
micro optimization
Yuki Kimoto authored on 2011-10-23
644
    $self->execute($sql, $param, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
645
}
646

            
micro optimization
Yuki Kimoto authored on 2011-10-23
647
sub _merge_id_to_param {
648
    my ($self, $id, $primary_keys, $param) = @_;
649
    
650
    # Create parameter
651
    $id = [$id] unless ref $id;
652
    
653
    return $param;
654
}
655

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
656
sub insert_timestamp {
657
    my $self = shift;
658
    
659
    if (@_) {
660
        $self->{insert_timestamp} = [@_];
661
        
662
        return $self;
663
    }
664
    return $self->{insert_timestamp};
665
}
666

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

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
734
sub mapper {
735
    my $self = shift;
736
    return DBIx::Custom::Mapper->new(@_);
737
}
738

            
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
739
sub merge_param {
740
    my ($self, @params) = @_;
741
    
cleanup
Yuki Kimoto authored on 2011-04-02
742
    # Merge parameters
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
743
    my $merge = {};
cleanup
Yuki Kimoto authored on 2011-10-21
744
    for my $param (@params) {
745
        for my $column (keys %$param) {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
746
            my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0;
747
            
748
            if (exists $merge->{$column}) {
749
                $merge->{$column} = [$merge->{$column}]
750
                  unless ref $merge->{$column} eq 'ARRAY';
751
                push @{$merge->{$column}},
752
                  ref $param->{$column} ? @{$param->{$column}} : $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
753
            }
754
            else {
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
755
                $merge->{$column} = $param->{$column};
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
756
            }
757
        }
758
    }
759
    
fixed merge_param bug
Yuki Kimoto authored on 2011-05-23
760
    return $merge;
added EXPERIMENTAL updat_par...
Yuki Kimoto authored on 2011-03-30
761
}
762

            
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
763
sub model {
764
    my ($self, $name, $model) = @_;
765
    
cleanup
Yuki Kimoto authored on 2011-04-02
766
    # Set model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
767
    if ($model) {
768
        $self->models->{$name} = $model;
769
        return $self;
770
    }
771
    
772
    # Check model existance
cleanup
Yuki Kimoto authored on 2011-04-25
773
    croak qq{Model "$name" is not included } . _subname
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
774
      unless $self->models->{$name};
775
    
cleanup
Yuki Kimoto authored on 2011-04-02
776
    # Get model
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-15
777
    return $self->models->{$name};
778
}
779

            
cleanup
Yuki Kimoto authored on 2011-03-21
780
sub mycolumn {
781
    my ($self, $table, $columns) = @_;
782
    
cleanup
Yuki Kimoto authored on 2011-04-02
783
    # Create column clause
784
    my @column;
cleanup
Yuki Kimoto authored on 2011-03-21
785
    $columns ||= [];
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
786
    push @column, $self->_q($table) . "." . $self->_q($_) .
787
      " as " . $self->_q($_)
788
      for @$columns;
cleanup
Yuki Kimoto authored on 2011-03-21
789
    
790
    return join (', ', @column);
791
}
792

            
added dbi_options attribute
kimoto authored on 2010-12-20
793
sub new {
794
    my $self = shift->SUPER::new(@_);
795
    
cleanup
Yuki Kimoto authored on 2011-04-02
796
    # Check attributes
added dbi_options attribute
kimoto authored on 2010-12-20
797
    my @attrs = keys %$self;
cleanup
Yuki Kimoto authored on 2011-10-21
798
    for my $attr (@attrs) {
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-08-20
799
        croak qq{Invalid attribute: "$attr" } . _subname
added dbi_options attribute
kimoto authored on 2010-12-20
800
          unless $self->can($attr);
801
    }
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
802

            
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
803
    # DEPRECATED
cleanup
Yuki Kimoto authored on 2011-08-13
804
    $self->{_tags} = {
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
805
        '?'     => \&DBIx::Custom::Tag::placeholder,
806
        '='     => \&DBIx::Custom::Tag::equal,
807
        '<>'    => \&DBIx::Custom::Tag::not_equal,
808
        '>'     => \&DBIx::Custom::Tag::greater_than,
809
        '<'     => \&DBIx::Custom::Tag::lower_than,
810
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
811
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
812
        'like'  => \&DBIx::Custom::Tag::like,
813
        'in'    => \&DBIx::Custom::Tag::in,
814
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
815
        'update_param' => \&DBIx::Custom::Tag::update_param
cleanup
Yuki Kimoto authored on 2011-08-13
816
    };
817
    
818
    return $self;
819
}
820

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

            
823
sub order {
824
    my $self = shift;
825
    return DBIx::Custom::Order->new(dbi => $self, @_);
added EXPERIMENTAL system_ta...
Yuki Kimoto authored on 2011-08-10
826
}
827

            
cleanup
yuki-kimoto authored on 2010-10-17
828
sub register_filter {
cleanup
Yuki Kimoto authored on 2011-04-02
829
    my $self = shift;
cleanup
yuki-kimoto authored on 2010-10-17
830
    
831
    # Register filter
832
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
cleanup
Yuki Kimoto authored on 2011-04-02
833
    $self->filters({%{$self->filters}, %$filters});
cleanup
yuki-kimoto authored on 2010-10-17
834
    
cleanup
Yuki Kimoto authored on 2011-04-02
835
    return $self;
cleanup
yuki-kimoto authored on 2010-10-17
836
}
packaging one directory
yuki-kimoto authored on 2009-11-16
837

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
841
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
842
    my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table}
843
               : defined $opt{table} ? [$opt{table}]
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
844
               : [];
cleanup
Yuki Kimoto authored on 2011-10-21
845
    $opt{table} = $tables;
cleanup
Yuki Kimoto authored on 2011-10-21
846
    my $where_param = $opt{where_param} || delete $opt{param} || {};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
847
    
cleanup
Yuki Kimoto authored on 2011-03-09
848
    # Add relation tables(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
849
    if ($opt{relation}) {
850
        warn "select() relation option is DEPRECATED!";
851
        $self->_add_relation_table($tables, $opt{relation});
852
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
853
    
cleanup
Yuki Kimoto authored on 2011-04-02
854
    # Select statement
micro optimization
Yuki Kimoto authored on 2011-09-30
855
    my $sql = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
856
    
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
857
    # Prefix
cleanup
Yuki Kimoto authored on 2011-10-21
858
    $sql .= "$opt{prefix} " if defined $opt{prefix};
added EXPERIMENTAL select pr...
Yuki Kimoto authored on 2011-06-13
859
    
cleanup
Yuki Kimoto authored on 2011-10-21
860
    # Column
cleanup
Yuki Kimoto authored on 2011-10-21
861
    if (defined $opt{column}) {
862
        my $columns
863
          = ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}];
cleanup
Yuki Kimoto authored on 2011-10-21
864
        for my $column (@$columns) {
- select() column option can...
Yuki Kimoto authored on 2011-06-08
865
            if (ref $column eq 'HASH') {
EXPERIMTANL column method th...
Yuki Kimoto authored on 2011-06-13
866
                $column = $self->column(%$column) if ref $column eq 'HASH';
- select() column option can...
Yuki Kimoto authored on 2011-06-08
867
            }
868
            elsif (ref $column eq 'ARRAY') {
- select method column optio...
Yuki Kimoto authored on 2011-07-11
869
                if (@$column == 3 && $column->[1] eq 'as') {
870
                    warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]";
871
                    splice @$column, 1, 1;
872
                }
873
                
added quote method's two cha...
Yuki Kimoto authored on 2011-07-29
874
                $column = join(' ', $column->[0], 'as', $self->_q($column->[1]));
- select() column option can...
Yuki Kimoto authored on 2011-06-08
875
            }
cleanup
Yuki Kimoto authored on 2011-04-02
876
            unshift @$tables, @{$self->_search_tables($column)};
micro optimization
Yuki Kimoto authored on 2011-09-30
877
            $sql .= "$column, ";
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
878
        }
micro optimization
Yuki Kimoto authored on 2011-09-30
879
        $sql =~ s/, $/ /;
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
880
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
881
    else { $sql .= '* ' }
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
882
    
883
    # Table
micro optimization
Yuki Kimoto authored on 2011-09-30
884
    $sql .= 'from ';
cleanup
Yuki Kimoto authored on 2011-10-21
885
    if ($opt{relation}) {
cleanup
Yuki Kimoto authored on 2011-03-30
886
        my $found = {};
cleanup
Yuki Kimoto authored on 2011-10-21
887
        for my $table (@$tables) {
micro optimization
Yuki Kimoto authored on 2011-09-30
888
            $sql .= $self->_q($table) . ', ' unless $found->{$table};
cleanup
Yuki Kimoto authored on 2011-03-30
889
            $found->{$table} = 1;
- added EXPERIMENTAL DBIx::C...
Yuki Kimoto authored on 2011-03-14
890
        }
packaging one directory
yuki-kimoto authored on 2009-11-16
891
    }
moved DBIx::Custom::Guide to...
Yuki Kimoto authored on 2011-10-22
892
    else { $sql .= $self->_q($tables->[-1] || '') . ' ' }
micro optimization
Yuki Kimoto authored on 2011-09-30
893
    $sql =~ s/, $/ /;
cleanup
Yuki Kimoto authored on 2011-10-21
894
    croak "select method table option must be specified " . _subname
improved error messages
Yuki Kimoto authored on 2011-04-18
895
      unless $tables->[-1];
cleanup
Yuki Kimoto authored on 2011-04-01
896

            
cleanup
Yuki Kimoto authored on 2011-04-02
897
    # Add tables in parameter
DEPRECATED select() param op...
Yuki Kimoto authored on 2011-04-25
898
    unshift @$tables,
899
            @{$self->_search_tables(join(' ', keys %$where_param) || '')};
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
900
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
901
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
902
    my $w = $self->_where_clause_and_param($opt{where}, $where_param,
903
      delete $opt{id}, $opt{primary_key}, $tables->[-1]);
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
904
    
fixed some select() join opi...
Yuki Kimoto authored on 2011-03-09
905
    # Add table names in where clause
cleanup
Yuki Kimoto authored on 2011-10-21
906
    unshift @$tables, @{$self->_search_tables($w->{clause})};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
907
    
cleanup
Yuki Kimoto authored on 2011-10-21
908
    # Join statement
cleanup
Yuki Kimoto authored on 2011-10-21
909
    $self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join};
remove experimental DBIx::Cu...
Yuki Kimoto authored on 2011-03-08
910
    
cleanup
Yuki Kimoto authored on 2011-03-09
911
    # Add where clause
cleanup
Yuki Kimoto authored on 2011-10-21
912
    $sql .= "$w->{clause} ";
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
913
    
cleanup
Yuki Kimoto authored on 2011-03-08
914
    # Relation(DEPRECATED!);
cleanup
Yuki Kimoto authored on 2011-10-21
915
    $self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0)
cleanup
Yuki Kimoto authored on 2011-10-21
916
      if $opt{relation};
cleanup
Yuki Kimoto authored on 2011-03-08
917
    
packaging one directory
yuki-kimoto authored on 2009-11-16
918
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
919
    $opt{statement} = 'select';
cleanup
Yuki Kimoto authored on 2011-10-21
920
    my $result = $self->execute($sql, $w->{param}, %opt);
packaging one directory
yuki-kimoto authored on 2009-11-16
921
    
micro optimization
Yuki Kimoto authored on 2011-10-23
922
    $result;
packaging one directory
yuki-kimoto authored on 2009-11-16
923
}
924

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
925
sub setup_model {
926
    my $self = shift;
927
    
cleanup
Yuki Kimoto authored on 2011-04-02
928
    # Setup model
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
929
    $self->each_column(
930
        sub {
931
            my ($self, $table, $column, $column_info) = @_;
932
            if (my $model = $self->models->{$table}) {
933
                push @{$model->columns}, $column;
934
            }
935
        }
936
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
937
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
938
}
939

            
update pod
Yuki Kimoto authored on 2011-08-10
940
sub show_datatype {
941
    my ($self, $table) = @_;
942
    croak "Table name must be specified" unless defined $table;
943
    print "$table\n";
944
    
945
    my $result = $self->select(table => $table, where => "'0' <> '0'");
946
    my $sth = $result->sth;
947

            
948
    my $columns = $sth->{NAME};
949
    my $data_types = $sth->{TYPE};
950
    
951
    for (my $i = 0; $i < @$columns; $i++) {
952
        my $column = $columns->[$i];
953
        my $data_type = $data_types->[$i];
954
        print "$column: $data_type\n";
955
    }
956
}
957

            
958
sub show_typename {
959
    my ($self, $t) = @_;
960
    croak "Table name must be specified" unless defined $t;
961
    print "$t\n";
962
    
963
    $self->each_column(sub {
964
        my ($self, $table, $column, $infos) = @_;
965
        return unless $table eq $t;
966
        my $typename = $infos->{TYPE_NAME};
967
        print "$column: $typename\n";
968
    });
969
    
970
    return $self;
971
}
972

            
test cleanup
Yuki Kimoto authored on 2011-08-15
973
sub show_tables {
974
    my $self = shift;
975
    
976
    my %tables;
977
    $self->each_table(sub { $tables{$_[1]}++ });
978
    print join("\n", sort keys %tables) . "\n";
979
    return $self;
980
}
981

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

            
985
    $self->{_type_rule_is_called} = 1;
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
986
    
987
    if (@_) {
changed type_rule arguments ...
Yuki Kimoto authored on 2011-06-12
988
        my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_};
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
989
        
990
        # Into
cleanup
Yuki Kimoto authored on 2011-10-21
991
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
992
            my $into = "into$i";
cleanup
Yuki Kimoto authored on 2011-08-16
993
            my $exists_into = exists $type_rule->{$into};
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
994
            $type_rule->{$into} = _array_to_hash($type_rule->{$into});
995
            $self->{type_rule} = $type_rule;
996
            $self->{"_$into"} = {};
cleanup
Yuki Kimoto authored on 2011-10-21
997
            for my $type_name (keys %{$type_rule->{$into} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
998
                croak qq{type name of $into section must be lower case}
999
                  if $type_name =~ /[A-Z]/;
1000
            }
cleanup
Yuki Kimoto authored on 2011-08-16
1001
            
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1002
            $self->each_column(sub {
1003
                my ($dbi, $table, $column, $column_info) = @_;
1004
                
1005
                my $type_name = lc $column_info->{TYPE_NAME};
1006
                if ($type_rule->{$into} &&
1007
                    (my $filter = $type_rule->{$into}->{$type_name}))
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1008
                {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1009
                    return unless exists $type_rule->{$into}->{$type_name};
1010
                    if  (defined $filter && ref $filter ne 'CODE') 
1011
                    {
1012
                        my $fname = $filter;
1013
                        croak qq{Filter "$fname" is not registered" } . _subname
1014
                          unless exists $self->filters->{$fname};
1015
                        
1016
                        $filter = $self->filters->{$fname};
1017
                    }
1018

            
micro optimization
Yuki Kimoto authored on 2011-07-30
1019
                    $self->{"_$into"}{key}{$table}{$column} = $filter;
1020
                    $self->{"_$into"}{dot}{"$table.$column"} = $filter;
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1021
                }
1022
            });
1023
        }
1024

            
1025
        # From
cleanup
Yuki Kimoto authored on 2011-10-21
1026
        for my $i (1 .. 2) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1027
            $type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"});
cleanup
Yuki Kimoto authored on 2011-10-21
1028
            for my $data_type (keys %{$type_rule->{"from$i"} || {}}) {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1029
                croak qq{data type of from$i section must be lower case or number}
1030
                  if $data_type =~ /[A-Z]/;
1031
                my $fname = $type_rule->{"from$i"}{$data_type};
1032
                if (defined $fname && ref $fname ne 'CODE') {
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1033
                    croak qq{Filter "$fname" is not registered" } . _subname
1034
                      unless exists $self->filters->{$fname};
1035
                    
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1036
                    $type_rule->{"from$i"}{$data_type} = $self->filters->{$fname};
type_rule can receive filter...
Yuki Kimoto authored on 2011-06-12
1037
                }
fixed bug that type_rule fro...
Yuki Kimoto authored on 2011-06-13
1038
            }
1039
        }
1040
        
added type_rule method and f...
Yuki Kimoto authored on 2011-06-09
1041
        return $self;
1042
    }
1043
    
1044
    return $self->{type_rule} || {};
1045
}
1046

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1050
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1051
    my $param = @_ % 2 ? shift : undef;
cleanup
Yuki Kimoto authored on 2011-10-21
1052
    my %opt = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1053
    warn "update param option is DEPRECATED!" if $opt{param};
cleanup
Yuki Kimoto authored on 2011-10-21
1054
    warn "update method where_param option is DEPRECATED!"
1055
      if $opt{where_param};
cleanup
Yuki Kimoto authored on 2011-10-21
1056
    $param ||= $opt{param} || {};
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1057
    
cleanup
Yuki Kimoto authored on 2011-10-21
1058
    # Don't allow update all rows
1059
    croak qq{update method where option must be specified } . _subname
1060
      if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all};
1061
    
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1062
    # Timestamp
cleanup
Yuki Kimoto authored on 2011-10-21
1063
    if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) {
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1064
        my $columns = $update_timestamp->[0];
1065
        $columns = [$columns] unless ref $columns eq 'ARRAY';
1066
        my $value = $update_timestamp->[1];
1067
        $value = $value->() if ref $value eq 'CODE';
1068
        $param->{$_} = $value for @$columns;
- added EXPERIMENTAL timesta...
Yuki Kimoto authored on 2011-09-02
1069
    }
1070

            
cleanup
Yuki Kimoto authored on 2011-10-21
1071
    # Assign clause
cleanup
Yuki Kimoto authored on 2011-10-21
1072
    my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}});
cleanup
Yuki Kimoto authored on 2011-10-21
1073
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
1074
    # Where
cleanup
Yuki Kimoto authored on 2011-10-25
1075
    my $w = $self->_where_clause_and_param($opt{where}, $opt{where_param},
1076
      delete $opt{id}, $opt{primary_key}, $opt{table});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1077
    
cleanup
Yuki Kimoto authored on 2011-04-02
1078
    # Update statement
cleanup
Yuki Kimoto authored on 2011-10-21
1079
    my $sql = "update ";
1080
    $sql .= "$opt{prefix} " if defined $opt{prefix};
cleanup
Yuki Kimoto authored on 2011-10-21
1081
    $sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} ";
cleanup
Yuki Kimoto authored on 2011-01-27
1082
    
cleanup
yuki-kimoto authored on 2010-10-17
1083
    # Execute query
- insert method id value is ...
Yuki Kimoto authored on 2011-10-25
1084
    $opt{statement} = 'update';
micro optimization and
Yuki Kimoto authored on 2011-10-25
1085
    $self->execute($sql, [$param, $w->{param}], %opt);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1086
}
1087

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1090
sub update_or_insert {
1091
    my $self = shift;
1092

            
cleanup
Yuki Kimoto authored on 2011-10-21
1093
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1094
    my $param  = shift;
1095
    my %opt = @_;
1096
    my $id = $opt{id};
1097
    my $primary_key = $opt{primary_key};
1098
    $primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY';
1099
    croak "update_or_insert method need primary_key option " .
1100
          "when id is specified" . _subname
1101
      if defined $id && !defined $primary_key;
1102
    my $table  = $opt{table};
1103
    croak qq{"table" option must be specified } . _subname
1104
      unless defined $table;
1105
    my $select_option = $opt{select_option};
1106
    
1107
    my $rows = $self->select(table => $table, id => $id,
1108
        primary_key => $primary_key, %$select_option)->all;
1109
    
1110
    croak "selected row count must be one or zero" . _subname
1111
      if @$rows > 1;
1112
    
1113
    my $row = $rows->[0];
1114
    my @opt = (table => $table);
1115
    push @opt, id => $id, primary_key => $primary_key if defined $id;
1116
    push @opt, %opt;
1117
    
1118
    if ($row) {
1119
        return $self->update($param, @opt);
1120
    }
1121
    else {
1122
        return $self->insert($param, @opt);
1123
    }
1124
}
1125

            
- added EXPERIMENTAL update_...
Yuki Kimoto authored on 2011-09-12
1126
sub update_timestamp {
1127
    my $self = shift;
1128
    
1129
    if (@_) {
1130
        $self->{update_timestamp} = [@_];
1131
        
1132
        return $self;
1133
    }
1134
    return $self->{update_timestamp};
1135
}
1136

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1137
sub values_clause {
1138
    my ($self, $param, $opts) = @_;
1139
    
1140
    my $wrap = $opts->{wrap} || {};
1141
    
1142
    # Create insert parameter tag
micro optimization
Yuki Kimoto authored on 2011-10-23
1143
    my $safety = $self->{safety_character} || $self->safety_character;
improved performance
Yuki Kimoto authored on 2011-10-22
1144
    my $qp = $self->_q('');
fixed some quoted bug
Yuki Kimoto authored on 2011-10-22
1145
    my $q = substr($qp, 0, 1) || '';
1146
    my $p = substr($qp, 1, 1) || '';
improved performance
Yuki Kimoto authored on 2011-10-22
1147
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1148
    # Check unsafety keys
1149
    unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) {
1150
        for my $column (keys %$param) {
1151
            croak qq{"$column" is not safety column name } . _subname
1152
              unless $column =~ /^[$safety\.]+$/;
1153
        }
1154
    }
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1155
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1156
    # values clause(performance is important)
micro optimization
Yuki Kimoto authored on 2011-10-23
1157
    '(' .
1158
    join(
1159
      ', ',
1160
      map { "$q$_$p" } sort keys %$param
1161
    ) .
1162
    ') values (' .
1163
    join(
1164
      ', ',
1165
      map {
1166
          ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} :
1167
          $wrap->{$_} ? $wrap->{$_}->(":$_") :
1168
          ":$_";
1169
      } sort keys %$param
1170
    ) .
1171
    ')'
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1172
}
1173

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

            
updated pod
Yuki Kimoto authored on 2011-06-21
1176
sub _create_query {
cleanup
Yuki Kimoto authored on 2011-06-13
1177
    
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1178
    my ($self, $source, $after_build_sql) = @_;
cleanup
Yuki Kimoto authored on 2011-06-13
1179
    
updated pod
Yuki Kimoto authored on 2011-06-21
1180
    # Cache
1181
    my $cache = $self->cache;
1182
    
1183
    # Query
1184
    my $query;
1185
    
1186
    # Get cached query
1187
    if ($cache) {
cleanup
Yuki Kimoto authored on 2011-06-13
1188
        
updated pod
Yuki Kimoto authored on 2011-06-21
1189
        # Get query
1190
        my $q = $self->cache_method->($self, $source);
cleanup
Yuki Kimoto authored on 2011-06-13
1191
        
updated pod
Yuki Kimoto authored on 2011-06-21
1192
        # Create query
1193
        if ($q) {
1194
            $query = DBIx::Custom::Query->new($q);
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1195
            $query->{filters} = $self->filters;
cleanup
Yuki Kimoto authored on 2011-06-13
1196
        }
updated pod
Yuki Kimoto authored on 2011-06-21
1197
    }
1198
    
1199
    # Create query
1200
    unless ($query) {
1201

            
1202
        # Create query
1203
        my $builder = $self->query_builder;
1204
        $query = $builder->build_query($source);
1205

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

            
1212
        # Save query to cache
1213
        $self->cache_method->(
1214
            $self, $source,
1215
            {
1216
                sql     => $query->sql, 
1217
                columns => $query->columns,
DBIx::Custom::Query tables a...
Yuki Kimoto authored on 2011-07-30
1218
                tables  => $query->{tables} || []
updated pod
Yuki Kimoto authored on 2011-06-21
1219
            }
1220
        ) if $cache;
cleanup
Yuki Kimoto authored on 2011-06-13
1221
    }
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1222

            
1223
    # Filter SQL
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1224
    if ($after_build_sql) {
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1225
        my $sql = $query->sql;
sqlfilter option is renamed ...
Yuki Kimoto authored on 2011-09-16
1226
        $sql = $after_build_sql->($sql);
added EXPERIMENTAL execute m...
Yuki Kimoto authored on 2011-08-14
1227
        $query->sql($sql);
1228
    }
1229
        
added EXPERIMENTAL last_sql ...
Yuki Kimoto authored on 2011-07-11
1230
    # Save sql
1231
    $self->last_sql($query->sql);
1232
    
updated pod
Yuki Kimoto authored on 2011-06-21
1233
    # Prepare statement handle
1234
    my $sth;
added EXPERIMENTAL reuse_que...
Yuki Kimoto authored on 2011-10-22
1235
    eval { $sth = $self->dbh->prepare($query->{sql}) };
updated pod
Yuki Kimoto authored on 2011-06-21
1236
    
1237
    if ($@) {
1238
        $self->_croak($@, qq{. Following SQL is executed.\n}
1239
                        . qq{$query->{sql}\n} . _subname);
1240
    }
1241
    
1242
    # Set statement handle
1243
    $query->sth($sth);
1244
    
1245
    # Set filters
DBIx::Custom::Query filters ...
Yuki Kimoto authored on 2011-07-30
1246
    $query->{filters} = $self->filters;
updated pod
Yuki Kimoto authored on 2011-06-21
1247
    
1248
    return $query;
cleanup
Yuki Kimoto authored on 2011-06-13
1249
}
1250

            
cleanup
Yuki Kimoto authored on 2011-04-02
1251
sub _create_bind_values {
EXPERIMENTAL type_rule argum...
Yuki Kimoto authored on 2011-06-17
1252
    my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1253
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1254
    $bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY';
1255
    
cleanup
Yuki Kimoto authored on 2011-04-02
1256
    # Create bind values
micro optimization
Yuki Kimoto authored on 2011-10-23
1257
    my @bind;
1258
    my @types;
1259
    my %count;
1260
    my %not_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1261
    for my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
1262
        
micro optimization
Yuki Kimoto authored on 2011-10-23
1263
        # Bind value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1264
        if(ref $params->{$column} eq 'ARRAY') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1265
            my $i = $count{$column} || 0;
1266
            $i += $not_exists{$column} || 0;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1267
            my $found;
1268
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
1269
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1270
                    $not_exists{$column}++;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1271
                }
1272
                else  {
micro optimization
Yuki Kimoto authored on 2011-10-23
1273
                    push @bind, $params->{$column}->[$k];
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1274
                    $found = 1;
1275
                    last
1276
                }
1277
            }
1278
            next unless $found;
1279
        }
micro optimization
Yuki Kimoto authored on 2011-10-23
1280
        else { push @bind, $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
1281
        
cleanup
Yuki Kimoto authored on 2011-01-12
1282
        # Filter
micro optimization
Yuki Kimoto authored on 2011-10-23
1283
        if (my $f = $filter->{$column} || $self->{default_out_filter} || '') {
micro optimization
Yuki Kimoto authored on 2011-10-23
1284
            $bind[-1] = $f->($bind[-1]);
micro optimization
Yuki Kimoto authored on 2011-10-23
1285
        }
separate DBIx::Custom type_r...
Yuki Kimoto authored on 2011-06-15
1286
        
1287
        # Type rule
micro optimization
Yuki Kimoto authored on 2011-10-23
1288
        if ($self->{_type_rule_is_called}) {
1289
            my $tf1 = $self->{"_into1"}->{dot}->{$column}
1290
              || $type_filters->{1}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1291
            $bind[-1] = $tf1->($bind[-1]) if $tf1;
micro optimization
Yuki Kimoto authored on 2011-10-23
1292
            my $tf2 = $self->{"_into2"}->{dot}->{$column}
1293
              || $type_filters->{2}->{$column};
micro optimization
Yuki Kimoto authored on 2011-10-23
1294
            $bind[-1] = $tf2->($bind[-1]) if $tf2;
micro optimization
Yuki Kimoto authored on 2011-10-23
1295
        }
micro optimization
Yuki Kimoto authored on 2011-10-22
1296
       
micro optimization
Yuki Kimoto authored on 2011-10-23
1297
        # Bind types
micro optimization
Yuki Kimoto authored on 2011-10-23
1298
        push @types, $bind_type->{$column};
removed reconnect method
yuki-kimoto authored on 2010-05-28
1299
        
1300
        # Count up 
micro optimization
Yuki Kimoto authored on 2011-10-23
1301
        $count{$column}++;
removed reconnect method
yuki-kimoto authored on 2010-05-28
1302
    }
1303
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1304
    return (\@bind, \@types);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1305
}
1306

            
cleanup
Yuki Kimoto authored on 2011-10-21
1307
sub _id_to_param {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1308
    my ($self, $id, $primary_keys, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-21
1309
    
1310
    # Check primary key
cleanup
Yuki Kimoto authored on 2011-10-21
1311
    croak "primary_key option " .
1312
          "must be specified with id option " . _subname
1313
      unless defined $primary_keys;
1314
    $primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY';
improved error messages
Yuki Kimoto authored on 2011-04-18
1315
    
cleanup
Yuki Kimoto authored on 2011-06-08
1316
    # Create parameter
1317
    my $param = {};
fixed small insert, update, ...
Yuki Kimoto authored on 2011-06-21
1318
    if (defined $id) {
cleanup
Yuki Kimoto authored on 2011-06-08
1319
        $id = [$id] unless ref $id;
1320
        croak qq{"id" must be constant value or array reference}
improved error messages
Yuki Kimoto authored on 2011-04-18
1321
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1322
          unless !ref $id || ref $id eq 'ARRAY';
1323
        croak qq{"id" must contain values same count as primary key}
improved error messages
Yuki Kimoto authored on 2011-04-18
1324
            . " (" . (caller 1)[3] . ")"
cleanup
Yuki Kimoto authored on 2011-06-08
1325
          unless @$primary_keys eq @$id;
improved error messages
Yuki Kimoto authored on 2011-04-18
1326
        for(my $i = 0; $i < @$primary_keys; $i ++) {
fixed id option bug when col...
Yuki Kimoto authored on 2011-10-10
1327
           my $key = $primary_keys->[$i];
1328
           $key = "$table." . $key if $table;
1329
           $param->{$key} = $id->[$i];
improved error messages
Yuki Kimoto authored on 2011-04-18
1330
        }
1331
    }
1332
    
cleanup
Yuki Kimoto authored on 2011-06-08
1333
    return $param;
improved error messages
Yuki Kimoto authored on 2011-04-18
1334
}
1335

            
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1336
sub _connect {
1337
    my $self = shift;
1338
    
1339
    # Attributes
added warnings
Yuki Kimoto authored on 2011-06-07
1340
    my $dsn = $self->data_source;
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1341
    warn "data_source is DEPRECATED!\n"
fixed bug that data_source D...
Yuki Kimoto authored on 2011-06-13
1342
      if $dsn;
added warnings
Yuki Kimoto authored on 2011-06-07
1343
    $dsn ||= $self->dsn;
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1344
    croak qq{"dsn" must be specified } . _subname
1345
      unless $dsn;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1346
    my $user        = $self->user;
1347
    my $password    = $self->password;
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1348
    my $option = $self->_option;
1349
    $option = {%{$self->default_option}, %$option};
cleanup
Yuki Kimoto authored on 2011-08-16
1350
    
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1351
    # Connect
cleanup
Yuki Kimoto authored on 2011-08-16
1352
    my $dbh;
1353
    eval {
1354
        $dbh = DBI->connect(
1355
            $dsn,
1356
            $user,
1357
            $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1358
            $option
cleanup
Yuki Kimoto authored on 2011-08-16
1359
        );
1360
    };
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1361
    
1362
    # Connect error
cleanup
Yuki Kimoto authored on 2011-04-25
1363
    croak "$@ " . _subname if $@;
EXPERIMETAL fork safety impl...
Yuki Kimoto authored on 2011-03-12
1364
    
1365
    return $dbh;
1366
}
1367

            
cleanup
yuki-kimoto authored on 2010-10-17
1368
sub _croak {
1369
    my ($self, $error, $append) = @_;
cleanup
Yuki Kimoto authored on 2011-04-02
1370
    
1371
    # Append
cleanup
yuki-kimoto authored on 2010-10-17
1372
    $append ||= "";
1373
    
1374
    # Verbose
1375
    if ($Carp::Verbose) { croak $error }
1376
    
1377
    # Not verbose
1378
    else {
1379
        
1380
        # Remove line and module infromation
1381
        my $at_pos = rindex($error, ' at ');
1382
        $error = substr($error, 0, $at_pos);
1383
        $error =~ s/\s+$//;
1384
        croak "$error$append";
1385
    }
1386
}
1387

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

            
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1390
sub _need_tables {
1391
    my ($self, $tree, $need_tables, $tables) = @_;
1392
    
cleanup
Yuki Kimoto authored on 2011-04-02
1393
    # Get needed tables
cleanup
Yuki Kimoto authored on 2011-10-21
1394
    for my $table (@$tables) {
added select() all_column op...
Yuki Kimoto authored on 2011-03-12
1395
        if ($tree->{$table}) {
1396
            $need_tables->{$table} = 1;
1397
            $self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}])
1398
        }
1399
    }
1400
}
1401

            
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1402
sub _option {
1403
    my $self = shift;
1404
    my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}};
1405
    warn "dbi_options is DEPRECATED! use option instead\n"
1406
      if keys %{$self->dbi_options};
1407
    warn "dbi_option is DEPRECATED! use option instead\n"
1408
      if keys %{$self->dbi_option};
1409
    return $option;
1410
}
1411

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

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

            
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1483
sub _quote {
1484
    my $self = shift;
micro optimization
Yuki Kimoto authored on 2011-10-22
1485
    return $self->{reserved_word_quote} || $self->quote || '';
reserved_word_quote is DEPRE...
Yuki Kimoto authored on 2011-06-17
1486
}
1487

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

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

            
1524
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1525
}
1526

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1544
sub _where_clause_and_param {
cleanup
Yuki Kimoto authored on 2011-10-25
1545
    my ($self, $where, $where_param, $id, $primary_key, $table) = @_;
cleanup
Yuki Kimoto authored on 2011-10-25
1546

            
cleanup
Yuki Kimoto authored on 2011-10-21
1547
    $where ||= {};
cleanup
Yuki Kimoto authored on 2011-10-25
1548
    $where = $self->_id_to_param($id, $primary_key, $table) if defined $id;
cleanup
Yuki Kimoto authored on 2011-10-25
1549
    $where_param ||= {};
cleanup
Yuki Kimoto authored on 2011-10-21
1550
    my $w = {};
1551
    my $where_clause = '';
cleanup
Yuki Kimoto authored on 2011-10-25
1552

            
cleanup
Yuki Kimoto authored on 2011-10-25
1553
    my $obj;
1554
    
cleanup
Yuki Kimoto authored on 2011-10-21
1555
    if (ref $where eq 'ARRAY' && !ref $where->[0]) {
1556
        $w->{clause} = "where " . $where->[0];
1557
        $w->{param} = $where->[1];
1558
    }
1559
    elsif (ref $where) {
cleanup
Yuki Kimoto authored on 2011-10-25
1560

            
1561
        # Hash
1562
        if (ref $where eq 'HASH') {
1563
            my $clause = ['and'];
1564
            my $q = $self->_quote;
1565
            for my $column (keys %$where) {
1566
                my $table;
1567
                my $c;
1568
                if ($column =~ /(?:(.*?)\.)?(.*)/) {
1569
                    $table = $1;
1570
                    $c = $2;
1571
                }
1572
                
1573
                my $table_quote;
1574
                $table_quote = $self->_q($table) if defined $table;
1575
                my $column_quote = $self->_q($c);
1576
                $column_quote = $table_quote . '.' . $column_quote
1577
                  if defined $table_quote;
1578
                push @$clause, "$column_quote = :$column" for keys %$where;
1579
            }
1580
            $obj = $self->where(clause => $clause, param => $where);
1581
        }
1582
        
1583
        # DBIx::Custom::Where object
1584
        elsif (ref $where eq 'DBIx::Custom::Where') {
1585
            $obj = $where;
1586
        }
1587
        
1588
        # Array
1589
        elsif (ref $where eq 'ARRAY') {
1590
            $obj = $self->where(
1591
                clause => $where->[0],
1592
                param  => $where->[1]
1593
            );
1594
        }
1595
        
1596
        # Check where argument
1597
        croak qq{"where" must be hash reference or DBIx::Custom::Where object}
1598
            . qq{or array reference, which contains where clause and parameter}
1599
            . _subname
1600
          unless ref $obj eq 'DBIx::Custom::Where';
1601

            
1602

            
1603
        $w->{param} = keys %$where_param
1604
                    ? $self->merge_param($where_param, $obj->param)
1605
                    : $obj->param;
1606
        $w->{clause} = $obj->to_string;
cleanup
Yuki Kimoto authored on 2011-10-21
1607
    }
1608
    elsif ($where) {
1609
        $w->{clause} = "where $where";
cleanup
Yuki Kimoto authored on 2011-10-25
1610
        $w->{param} = $where_param;
cleanup
Yuki Kimoto authored on 2011-10-21
1611
    }
1612
    
1613
    return $w;
1614
}
1615

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

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

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1686
# DEPRECATED!
1687
has 'data_source';
1688
has dbi_options => sub { {} };
1689
has filter_check  => 1;
1690
has 'reserved_word_quote';
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1691
has dbi_option => sub { {} };
1692
has default_dbi_option => sub {
1693
    warn "default_dbi_option is DEPRECATED! use default_option instead";
1694
    return shift->default_option;
1695
};
1696

            
- method method of DBIx::Cus...
Yuki Kimoto authored on 2011-10-10
1697
# DEPRECATED!
1698
sub method {
1699
    warn "method is DEPRECATED! use helper instead";
1700
    return shift->helper(@_);
1701
}
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1702

            
1703
# DEPRECATED!
1704
sub assign_param {
1705
    my $self = shift;
1706
    warn "assing_param is DEPRECATED! use assign_clause instead";
1707
    return $self->assign_clause(@_);
1708
}
1709

            
1710
# DEPRECATED
1711
sub update_param {
1712
    my ($self, $param, $opts) = @_;
1713
    
micro optimization
Yuki Kimoto authored on 2011-10-23
1714
    warn "update_param is DEPRECATED! use assign_clause instead.";
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1715
    
1716
    # Create update parameter tag
1717
    my $tag = $self->assign_clause($param, $opts);
1718
    $tag = "set $tag" unless $opts->{no_set};
1719

            
1720
    return $tag;
1721
}
1722

            
updated pod
Yuki Kimoto authored on 2011-06-21
1723
# DEPRECATED!
1724
sub create_query {
1725
    warn "create_query is DEPRECATED! use query option of each method";
1726
    shift->_create_query(@_);
1727
}
1728

            
cleanup
Yuki Kimoto authored on 2011-06-13
1729
# DEPRECATED!
1730
sub apply_filter {
1731
    my $self = shift;
1732
    
- added EXPERIMENTAL order m...
Yuki Kimoto authored on 2011-06-28
1733
    warn "apply_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-06-13
1734
    return $self->_apply_filter(@_);
1735
}
1736

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1743
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1744
    my $primary_keys = delete $opt{primary_key};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1745
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1746
    my $where = delete $opt{where};
1747
    my $param = delete $opt{param};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1748
    
1749
    # Table
1750
    croak qq{"table" option must be specified } . _subname
cleanup
Yuki Kimoto authored on 2011-10-21
1751
      unless $opt{table};
1752
    my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table};
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1753
    
1754
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1755
    my $where_param = $self->_id_to_param($where, $primary_keys);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1756
    
cleanup
Yuki Kimoto authored on 2011-10-21
1757
    return $self->select(where => $where_param, %opt);
select_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1758
}
1759

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1764
    warn "delete_at is DEPRECATED! use delete method id option instead";
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1765
    
cleanup
Yuki Kimoto authored on 2011-10-21
1766
    # Options
cleanup
Yuki Kimoto authored on 2011-10-21
1767
    my $primary_keys = delete $opt{primary_key};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1768
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1769
    my $where = delete $opt{where};
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1770
    
1771
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1772
    my $where_param = $self->_id_to_param($where, $primary_keys);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1773
    
cleanup
Yuki Kimoto authored on 2011-10-21
1774
    return $self->delete(where => $where_param, %opt);
delete_at is DEPRECATED! use...
Yuki Kimoto authored on 2011-06-08
1775
}
1776

            
cleanup
Yuki Kimoto authored on 2011-06-08
1777
# DEPRECATED!
1778
sub update_at {
1779
    my $self = shift;
1780

            
cleanup
Yuki Kimoto authored on 2011-10-21
1781
    warn "update_at is DEPRECATED! use update method id option instead";
cleanup
Yuki Kimoto authored on 2011-06-08
1782
    
cleanup
Yuki Kimoto authored on 2011-10-21
1783
    # Options
cleanup
Yuki Kimoto authored on 2011-06-08
1784
    my $param;
1785
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1786
    my %opt = @_;
1787
    my $primary_keys = delete $opt{primary_key};
cleanup
Yuki Kimoto authored on 2011-06-08
1788
    $primary_keys = [$primary_keys] unless ref $primary_keys;
cleanup
Yuki Kimoto authored on 2011-10-21
1789
    my $where = delete $opt{where};
1790
    my $p = delete $opt{param} || {};
cleanup
Yuki Kimoto authored on 2011-06-08
1791
    $param  ||= $p;
1792
    
1793
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1794
    my $where_param = $self->_id_to_param($where, $primary_keys);
cleanup
Yuki Kimoto authored on 2011-06-08
1795
    
cleanup
Yuki Kimoto authored on 2011-10-21
1796
    return $self->update(where => $where_param, param => $param, %opt);
cleanup
Yuki Kimoto authored on 2011-06-08
1797
}
1798

            
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1799
# DEPRECATED!
1800
sub insert_at {
1801
    my $self = shift;
1802
    
cleanup
Yuki Kimoto authored on 2011-10-21
1803
    warn "insert_at is DEPRECATED! use insert method id option instead";
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1804
    
cleanup
Yuki Kimoto authored on 2011-10-21
1805
    # Options
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1806
    my $param;
1807
    $param = shift if @_ % 2;
cleanup
Yuki Kimoto authored on 2011-10-21
1808
    my %opt = @_;
1809
    my $primary_key = delete $opt{primary_key};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1810
    $primary_key = [$primary_key] unless ref $primary_key;
cleanup
Yuki Kimoto authored on 2011-10-21
1811
    my $where = delete $opt{where};
1812
    my $p = delete $opt{param} || {};
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1813
    $param  ||= $p;
1814
    
1815
    # Create where parameter
cleanup
Yuki Kimoto authored on 2011-10-21
1816
    my $where_param = $self->_id_to_param($where, $primary_key);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1817
    $param = $self->merge_param($where_param, $param);
1818
    
cleanup
Yuki Kimoto authored on 2011-10-21
1819
    return $self->insert(param => $param, %opt);
insert_at is DEPRECATED! add...
Yuki Kimoto authored on 2011-06-08
1820
}
1821

            
added warnings
Yuki Kimoto authored on 2011-06-07
1822
# DEPRECATED!
1823
sub register_tag {
test cleanup
Yuki Kimoto authored on 2011-08-10
1824
    my $self = shift;
1825
    
added warnings
Yuki Kimoto authored on 2011-06-07
1826
    warn "register_tag is DEPRECATED!";
test cleanup
Yuki Kimoto authored on 2011-08-10
1827
    
1828
    # Merge tag
1829
    my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1830
    $self->{_tags} = {%{$self->{_tags} || {}}, %$tags};
1831
    
1832
    return $self;
1833
}
1834

            
1835
# DEPRECATED!
1836
sub register_tag_processor {
1837
    my $self = shift;
1838
    warn "register_tag_processor is DEPRECATED!";
1839
    # Merge tag
1840
    my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_};
1841
    $self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}};
1842
    return $self;
added warnings
Yuki Kimoto authored on 2011-06-07
1843
}
1844

            
cleanup
Yuki Kimoto authored on 2011-01-25
1845
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1846
sub default_bind_filter {
1847
    my $self = shift;
1848
    
cleanup
Yuki Kimoto authored on 2011-06-13
1849
    warn "default_bind_filter is DEPRECATED!";
added warnings
Yuki Kimoto authored on 2011-06-07
1850
    
cleanup
Yuki Kimoto authored on 2011-01-12
1851
    if (@_) {
1852
        my $fname = $_[0];
1853
        
1854
        if (@_ && !$fname) {
1855
            $self->{default_out_filter} = undef;
1856
        }
1857
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1858
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1859
              unless exists $self->filters->{$fname};
1860
        
1861
            $self->{default_out_filter} = $self->filters->{$fname};
1862
        }
1863
        return $self;
1864
    }
1865
    
1866
    return $self->{default_out_filter};
1867
}
1868

            
cleanup
Yuki Kimoto authored on 2011-01-25
1869
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1870
sub default_fetch_filter {
1871
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1872

            
cleanup
Yuki Kimoto authored on 2011-06-13
1873
    warn "default_fetch_filter is DEPRECATED!";
cleanup
Yuki Kimoto authored on 2011-01-12
1874
    
1875
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1876
        my $fname = $_[0];
1877

            
cleanup
Yuki Kimoto authored on 2011-01-12
1878
        if (@_ && !$fname) {
1879
            $self->{default_in_filter} = undef;
1880
        }
1881
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1882
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1883
              unless exists $self->filters->{$fname};
1884
        
1885
            $self->{default_in_filter} = $self->filters->{$fname};
1886
        }
1887
        
1888
        return $self;
1889
    }
1890
    
many changed
Yuki Kimoto authored on 2011-01-23
1891
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1892
}
1893

            
- update_param is DEPRECATED...
Yuki Kimoto authored on 2011-10-04
1894
# DEPRECATED!
1895
sub insert_param {
1896
    my $self = shift;
1897
    warn "insert_param is DEPRECATED! use values_clause instead";
1898
    return $self->values_clause(@_);
1899
}
1900

            
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1901
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1902
sub insert_param_tag {
1903
    warn "insert_param_tag is DEPRECATED! " .
1904
         "use insert_param instead!";
1905
    return shift->insert_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1906
}
1907

            
1908
# DEPRECATED!
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1909
sub update_param_tag {
fixed DEPRECATED message bug
Yuki Kimoto authored on 2011-06-10
1910
    warn "update_param_tag is DEPRECATED! " .
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
1911
         "use update_param instead";
1912
    return shift->update_param(@_);
- renamed update_param to up...
Yuki Kimoto authored on 2011-03-30
1913
}
cleanup
Yuki Kimoto authored on 2011-03-08
1914
# DEPRECATED!
1915
sub _push_relation {
1916
    my ($self, $sql, $tables, $relation, $need_where) = @_;
1917
    
1918
    if (keys %{$relation || {}}) {
micro optimization
Yuki Kimoto authored on 2011-09-30
1919
        $$sql .= $need_where ? 'where ' : 'and ';
cleanup
Yuki Kimoto authored on 2011-10-21
1920
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1921
            my $table1 = (split (/\./, $rcolumn))[0];
1922
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1923
            push @$tables, ($table1, $table2);
micro optimization
Yuki Kimoto authored on 2011-09-30
1924
            $$sql .= "$rcolumn = " . $relation->{$rcolumn} .  'and ';
cleanup
Yuki Kimoto authored on 2011-03-08
1925
        }
1926
    }
micro optimization
Yuki Kimoto authored on 2011-09-30
1927
    $$sql =~ s/and $/ /;
cleanup
Yuki Kimoto authored on 2011-03-08
1928
}
1929

            
1930
# DEPRECATED!
1931
sub _add_relation_table {
cleanup
Yuki Kimoto authored on 2011-03-09
1932
    my ($self, $tables, $relation) = @_;
cleanup
Yuki Kimoto authored on 2011-03-08
1933
    
1934
    if (keys %{$relation || {}}) {
cleanup
Yuki Kimoto authored on 2011-10-21
1935
        for my $rcolumn (keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-03-08
1936
            my $table1 = (split (/\./, $rcolumn))[0];
1937
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
1938
            my $table1_exists;
1939
            my $table2_exists;
cleanup
Yuki Kimoto authored on 2011-10-21
1940
            for my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-03-08
1941
                $table1_exists = 1 if $table eq $table1;
1942
                $table2_exists = 1 if $table eq $table2;
1943
            }
1944
            unshift @$tables, $table1 unless $table1_exists;
1945
            unshift @$tables, $table2 unless $table2_exists;
1946
        }
1947
    }
1948
}
1949

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1952
=head1 NAME
1953

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

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

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1958
    use DBIx::Custom;
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1959
    
1960
    # Connect
1961
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
1962
        dsn => "dbi:mysql:database=dbname",
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1963
        user => 'ken',
1964
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
1965
        option => {mysql_enable_utf8 => 1}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1966
    );
cleanup
yuki-kimoto authored on 2010-08-05
1967

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1968
    # Insert 
updated pod
Yuki Kimoto authored on 2011-06-21
1969
    $dbi->insert({title => 'Perl', author => 'Ken'}, table  => 'book');
removed reconnect method
yuki-kimoto authored on 2010-05-28
1970
    
1971
    # Update 
updated pod
Yuki Kimoto authored on 2011-06-21
1972
    $dbi->update({title => 'Perl', author => 'Ken'}, table  => 'book',
1973
      where  => {id => 5});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1974
    
1975
    # Delete
updated pod
Yuki Kimoto authored on 2011-06-21
1976
    $dbi->delete(table  => 'book', where => {author => 'Ken'});
cleanup
yuki-kimoto authored on 2010-08-05
1977

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1982
    # Select, more complex
1983
    my $result = $dbi->select(
1984
        table  => 'book',
1985
        column => [
cleanup
Yuki Kimoto authored on 2011-06-13
1986
            {book => [qw/title author/]},
1987
            {company => ['name']}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1988
        ],
1989
        where  => {'book.author' => 'Ken'},
1990
        join => ['left outer join company on book.company_id = company.id'],
1991
        append => 'order by id limit 5'
removed reconnect method
yuki-kimoto authored on 2010-05-28
1992
    );
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1993
    
removed register_format()
yuki-kimoto authored on 2010-05-26
1994
    # Fetch
1995
    while (my $row = $result->fetch) {
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1996
        
removed register_format()
yuki-kimoto authored on 2010-05-26
1997
    }
1998
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
1999
    # Fetch as hash
removed register_format()
yuki-kimoto authored on 2010-05-26
2000
    while (my $row = $result->fetch_hash) {
2001
        
2002
    }
2003
    
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2004
    # Execute SQL with parameter.
2005
    $dbi->execute(
- update_param_tag is DEPREC...
Yuki Kimoto authored on 2011-06-07
2006
        "select id from book where author = :author and title like :title",
updated pod
Yuki Kimoto authored on 2011-06-21
2007
        {author => 'ken', title => '%Perl%'}
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2008
    );
2009
    
fix heading typos
Terrence Brannon authored on 2011-08-17
2010
=head1 DESCRIPTION
removed reconnect method
yuki-kimoto authored on 2010-05-28
2011

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2027
Named place holder support
2028

            
2029
=item *
2030

            
cleanup
Yuki Kimoto authored on 2011-07-29
2031
Model support
2032

            
2033
=item *
2034

            
2035
Connection manager support
2036

            
2037
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2038

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

            
2043
=item *
2044

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

            
2047
=item *
2048

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

            
2051
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2052

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2060
Module documentations - 
cleanup
Yuki Kimoto authored on 2011-07-29
2061
L<DBIx::Custom::Result>,
2062
L<DBIx::Custom::Query>,
2063
L<DBIx::Custom::Where>,
2064
L<DBIx::Custom::Model>,
2065
L<DBIx::Custom::Order>
updated document
yuki-kimoto authored on 2010-08-08
2066

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

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

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

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

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

            
2080
    my $connector = DBIx::Connector->new(
cleanup
Yuki Kimoto authored on 2011-08-16
2081
        "dbi:mysql:database=$database",
2082
        $user,
2083
        $password,
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2084
        DBIx::Custom->new->default_option
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2085
    );
2086
    
updated pod
Yuki Kimoto authored on 2011-06-21
2087
    my $dbi = DBIx::Custom->connect(connector => $connector);
- removed EXPERIMENTAL Prefo...
Yuki Kimoto authored on 2011-04-04
2088

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

            
2092
    my $dbi = DBIx::Custom->connect(
2093
      dsn => $dsn, user => $user, password => $password, connector => 1);
2094
    
2095
    my $connector = $dbi->connector; # DBIx::Connector
2096

            
2097
Note that L<DBIx::Connector> must be installed.
2098

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

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

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

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

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

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

            
- remaned experimental safty...
Yuki Kimoto authored on 2011-03-10
2114
    {
2115
        RaiseError => 1,
2116
        PrintError => 0,
2117
        AutoCommit => 1,
2118
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
2119

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

            
2122
    my $exclude_table = $dbi->exclude_table;
2123
    $dbi = $dbi->exclude_table(qr/pg_/);
2124

            
2125
Excluded table regex.
2126
C<each_column>, C<each_table>, C<type_rule>,
2127
and C<setup_model> methods ignore matching tables.
2128

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

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

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

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

            
2138
    my $last_sql = $dbi->last_sql;
2139
    $dbi = $dbi->last_sql($last_sql);
2140

            
2141
Get last successed SQL executed by C<execute> method.
2142

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

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

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

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

            
2152
    my $option = $dbi->option;
2153
    $dbi = $dbi->option($option);
2154

            
2155
L<DBI> option, used when C<connect> method is executed.
2156
Each value in option override the value of C<default_option>.
2157

            
cleanup
yuki-kimoto authored on 2010-10-17
2158
=head2 C<password>
2159

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2180
You can set quote pair.
2181

            
2182
    $dbi->quote('[]');
2183

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2193
    my $safety_character = $dbi->safety_character;
2194
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2195

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

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

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

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

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

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

            
2212
    my $tag_parse = $dbi->tag_parse(0);
2213
    $dbi = $dbi->tag_parse;
2214

            
2215
Enable DEPRECATED tag parsing functionality, default to 1.
2216
If you want to disable tag parsing functionality, set to 0.
2217

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

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

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

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

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

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

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

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

            
2239
    my $user_column_info
2240
      = $dbi->get_column_info(exclude_table => qr/^system/);
2241
    $dbi->user_column_info($user_column_info);
2242

            
2243
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
2244
to find column info. this is very fast.
- added EXPERIMENTAL get_col...
Yuki Kimoto authored on 2011-08-16
2245

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

            
2248
    my $user_table_info = $dbi->user_table_info;
2249
    $dbi = $dbi->user_table_info($user_table_info);
2250

            
2251
You can set the following data.
2252

            
2253
    [
2254
        {table => 'book', info => {...}},
2255
        {table => 'author', info => {...}}
2256
    ]
2257

            
2258
Usually, you can set return value of C<get_table_info>.
2259

            
2260
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2261
    $dbi->user_table_info($user_table_info);
2262

            
2263
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2264
to find table info.
2265

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2302
Create column clause. The follwoing column clause is created.
2303

            
2304
    book.author as "book.author",
2305
    book.title as "book.title"
2306

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

            
cleanup
Yuki Kimoto authored on 2011-06-13
2309
    # Separator is hyphen
2310
    $dbi->separator('-');
2311
    
2312
    book.author as "book-author",
2313
    book.title as "book-title"
2314
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
2315
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
2316

            
update pod
Yuki Kimoto authored on 2011-03-13
2317
    my $dbi = DBIx::Custom->connect(
data_source is DEPRECATED! I...
Yuki Kimoto authored on 2011-06-06
2318
        dsn => "dbi:mysql:database=dbname",
update pod
Yuki Kimoto authored on 2011-03-13
2319
        user => 'ken',
2320
        password => '!LFKD%$&',
- dbi_option attribute is re...
Yuki Kimoto authored on 2011-10-05
2321
        option => {mysql_enable_utf8 => 1}
update pod
Yuki Kimoto authored on 2011-03-13
2322
    );
2323

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

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

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

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

            
2334
Get rows count.
2335

            
2336
Options is same as C<select> method's ones.
2337

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

            
adeed EXPERIMENTAL DBIx::Cus...
Yuki Kimoto authored on 2011-03-29
2340
    my $model = $dbi->create_model(
removed EXPERIMETNAL flag fr...
Yuki Kimoto authored on 2011-03-25
2341
        table => 'book',
2342
        primary_key => 'id',
2343
        join => [
2344
            'inner join company on book.comparny_id = company.id'
2345
        ],
2346
    );
2347

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

            
2351
   $dbi->model('book')->select(...);
2352

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

            
2355
    my $dbh = $dbi->dbh;
2356

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

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

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

            
2364
Execute delete statement.
2365

            
2366
The following opitons are available.
2367

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

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

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

            
2375
=item C<id>
2376

            
2377
    id => 4
2378
    id => [4, 5]
2379

            
2380
ID corresponding to C<primary_key>.
2381
You can delete rows by C<id> and C<primary_key>.
2382

            
2383
    $dbi->delete(
fixed pod
Yuki Kimoto authored on 2011-10-20
2384
        primary_key => ['id1', 'id2'],
added EXPERIMENTAL find_tabl...
Yuki Kimoto authored on 2011-08-16
2385
        id => [4, 5],
2386
        table => 'book',
2387
    );
2388

            
2389
The above is same as the followin one.
2390

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

            
2393
=item C<prefix>
2394

            
2395
    prefix => 'some'
2396

            
2397
prefix before table name section.
2398

            
2399
    delete some from book
2400

            
2401
=item C<table>
2402

            
2403
    table => 'book'
2404

            
2405
Table name.
2406

            
2407
=item C<where>
2408

            
2409
Same as C<select> method's C<where> option.
2410

            
2411
=back
2412

            
2413
=head2 C<delete_all>
2414

            
2415
    $dbi->delete_all(table => $table);
2416

            
2417
Execute delete statement for all rows.
2418
Options is same as C<delete>.
2419

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

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

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

            
2439
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2440
infromation, you can improve the performance of C<each_column> in
2441
the following way.
2442

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

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

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

            
improved pod
Yuki Kimoto authored on 2011-10-14
2457
Iterate all table informationsfrom in database.
2458
Argument is callback which is executed when one table is found.
2459
Callback receive three arguments, C<DBIx::Custom object>, C<table name>,
2460
C<table information>.
2461

            
2462
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2463
infromation, you can improve the performance of C<each_table> in
2464
the following way.
2465

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

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

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

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

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

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

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

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

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

            
2509
    select * from where title = "aa\\:bb";
2510

            
cleanup
Yuki Kimoto authored on 2011-10-20
2511
B<OPTIONS>
2512

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

            
2515
=over 4
2516

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

            
2519
You can filter sql after the sql is build.
2520

            
2521
    after_build_sql => $code_ref
2522

            
2523
The following one is one example.
2524

            
2525
    $dbi->select(
2526
        table => 'book',
2527
        column => 'distinct(name)',
2528
        after_build_sql => sub {
2529
            "select count(*) from ($_[0]) as t1"
2530
        }
2531
    );
2532

            
2533
The following SQL is executed.
2534

            
2535
    select count(*) from (select distinct(name) from book) as t1;
2536

            
cleanup
Yuki Kimoto authored on 2011-10-20
2537
=item C<append>
2538

            
2539
    append => 'order by name'
2540

            
2541
Append some statement after SQL.
2542

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

            
2545
Specify database bind data type.
2546

            
2547
    bind_type => [image => DBI::SQL_BLOB]
2548
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2549

            
2550
This is used to bind parameter by C<bind_param> of statment handle.
2551

            
2552
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2553

            
update pod
Yuki Kimoto authored on 2011-03-13
2554
=item C<filter>
updated pod
Yuki Kimoto authored on 2011-06-09
2555
    
2556
    filter => {
2557
        title  => sub { uc $_[0] }
2558
        author => sub { uc $_[0] }
2559
    }
update pod
Yuki Kimoto authored on 2011-03-13
2560

            
updated pod
Yuki Kimoto authored on 2011-06-09
2561
    # Filter name
2562
    filter => {
2563
        title  => 'upper_case',
2564
        author => 'upper_case'
2565
    }
2566
        
2567
    # At once
2568
    filter => [
2569
        [qw/title author/]  => sub { uc $_[0] }
2570
    ]
2571

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

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

            
2579
    id => 4
2580
    id => [4, 5]
2581

            
2582
ID corresponding to C<primary_key>.
2583
You can delete rows by C<id> and C<primary_key>.
2584

            
2585
    $dbi->execute(
2586
        "select * from book where id1 = :id1 and id2 = :id2",
2587
        {},
fixed pod
Yuki Kimoto authored on 2011-10-20
2588
        primary_key => ['id1', 'id2'],
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2589
        id => [4, 5],
2590
    );
2591

            
2592
The above is same as the followin one.
2593

            
2594
    $dbi->execute(
2595
        "select * from book where id1 = :id1 and id2 = :id2",
2596
        {id1 => 4, id2 => 5}
2597
    );
2598

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

            
2601
    query => 1
2602

            
2603
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL.
micro optimization and
Yuki Kimoto authored on 2011-10-25
2604
You can check SQL, column, or get statment handle.
updated pod
Yuki Kimoto authored on 2011-06-21
2605

            
2606
    my $sql = $query->sql;
cleanup
Yuki Kimoto authored on 2011-07-30
2607
    my $sth = $query->sth;
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2608
    my $columns = $query->columns;
2609
    
- removed placeholder count ...
Yuki Kimoto authored on 2011-08-22
2610
=item C<primary_key>
2611

            
cleanup
Yuki Kimoto authored on 2011-10-20
2612
    primary_key => 'id'
2613
    primary_key => ['id1', 'id2']
2614

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

            
updated pod
Yuki Kimoto authored on 2011-06-09
2617
=item C<table>
2618
    
2619
    table => 'author'
2620

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

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

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

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

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

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

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

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

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

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

            
2655
    type_rule_off => 1
2656

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

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

            
2661
    type_rule1_off => 1
2662

            
2663
Turn C<into1> type rule off.
2664

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

            
2667
    type_rule2_off => 1
2668

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

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

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

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

            
2677
get column infomation except for one which match C<exclude_table> pattern.
2678

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

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

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

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

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

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

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

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

            
2712
Register helper. These helper is called directly from L<DBIx::Custom> object.
2713

            
2714
    $dbi->update_or_insert;
2715
    $dbi->find_or_create;
2716

            
cleanup
yuki-kimoto authored on 2010-10-17
2717
=head2 C<insert>
2718

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

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

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

            
2727
    {date => \"NOW()"}
2728

            
cleanup
Yuki Kimoto authored on 2011-10-20
2729
B<options>
2730

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

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

            
added EXPERIMENTAL execute()...
Yuki Kimoto authored on 2011-06-09
2736
=item C<id>
2737

            
updated document
Yuki Kimoto authored on 2011-06-09
2738
    id => 4
2739
    id => [4, 5]
update pod
Yuki Kimoto authored on 2011-03-13
2740

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

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

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

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

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

            
2760
    prefix => 'or replace'
2761

            
2762
prefix before table name section
2763

            
2764
    insert or replace into book
2765

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

            
2768
    table => 'book'
2769

            
2770
Table name.
2771

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

            
2774
    timestamp => 1
2775

            
2776
If this value is set to 1,
2777
automatically created timestamp column is set based on
2778
C<timestamp> attribute's C<insert> value.
2779

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

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

            
2784
placeholder wrapped string.
2785

            
2786
If the following statement
2787

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

            
2791
is executed, the following SQL is executed.
2792

            
2793
    insert into book price values ( ? + 5 );
2794

            
update pod
Yuki Kimoto authored on 2011-03-13
2795
=back
2796

            
2797
=over 4
2798

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2862
    my $like_value = $dbi->like_value
2863

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

            
2866
    sub { "%$_[0]%" }
2867

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

            
2870
    my $mapper = $dbi->mapper(param => $param);
2871

            
2872
Create a new L<DBIx::Custom::Mapper> object.
2873

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

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

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

            
2880
    {key1 => [1, 1], key2 => 2}
2881

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

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

            
2886
    my $model = $dbi->model('book');
2887

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

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

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

            
2895
Create column clause for myself. The follwoing column clause is created.
2896

            
2897
    book.author as author,
2898
    book.title as title
2899

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

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

            
2909
Create a new L<DBIx::Custom> object.
2910

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

            
2913
    my $not_exists = $dbi->not_exists;
2914

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

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

            
2920
    my $order = $dbi->order;
2921

            
2922
Create a new L<DBIx::Custom::Order> object.
2923

            
cleanup
yuki-kimoto authored on 2010-10-17
2924
=head2 C<register_filter>
2925

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

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

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

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

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

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

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

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

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

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

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

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

            
2978
    book.author as "book.author",
2979
    book.title as "book.title",
2980
    person.name as "person.name",
2981
    person.age as "person.age"
2982

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

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

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

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

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

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

            
2998
=item C<id>
2999

            
3000
    id => 4
3001
    id => [4, 5]
3002

            
3003
ID corresponding to C<primary_key>.
3004
You can select rows by C<id> and C<primary_key>.
3005

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

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

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

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

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

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

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

            
3033
    prefix => 'SQL_CALC_FOUND_ROWS'
3034

            
3035
Prefix of column cluase
3036

            
3037
    select SQL_CALC_FOUND_ROWS title, author from book;
3038

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

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

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

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

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

            
added join new syntax
Yuki Kimoto authored on 2011-07-28
3067
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
3068
the join clause correctly.
added join new syntax
Yuki Kimoto authored on 2011-07-28
3069

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3086
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3087

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

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

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

            
3120
    $dbi->setup_model;
3121

            
3122
Setup all model objects.
3123
C<columns> of model object is automatically set, parsing database information.
3124

            
3125
=head2 C<type_rule>
3126

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

            
3150
Filtering rule when data is send into and get from database.
3151
This has a little complex problem.
3152

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

            
3157
Note that type name and data type don't contain upper case.
3158
If these contain upper case charactor, you convert it to lower case.
3159

            
3160
C<into2> is executed after C<into1>.
3161

            
3162
Type rule of C<into1> and C<into2> is enabled on the following
3163
column name.
3164

            
3165
=over 4
3166

            
3167
=item 1. column name
3168

            
3169
    issue_date
3170
    issue_datetime
3171

            
3172
This need C<table> option in each method.
3173

            
3174
=item 2. table name and column name, separator is dot
3175

            
3176
    book.issue_date
3177
    book.issue_datetime
3178

            
3179
=back
3180

            
3181
You get all type name used in database by C<available_typename>.
3182

            
3183
    print $dbi->available_typename;
3184

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

            
3189
    print $dbi->available_datatype;
3190

            
3191
You can also specify multiple types at once.
3192

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

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

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

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

            
3205
If you want to set constant value to row data, use scalar reference
3206
as parameter value.
3207

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3219
    id => 4
3220
    id => [4, 5]
- insert, insert_at, update,...
Yuki Kimoto authored on 2011-06-08
3221

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

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

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

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

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

            
3242
    prefix => 'or replace'
3243

            
3244
prefix before table name section
3245

            
3246
    update or replace book
3247

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

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

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

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

            
3256
    timestamp => 1
3257

            
3258
If this value is set to 1,
3259
automatically updated timestamp column is set based on
3260
C<timestamp> attribute's C<update> value.
3261

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

            
3264
Same as C<select> method's C<where> option.
3265

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

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

            
3270
placeholder wrapped string.
3271

            
3272
If the following statement
3273

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

            
3277
is executed, the following SQL is executed.
3278

            
3279
    update book set price =  ? + 5;
3280

            
updated pod
Yuki Kimoto authored on 2011-06-08
3281
=back
update pod
Yuki Kimoto authored on 2011-03-13
3282

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

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

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

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

            
3311
In both examples, the following SQL is executed.
3312

            
3313
    # In case insert
3314
    insert into book (id, title) values (?, ?)
3315
    
3316
    # In case update
3317
    update book set (id = ?, title = ?) where book.id = ?
3318

            
3319
The following opitons are available adding to C<update> option.
3320

            
3321
=over 4
3322

            
3323
=item C<select_option>
3324

            
3325
    select_option => {append => 'for update'}
3326

            
3327
select method option,
3328
select method is used to check the row is already exists.
3329

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

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

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

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

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

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

            
3350
    $dbi->show_datatype($table);
3351

            
3352
Show data type of the columns of specified table.
3353

            
3354
    book
3355
    title: 5
3356
    issue_date: 91
3357

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

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

            
3362
    $dbi->show_tables;
3363

            
3364
Show tables.
3365

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

            
3368
    $dbi->show_typename($table);
3369

            
3370
Show type name of the columns of specified table.
3371

            
3372
    book
3373
    title: varchar
3374
    issue_date: date
3375

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

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

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

            
3382
Create values clause.
3383

            
3384
    (title, author) values (title = :title, age = :age);
3385

            
3386
You can use this in insert statement.
3387

            
3388
    my $insert_sql = "insert into book $values_clause";
3389

            
3390
=head2 C<where>
3391

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

            
3397
Create a new L<DBIx::Custom::Where> object.
3398

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

            
3401
=head2 C<DBIX_CUSTOM_DEBUG>
3402

            
3403
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true,
3404
executed SQL and bind values are printed to STDERR.
3405

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

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

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

            
3412
L<DBIx::Custom>
3413

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

            
3461
L<DBIx::Custom::Model>
3462

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

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

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

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

            
3504
L<DBIx::Custom::Tag>
3505

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

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

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

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

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

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

            
3523
C<< <kimoto.yuki at gmail.com> >>
3524

            
3525
L<http://github.com/yuki-kimoto/DBIx-Custom>
3526

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3527
=head1 AUTHOR
3528

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

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

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

            
3535
This program is free software; you can redistribute it and/or modify it
3536
under the same terms as Perl itself.
3537

            
3538
=cut