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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1604

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

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

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

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

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

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

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

            
1722
    return $tag;
1723
}
1724

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1954
=head1 NAME
1955

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2029
Named place holder support
2030

            
2031
=item *
2032

            
cleanup
Yuki Kimoto authored on 2011-07-29
2033
Model support
2034

            
2035
=item *
2036

            
2037
Connection manager support
2038

            
2039
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2040

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

            
2045
=item *
2046

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

            
2049
=item *
2050

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

            
2053
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2054

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

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

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

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

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

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

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

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

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

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

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

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

            
2099
Note that L<DBIx::Connector> must be installed.
2100

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

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

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

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

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

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

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

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

            
2124
    my $exclude_table = $dbi->exclude_table;
2125
    $dbi = $dbi->exclude_table(qr/pg_/);
2126

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

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

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

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

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

            
2140
    my $last_sql = $dbi->last_sql;
2141
    $dbi = $dbi->last_sql($last_sql);
2142

            
2143
Get last successed SQL executed by C<execute> method.
2144

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

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

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

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

            
2154
    my $option = $dbi->option;
2155
    $dbi = $dbi->option($option);
2156

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

            
cleanup
yuki-kimoto authored on 2010-10-17
2160
=head2 C<password>
2161

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2182
You can set quote pair.
2183

            
2184
    $dbi->quote('[]');
2185

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

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

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

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

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

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

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

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

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

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

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

            
2214
    my $tag_parse = $dbi->tag_parse(0);
2215
    $dbi = $dbi->tag_parse;
2216

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

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

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

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

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

            
2229
    my $user_column_info = $dbi->user_column_info;
2230
    $dbi = $dbi->user_column_info($user_column_info);
2231

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

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

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

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

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

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

            
2250
    my $user_table_info = $dbi->user_table_info;
2251
    $dbi = $dbi->user_table_info($user_table_info);
2252

            
2253
You can set the following data.
2254

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

            
2260
Usually, you can set return value of C<get_table_info>.
2261

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2304
Create column clause. The follwoing column clause is created.
2305

            
2306
    book.author as "book.author",
2307
    book.title as "book.title"
2308

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

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

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

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

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

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

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

            
2336
Get rows count.
2337

            
2338
Options is same as C<select> method's ones.
2339

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

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

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

            
2353
   $dbi->model('book')->select(...);
2354

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

            
2357
    my $dbh = $dbi->dbh;
2358

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

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

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

            
2366
Execute delete statement.
2367

            
2368
The following opitons are available.
2369

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

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

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

            
2377
=item C<id>
2378

            
2379
    id => 4
2380
    id => [4, 5]
2381

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

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

            
2391
The above is same as the followin one.
2392

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

            
2395
=item C<prefix>
2396

            
2397
    prefix => 'some'
2398

            
2399
prefix before table name section.
2400

            
2401
    delete some from book
2402

            
2403
=item C<table>
2404

            
2405
    table => 'book'
2406

            
2407
Table name.
2408

            
2409
=item C<where>
2410

            
2411
Same as C<select> method's C<where> option.
2412

            
2413
=back
2414

            
2415
=head2 C<delete_all>
2416

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-20
2513
B<OPTIONS>
2514

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

            
2517
=over 4
2518

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

            
2521
You can filter sql after the sql is build.
2522

            
2523
    after_build_sql => $code_ref
2524

            
2525
The following one is one example.
2526

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

            
2535
The following SQL is executed.
2536

            
2537
    select count(*) from (select distinct(name) from book) as t1;
2538

            
cleanup
Yuki Kimoto authored on 2011-10-20
2539
=item C<append>
2540

            
2541
    append => 'order by name'
2542

            
2543
Append some statement after SQL.
2544

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

            
2547
Specify database bind data type.
2548

            
2549
    bind_type => [image => DBI::SQL_BLOB]
2550
    bind_type => [[qw/image audio/] => DBI::SQL_BLOB]
2551

            
2552
This is used to bind parameter by C<bind_param> of statment handle.
2553

            
2554
    $sth->bind_param($pos, $value, DBI::SQL_BLOB);
2555

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

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

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

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

            
2581
    id => 4
2582
    id => [4, 5]
2583

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

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

            
2594
The above is same as the followin one.
2595

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

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

            
2603
    query => 1
2604

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2657
    type_rule_off => 1
2658

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

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

            
2663
    type_rule1_off => 1
2664

            
2665
Turn C<into1> type rule off.
2666

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

            
2669
    type_rule2_off => 1
2670

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

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

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

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

            
2679
get column infomation except for one which match C<exclude_table> pattern.
2680

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

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

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

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

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

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

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

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

            
2714
Register helper. These helper is called directly from L<DBIx::Custom> object.
2715

            
2716
    $dbi->update_or_insert;
2717
    $dbi->find_or_create;
2718

            
cleanup
yuki-kimoto authored on 2010-10-17
2719
=head2 C<insert>
2720

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

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

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

            
2729
    {date => \"NOW()"}
2730

            
cleanup
Yuki Kimoto authored on 2011-10-20
2731
B<options>
2732

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

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

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

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

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

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

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

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

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

            
2762
    prefix => 'or replace'
2763

            
2764
prefix before table name section
2765

            
2766
    insert or replace into book
2767

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

            
2770
    table => 'book'
2771

            
2772
Table name.
2773

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

            
2776
    timestamp => 1
