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

            
micro optimization
Yuki Kimoto authored on 2011-10-23
4
our $VERSION = '0.1736';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
added DBIx::Custom::Mapper
Yuki Kimoto authored on 2011-08-26
699
sub mapper {
700
    my $self = shift;
701
    return DBIx::Custom::Mapper->new(@_);
702
}
703

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-10-21
1062
sub update_or_insert {
1063
    my $self = shift;
1064

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

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

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

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

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

            
1174
        # Create query
1175
        my $builder = $self->query_builder;
1176
        $query = $builder->build_query($source);
1177

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1496
    return $new_tables;
cleanup
Yuki Kimoto authored on 2011-04-02
1497
}
1498

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

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

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

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

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

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

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

            
1678
# DEPRECATED!
1679
sub assign_param {
1680
    my $self = shift;
1681
    warn "assing_param is DEPRECATED! use assign_clause instead";
1682
    return $self->assign_clause(@_);
1683
}
1684

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

            
1695
    return $tag;
1696
}
1697

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-06-08
1752
# DEPRECATED!
1753
sub update_at {
1754
    my $self = shift;
1755

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1844
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1845
sub default_fetch_filter {
1846
    my $self = shift;
added warnings
Yuki Kimoto authored on 2011-06-07
1847

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1927
=head1 NAME
1928

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

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

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

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

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

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

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

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

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

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

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

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

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

            
micro optimization
Yuki Kimoto authored on 2011-07-30
2002
Named place holder support
2003

            
2004
=item *
2005

            
cleanup
Yuki Kimoto authored on 2011-07-29
2006
Model support
2007

            
2008
=item *
2009

            
2010
Connection manager support
2011

            
2012
=item *
pod fix
Yuki Kimoto authored on 2011-01-21
2013

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

            
2018
=item *
2019

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

            
2022
=item *
2023

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

            
2026
=back
pod fix
Yuki Kimoto authored on 2011-01-21
2027

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

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

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

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

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

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

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

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

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

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

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

            
2067
    my $dbi = DBIx::Custom->connect(
2068
      dsn => $dsn, user => $user, password => $password, connector => 1);
2069
    
2070
    my $connector = $dbi->connector; # DBIx::Connector
2071

            
2072
Note that L<DBIx::Connector> must be installed.
2073

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

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

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

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

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

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

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

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

            
2097
    my $exclude_table = $dbi->exclude_table;
2098
    $dbi = $dbi->exclude_table(qr/pg_/);
2099

            
2100
Excluded table regex.
2101
C<each_column>, C<each_table>, C<type_rule>,
2102
and C<setup_model> methods ignore matching tables.
2103

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

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

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

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

            
2113
    my $last_sql = $dbi->last_sql;
2114
    $dbi = $dbi->last_sql($last_sql);
2115

            
2116
Get last successed SQL executed by C<execute> method.
2117

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

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

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

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

            
2127
    my $option = $dbi->option;
2128
    $dbi = $dbi->option($option);
2129

            
2130
L<DBI> option, used when C<connect> method is executed.
2131
Each value in option override the value of C<default_option>.
2132

            
cleanup
yuki-kimoto authored on 2010-10-17
2133
=head2 C<password>
2134

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-07-30
2155
You can set quote pair.
2156

            
2157
    $dbi->quote('[]');
2158

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

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

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

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

            
fixed pod
Yuki Kimoto authored on 2011-09-27
2168
    my $safety_character = $dbi->safety_character;
2169
    $dbi = $dbi->safety_character($character);
update pod
Yuki Kimoto authored on 2011-01-27
2170

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

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

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

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

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

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

            
2187
    my $tag_parse = $dbi->tag_parse(0);
2188
    $dbi = $dbi->tag_parse;
2189

            
2190
Enable DEPRECATED tag parsing functionality, default to 1.
2191
If you want to disable tag parsing functionality, set to 0.
2192

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

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

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

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

            
2202
    my $user_column_info = $dbi->user_column_info;
2203
    $dbi = $dbi->user_column_info($user_column_info);
2204

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

            
2207
    [
2208
        {table => 'book', column => 'title', info => {...}},
2209
        {table => 'author', column => 'name', info => {...}}
2210
    ]
2211

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

            
2214
    my $user_column_info
2215
      = $dbi->get_column_info(exclude_table => qr/^system/);
2216
    $dbi->user_column_info($user_column_info);
2217

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

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

            
2223
    my $user_table_info = $dbi->user_table_info;
2224
    $dbi = $dbi->user_table_info($user_table_info);
2225

            
2226
You can set the following data.
2227

            
2228
    [
2229
        {table => 'book', info => {...}},
2230
        {table => 'author', info => {...}}
2231
    ]
2232

            
2233
Usually, you can set return value of C<get_table_info>.
2234

            
2235
    my $user_table_info = $dbi->get_table_info(exclude => qr/^system/);
2236
    $dbi->user_table_info($user_table_info);
2237

            
2238
If C<user_table_info> is set, C<each_table> use C<user_table_info>
2239
to find table info.
2240

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2277
Create column clause. The follwoing column clause is created.
2278

            
2279
    book.author as "book.author",
2280
    book.title as "book.title"
2281

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

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

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

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

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

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

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

            
2309
Get rows count.
2310

            
2311
Options is same as C<select> method's ones.
2312

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

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

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

            
2326
   $dbi->model('book')->select(...);
2327

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

            
2330
    my $dbh = $dbi->dbh;
2331

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

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

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

            
2339
Execute delete statement.
2340

            
2341
The following opitons are available.
2342

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

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

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

            
2350
=item C<id>
2351

            
2352
    id => 4
2353
    id => [4, 5]
2354

            
2355
ID corresponding to C<primary_key>.
2356
You can delete rows by C<id> and C<primary_key>.
2357

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

            
2364
The above is same as the followin one.
2365

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

            
2368
=item C<prefix>
2369

            
2370
    prefix => 'some'
2371

            
2372
prefix before table name section.
2373

            
2374
    delete some from book
2375

            
2376
=item C<table>
2377

            
2378
    table => 'book'
2379

            
2380
Table name.
2381

            
2382
=item C<where>
2383

            
2384
Same as C<select> method's C<where> option.
2385

            
2386
=back
2387

            
2388
=head2 C<delete_all>
2389

            
2390
    $dbi->delete_all(table => $table);
2391

            
2392
Execute delete statement for all rows.
2393
Options is same as C<delete>.
2394

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

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

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

            
2414
If C<user_column_info> is set, C<each_column> method use C<user_column_info>
2415
infromation, you can improve the performance of C<each_column> in
2416
the following way.
2417

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

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

            
2424
    $dbi->each_table(
2425
        sub {
2426
            my ($dbi, $table, $table_info) = @_;
2427
            
2428
            my $table_name = $table_info->{TABLE_NAME};
2429
        }
2430
    );
2431

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

            
2437
If C<user_table_info> is set, C<each_table> method use C<user_table_info>
2438
infromation, you can improve the performance of C<each_table> in
2439
the following way.
2440

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

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

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

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

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

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

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

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

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

            
2484
    select * from where title = "aa\\:bb";
2485

            
cleanup
Yuki Kimoto authored on 2011-10-20
2486
B<OPTIONS>
2487

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

            
2490
=over 4
2491

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

            
2494
You can filter sql after the sql is build.
2495

            
2496
    after_build_sql => $code_ref
2497

            
2498
The following one is one example.
2499

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

            
2508
The following SQL is executed.
2509

            
2510
    select count(*) from (select distinct(name) from book) as t1;
2511

            
cleanup
Yuki Kimoto authored on 2011-10-20
2512
=item C<append>
2513

            
2514
    append => 'order by name'
2515

            
2516
Append some statement after SQL.
2517

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

            
2520
Specify database bind data type.
2521

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

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

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

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

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

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

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

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

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

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

            
2567
The above is same as the followin one.
2568

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

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

            
2576
    query => 1
2577

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

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

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

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

            
2596
If you want to execute SQL as possible as fast and don't need filtering.
Added execute method's query...
Yuki Kimoto authored on 2011-07-30
2597
You can do the following way.
cleanup
Yuki Kimoto authored on 2011-07-30
2598
    
2599
    my $query;
2600
    my $sth;
cleanup
Yuki Kimoto authored on 2011-10-21
2601
    for my $row (@$rows) {
cleanup
Yuki Kimoto authored on 2011-07-30
2602
      $query ||= $dbi->insert($row, table => 'book', query => 1);
2603
      $sth ||= $query->sth;
2604
      $sth->execute(map { $row->{$_} } sort keys %$row);
2605
    }
2606

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2656
    type_rule_off => 1
2657

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

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

            
2662
    type_rule1_off => 1
2663

            
2664
Turn C<into1> type rule off.
2665

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

            
2668
    type_rule2_off => 1
2669

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2761
    prefix => 'or replace'
2762

            
2763
prefix before table name section
2764

            
2765
    insert or replace into book
2766

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

            
2769
    table => 'book'
2770

            
2771
Table name.
2772

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

            
2775
    timestamp => 1
2776

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

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

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

            
2785
placeholder wrapped string.
2786

            
2787
If the following statement
2788

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

            
2792
is executed, the following SQL is executed.
2793

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

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

            
2798
=over 4
2799

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2863
    my $like_value = $dbi->like_value
2864

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
2999
=item C<id>
3000

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

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

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

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

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

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

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

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

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

            
3034
    prefix => 'SQL_CALC_FOUND_ROWS'
3035

            
3036
Prefix of column cluase
3037

            
3038
    select SQL_CALC_FOUND_ROWS title, author from book;
3039

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3121
    $dbi->setup_model;
3122

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

            
3126
=head2 C<type_rule>
3127

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

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

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

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

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

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

            
3166
=over 4
3167

            
3168
=item 1. column name
3169

            
3170
    issue_date
3171
    issue_datetime
3172

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

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

            
3177
    book.issue_date
3178
    book.issue_datetime
3179

            
3180
=back
3181

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

            
3184
    print $dbi->available_typename;
3185

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

            
3190
    print $dbi->available_datatype;
3191

            
3192
You can also specify multiple types at once.
3193

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3243
    prefix => 'or replace'
3244

            
3245
prefix before table name section
3246

            
3247
    update or replace book
3248

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

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

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

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

            
3257
    timestamp => 1
3258

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

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

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

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

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

            
3271
placeholder wrapped string.
3272

            
3273
If the following statement
3274

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

            
3278
is executed, the following SQL is executed.
3279

            
3280
    update book set price =  ? + 5;
3281

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

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

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

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

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

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

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

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

            
3322
=over 4
3323

            
3324
=item C<select_option>
3325

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

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

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

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

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

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

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

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

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

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

            
3355
    book
3356
    title: 5
3357
    issue_date: 91
3358

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

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

            
3363
    $dbi->show_tables;
3364

            
3365
Show tables.
3366

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

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

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

            
3373
    book
3374
    title: varchar
3375
    issue_date: date
3376

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

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

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

            
3383
Create values clause.
3384

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

            
3387
You can use this in insert statement.
3388

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

            
3391
=head2 C<where>
3392

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

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

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

            
3402
=head2 C<DBIX_CUSTOM_DEBUG>
3403

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

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

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

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

            
3413
L<DBIx::Custom>
3414

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
3537
=cut