2777

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

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

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

            
2786
placeholder wrapped string.
2787

            
2788
If the following statement
2789

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

            
2793
is executed, the following SQL is executed.
2794

            
2795
    insert into book price values ( ? + 5 );
2796

            
update pod
Yuki Kimoto authored on 2011-03-13
2797
=back
2798

            
2799
=over 4
2800

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2864
    my $like_value = $dbi->like_value
2865

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

            
2868
    sub { "%$_[0]%" }
2869

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

            
2872
    my $mapper = $dbi->mapper(param => $param);
2873

            
2874
Create a new L<DBIx::Custom::Mapper> object.
2875

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

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

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

            
2882
    {key1 => [1, 1], key2 => 2}
2883

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

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

            
2888
    my $model = $dbi->model('book');
2889

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

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

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

            
2897
Create column clause for myself. The follwoing column clause is created.
2898

            
2899
    book.author as author,
2900
    book.title as title
2901

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

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

            
2911
Create a new L<DBIx::Custom> object.
2912

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

            
2915
    my $not_exists = $dbi->not_exists;
2916

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

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

            
2922
    my $order = $dbi->order;
2923

            
2924
Create a new L<DBIx::Custom::Order> object.
2925

            
cleanup
yuki-kimoto authored on 2010-10-17
2926
=head2 C<register_filter>
2927

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

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

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

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

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

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

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

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

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

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

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

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

            
2980
    book.author as "book.author",
2981
    book.title as "book.title",
2982
    person.name as "person.name",
2983
    person.age as "person.age"
2984

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

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

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

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

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

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

            
3000
=item C<id>
3001

            
3002
    id => 4
3003
    id => [4, 5]
3004

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

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

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

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

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

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

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

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

            
3035
    prefix => 'SQL_CALC_FOUND_ROWS'
3036

            
3037
Prefix of column cluase
3038

            
3039
    select SQL_CALC_FOUND_ROWS title, author from book;
3040

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

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

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

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

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

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

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

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

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

            
updated document
Yuki Kimoto authored on 2011-06-09
3088
Table name.
updated pod
Yuki Kimoto authored on 2011-06-08
3089

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

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

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

            
3122
    $dbi->setup_model;
3123

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

            
3127
=head2 C<type_rule>
3128

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

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

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

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

            
3162
C<into2> is executed after C<into1>.
3163

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

            
3167
=over 4
3168

            
3169
=item 1. column name
3170

            
3171
    issue_date
3172
    issue_datetime
3173

            
3174
This need C<table> option in each method.
3175

            
3176
=item 2. table name and column name, separator is dot
3177

            
3178
    book.issue_date
3179
    book.issue_datetime
3180

            
3181
=back
3182

            
3183
You get all type name used in database by C<available_typename>.
3184

            
3185
    print $dbi->available_typename;
3186

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

            
3191
    print $dbi->available_datatype;
3192

            
3193
You can also specify multiple types at once.
3194

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3244
    prefix => 'or replace'
3245

            
3246
prefix before table name section
3247

            
3248
    update or replace book
3249

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

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

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

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

            
3258
    timestamp => 1
3259

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

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

            
3266
Same as C<select> method's C<where> option.
3267

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

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

            
3272
placeholder wrapped string.
3273

            
3274
If the following statement
3275

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

            
3279
is executed, the following SQL is executed.
3280

            
3281
    update book set price =  ? + 5;
3282

            
updated pod
Yuki Kimoto authored on 2011-06-08
3283
=back
update pod
Yuki Kimoto authored on 2011-03-13
3284

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

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

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

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

            
3313
In both examples, the following SQL is executed.
3314

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

            
3321
The following opitons are available adding to C<update> option.
3322

            
3323
=over 4
3324

            
3325
=item C<select_option>
3326

            
3327
    select_option => {append => 'for update'}
3328

            
3329
select method option,
3330
select method is used to check the row is already exists.
3331

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

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

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

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

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

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

            
3352
    $dbi->show_datatype($table);
3353

            
3354
Show data type of the columns of specified table.
3355

            
3356
    book
3357
    title: 5
3358
    issue_date: 91
3359

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

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

            
3364
    $dbi->show_tables;
3365

            
3366
Show tables.
3367

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

            
3370
    $dbi->show_typename($table);
3371

            
3372
Show type name of the columns of specified table.
3373

            
3374
    book
3375
    title: varchar
3376
    issue_date: date
3377

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

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

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

            
3384
Create values clause.
3385

            
3386
    (title, author) values (title = :title, age = :age);
3387

            
3388
You can use this in insert statement.
3389

            
3390
    my $insert_sql = "insert into book $values_clause";
3391

            
3392
=head2 C<where>
3393

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

            
3399
Create a new L<DBIx::Custom::Where> object.
3400

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

            
3403
=head2 C<DBIX_CUSTOM_DEBUG>
3404

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

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

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

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

            
3414
L<DBIx::Custom>
3415

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

            
3463
L<DBIx::Custom::Model>
3464

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

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

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

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

            
3506
L<DBIx::Custom::Tag>
3507

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

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

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

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

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

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

            
3525
C<< <kimoto.yuki at gmail.com> >>
3526

            
3527
L<http://github.com/yuki-kimoto/DBIx-Custom>
3528

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
3529
=head1 AUTHOR
3530

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

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

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

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

            
3540
=cut