cleanup
|
1 |
package DBIx::Custom; |
added EXPERIMENTAL insert, u...
|
2 |
use Object::Simple -base; |
cleanup
|
3 | |
micro optimization
|
4 |
our $VERSION = '0.1735'; |
fixed DBIx::Custom::QueryBui...
|
5 |
use 5.008001; |
cleanup
|
6 | |
packaging one directory
|
7 |
use Carp 'croak'; |
8 |
use DBI; |
|
9 |
use DBIx::Custom::Result; |
|
cleanup
|
10 |
use DBIx::Custom::Query; |
cleanup
|
11 |
use DBIx::Custom::QueryBuilder; |
added experimental DBIx::Cus...
|
12 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
13 |
use DBIx::Custom::Model; |
cleanup
|
14 |
use DBIx::Custom::Tag; |
- added EXPERIMENTAL order m...
|
15 |
use DBIx::Custom::Order; |
cleanup
|
16 |
use DBIx::Custom::Util qw/_array_to_hash _subname/; |
added tests
|
17 |
use DBIx::Custom::Mapper; |
- added EXPERIMENTAL pass at...
|
18 |
use DBIx::Custom::NotExists; |
improved debug message
|
19 |
use Encode qw/encode encode_utf8 decode_utf8/; |
cleanup
|
20 |
use Scalar::Util qw/weaken/; |
packaging one directory
|
21 | |
added environment variable D...
|
22 |
use constant DEBUG => $ENV{DBIX_CUSTOM_DEBUG} || 0; |
improved debug message
|
23 |
use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8'; |
added environment variable D...
|
24 | |
- added EXPERIMENTAL get_col...
|
25 |
has [qw/connector dsn password quote user exclude_table user_table_info |
26 |
user_column_info/], |
|
removed from cache() and cac...
|
27 |
cache => 0, |
many changed
|
28 |
cache_method => sub { |
29 |
sub { |
|
30 |
my $self = shift; |
|
31 |
|
|
32 |
$self->{_cached} ||= {}; |
|
33 |
|
|
34 |
if (@_ > 1) { |
|
update pod
|
35 |
$self->{_cached}{$_[0]} = $_[1]; |
many changed
|
36 |
} |
37 |
else { |
|
update pod
|
38 |
return $self->{_cached}{$_[0]}; |
many changed
|
39 |
} |
40 |
} |
|
update pod
|
41 |
}, |
- dbi_option attribute is re...
|
42 |
option => sub { {} }, |
43 |
default_option => sub { |
|
update pod
|
44 |
{ |
45 |
RaiseError => 1, |
|
46 |
PrintError => 0, |
|
47 |
AutoCommit => 1 |
|
48 |
} |
|
49 |
}, |
|
fix tests
|
50 |
filters => sub { |
51 |
{ |
|
52 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
53 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
54 |
} |
|
update pod
|
55 |
}, |
added EXPERIMENTAL last_sql ...
|
56 |
last_sql => '', |
update pod
|
57 |
models => sub { {} }, |
cleanup
|
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
|
64 |
result_class => 'DBIx::Custom::Result', |
65 |
safety_character => '\w', |
|
cleanup test
|
66 |
separator => '.', |
added tag_parse attribute
|
67 |
stash => sub { {} }, |
- added EXPERIMENTAL update_...
|
68 |
tag_parse => 1; |
cleanup
|
69 | |
added EXPERIMENTAL system_ta...
|
70 |
sub available_datatype { |
test cleanup
|
71 |
my $self = shift; |
72 |
|
|
added EXPERIMENTAL system_ta...
|
73 |
my $data_types = ''; |
cleanup
|
74 |
for my $i (-1000 .. 1000) { |
added EXPERIMENTAL system_ta...
|
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
|
99 |
} |
100 | ||
added helper method
|
101 |
our $AUTOLOAD; |
102 |
sub AUTOLOAD { |
|
103 |
my $self = shift; |
|
104 | ||
renamed helper to method.
|
105 |
# Method name |
106 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
107 | |
cleanup
|
108 |
# Call method |
renamed helper to method.
|
109 |
$self->{_methods} ||= {}; |
add feture. all model class ...
|
110 |
if (my $method = $self->{_methods}->{$mname}) { |
111 |
return $self->$method(@_) |
|
112 |
} |
|
- removed EXPERIMENTAL Prefo...
|
113 |
elsif ($self->{dbh} && (my $dbh_method = $self->dbh->can($mname))) { |
- added EXPERIMENTAL DBIx::C...
|
114 |
$self->dbh->$dbh_method(@_); |
add feture. all model class ...
|
115 |
} |
116 |
else { |
|
cleanup
|
117 |
croak qq{Can't locate object method "$mname" via "$package" } |
118 |
. _subname; |
|
add feture. all model class ...
|
119 |
} |
added helper method
|
120 |
} |
121 | ||
- update_param is DEPRECATED...
|
122 |
sub assign_clause { |
updated pod
|
123 |
my ($self, $param, $opts) = @_; |
124 |
|
|
125 |
my $wrap = $opts->{wrap} || {}; |
|
micro optimization
|
126 |
my $safety = $self->{safety_character} || $self->safety_character; |
fixed some quoted bug
|
127 |
my $qp = $self->_q(''); |
128 |
my $q = substr($qp, 0, 1) || ''; |
|
129 |
my $p = substr($qp, 1, 1) || ''; |
|
added EXPERIMENTAL assign_ta...
|
130 |
|
micro optimization
|
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...
|
137 |
} |
138 |
|
|
micro optimization
|
139 |
# Assign clause (performance is important) |
micro optimization
|
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...
|
148 |
} |
149 | ||
cleanup
|
150 |
sub column { |
- DBIx::Custom Model filter ...
|
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
|
161 |
|
EXPERIMTANL column method th...
|
162 |
# Separator |
163 |
my $separator = $self->separator; |
|
164 |
|
|
cleanup
|
165 |
# Column clause |
cleanup
|
166 |
my @column; |
cleanup
|
167 |
$columns ||= []; |
added quote method's two cha...
|
168 |
push @column, $self->_q($table) . "." . $self->_q($_) . |
169 |
" as " . $self->_q("${table}${separator}$_") |
|
EXPERIMTANL column method th...
|
170 |
for @$columns; |
cleanup
|
171 |
|
172 |
return join (', ', @column); |
|
added helper method
|
173 |
} |
174 | ||
packaging one directory
|
175 |
sub connect { |
cleanup
|
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...
|
186 |
my $option = $self->_option; |
cleanup
|
187 |
my $connector = DBIx::Connector->new($dsn, $user, $password, |
- dbi_option attribute is re...
|
188 |
{%{$self->default_option} , %$option}); |
cleanup
|
189 |
$self->connector($connector); |
190 |
} |
|
removed register_format()
|
191 |
|
- removed EXPERIMENTAL Prefo...
|
192 |
# Connect |
193 |
$self->dbh; |
|
update document
|
194 |
|
packaging one directory
|
195 |
return $self; |
196 |
} |
|
197 | ||
- added EXPERIMENTAL DBIx::C...
|
198 |
sub count { shift->select(column => 'count(*)', @_)->fetch_first->[0] } |
199 | ||
update pod
|
200 |
sub dbh { |
201 |
my $self = shift; |
|
cleanup
|
202 |
|
fixed dbh() method bug:wq
|
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
|
214 |
croak "connector must have dbh() method " . _subname |
fixed dbh() method bug:wq
|
215 |
unless ref $connector && $connector->can('dbh'); |
216 |
|
|
set reserved_word_quote auto...
|
217 |
$self->{dbh} = $connector->dbh; |
fixed dbh() method bug:wq
|
218 |
} |
219 |
|
|
set reserved_word_quote auto...
|
220 |
# Connect |
221 |
$self->{dbh} ||= $self->_connect; |
|
222 |
|
|
223 |
# Quote |
|
reserved_word_quote is DEPRE...
|
224 |
if (!defined $self->reserved_word_quote && !defined $self->quote) { |
prepare oracle test
|
225 |
my $driver = $self->_driver; |
added EXPERIMENTAL find_tabl...
|
226 |
my $quote = $driver eq 'odbc' ? '[]' |
227 |
: $driver eq 'ado' ? '[]' |
|
228 |
: $driver eq 'mysql' ? '`' |
|
fixex [] reserved_word_quote...
|
229 |
: '"'; |
reserved_word_quote is DEPRE...
|
230 |
$self->quote($quote); |
set reserved_word_quote auto...
|
231 |
} |
reserved_word_quote is DEPRE...
|
232 |
|
set reserved_word_quote auto...
|
233 |
return $self->{dbh}; |
update pod
|
234 |
} |
235 |
} |
|
236 | ||
cleanup
|
237 |
sub delete { |
238 |
my ($self, %opt) = @_; |
|
239 |
warn "delete method where_param option is DEPRECATED!" |
|
240 |
if $opt{where_param}; |
|
241 |
|
|
cleanup
|
242 |
# Don't allow delete all rows |
cleanup
|
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...
|
248 |
? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table}) |
cleanup
|
249 |
: $opt{where}; |
250 |
my $w = $self->_where_clause_and_param($where, $opt{where_param}); |
|
make delete() using where ob...
|
251 | |
cleanup
|
252 |
# Delete statement |
cleanup
|
253 |
my $sql = "delete "; |
cleanup
|
254 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
cleanup
|
255 |
$sql .= "from " . $self->_q($opt{table}) . " $w->{clause} "; |
packaging one directory
|
256 |
|
257 |
# Execute query |
|
micro optimization
|
258 |
$self->execute($sql, $w->{param}, %opt); |
packaging one directory
|
259 |
} |
260 | ||
cleanup
|
261 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
262 | |
added memory leak check test
|
263 |
sub DESTROY {} |
added helper method
|
264 | |
removed EXPERIMETNAL flag fr...
|
265 |
sub create_model { |
266 |
my $self = shift; |
|
267 |
|
|
cleanup
|
268 |
# Options |
cleanup
|
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...
|
274 |
$model_name ||= $model_table; |
275 |
|
|
cleanup
|
276 |
# Create model |
cleanup
|
277 |
my $model = $model_class->new($opt); |
cleanup
|
278 |
weaken $model->{dbi}; |
removed EXPERIMETNAL flag fr...
|
279 |
$model->name($model_name) unless $model->name; |
280 |
$model->table($model_table) unless $model->table; |
|
281 |
|
|
micro optimization
|
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...
|
293 |
# Set model |
294 |
$self->model($model->name, $model); |
|
295 |
|
|
create_model() return model
|
296 |
return $self->model($model->name); |
removed EXPERIMETNAL flag fr...
|
297 |
} |
298 | ||
299 |
sub each_column { |
|
- added EXPERIMENTAL get_col...
|
300 |
my ($self, $cb, %options) = @_; |
added EXPERIMENTAL system_ta...
|
301 | |
- added EXPERIMENTAL get_col...
|
302 |
my $user_column_info = $self->user_column_info; |
removed EXPERIMETNAL flag fr...
|
303 |
|
- added EXPERIMENTAL get_col...
|
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
|
313 | |
- added EXPERIMENTAL get_col...
|
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...
|
327 |
} |
328 |
} |
|
329 |
} |
|
330 | ||
added EXPERIMENTAL each_tabl...
|
331 |
sub each_table { |
added EXPERIMENTAL find_tabl...
|
332 |
my ($self, $cb, %option) = @_; |
added EXPERIMENTAL each_tabl...
|
333 |
|
cleanup test
|
334 |
my $user_table_infos = $self->user_table_info; |
added EXPERIMENTAL system_ta...
|
335 |
|
added test
|
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...
|
350 |
} |
351 |
} |
|
352 | ||
cleanup
|
353 |
sub execute { |
execute method can second ar...
|
354 |
my $self = shift; |
cleanup
|
355 |
my $sql = shift; |
moved DBIx::Custom::Guide to...
|
356 | |
357 |
# Options |
|
execute method can second ar...
|
358 |
my $param; |
359 |
$param = shift if @_ % 2; |
|
cleanup
|
360 |
my %opt = @_; |
moved DBIx::Custom::Guide to...
|
361 |
warn "sqlfilter option is DEPRECATED" if $opt{sqlfilter}; |
362 |
$param ||= $opt{param} || {}; |
|
cleanup
|
363 |
my $tables = $opt{table} || []; |
cleanup
|
364 |
$tables = [$tables] unless ref $tables eq 'ARRAY'; |
micro optimization
|
365 |
my $filter = ref $opt{filter} eq 'ARRAY' ? |
366 |
_array_to_hash($opt{filter}) : $opt{filter}; |
|
refactoring delete and delet...
|
367 |
|
moved DBIx::Custom::Guide to...
|
368 |
# Append |
369 |
$sql .= $opt{append} if defined $opt{append} && !ref $sql; |
|
370 |
|
|
371 |
# Query |
|
added EXPERIMENTAL reuse_que...
|
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 ...
|
381 |
# Save query |
micro optimization
|
382 |
$self->{last_sql} = $query->{sql}; |
added EXPERIMENTAL last_sql ...
|
383 | |
moved DBIx::Custom::Guide to...
|
384 |
# Return query |
385 |
return $query if $opt{query}; |
|
micro optimization
|
386 |
|
moved DBIx::Custom::Guide to...
|
387 |
# Merge query filter(DEPRECATED!) |
DBIx::Custom::Query filter m...
|
388 |
$filter ||= $query->{filter} || {}; |
all filter can receive array...
|
389 |
|
cleanup
|
390 |
# Tables |
DBIx::Custom::Query tables a...
|
391 |
unshift @$tables, @{$query->{tables} || []}; |
micro optimization
|
392 |
my $main_table = @{$tables}[-1]; |
moved DBIx::Custom::Guide to...
|
393 |
|
394 |
# Convert id to parameter |
|
395 |
if (defined $opt{id}) { |
|
396 |
my $id_param = $self->_id_to_param($opt{id}, $opt{primary_key}, $main_table); |
|
fixed id option bug when col...
|
397 |
$param = $self->merge_param($id_param, $param); |
398 |
} |
|
micro optimization
|
399 |
|
moved DBIx::Custom::Guide to...
|
400 |
# Cleanup tables(DEPRECATED!) |
micro optimization
|
401 |
$tables = $self->_remove_duplicate_table($tables, $main_table) |
402 |
if @$tables > 1; |
|
cleanup
|
403 |
|
added type_rule into logic
|
404 |
# Type rule |
EXPERIMENTAL type_rule argum...
|
405 |
my $type_filters = {}; |
micro optimization
|
406 |
if ($self->{_type_rule_is_called}) { |
407 |
unless ($opt{type_rule_off}) { |
|
408 |
my $type_rule_off_parts = { |
|
409 |
1 => $opt{type_rule1_off}, |
|
410 |
2 => $opt{type_rule2_off} |
|
411 |
}; |
|
412 |
for my $i (1, 2) { |
|
413 |
unless ($type_rule_off_parts->{$i}) { |
|
414 |
$type_filters->{$i} = {}; |
|
415 |
my $table_alias = $opt{table_alias} || {}; |
|
416 |
for my $alias (keys %$table_alias) { |
|
417 |
my $table = $table_alias->{$alias}; |
|
418 |
|
|
419 |
for my $column (keys %{$self->{"_into$i"}{key}{$table} || {}}) { |
|
420 |
$type_filters->{$i}->{"$alias.$column"} = $self->{"_into$i"}{key}{$table}{$column}; |
|
421 |
} |
|
EXPERIMENTAL type_rule argum...
|
422 |
} |
micro optimization
|
423 |
$type_filters->{$i} = {%{$type_filters->{$i}}, %{$self->{"_into$i"}{key}{$main_table} || {}}} |
424 |
if $main_table; |
|
EXPERIMENTAL type_rule argum...
|
425 |
} |
added EXPERIMENTAL execute()...
|
426 |
} |
added type_rule into logic
|
427 |
} |
428 |
} |
|
cleanup
|
429 |
|
moved DBIx::Custom::Guide to...
|
430 |
# Applied filter(DEPRECATED!) |
micro optimization
|
431 |
if ($self->{filter}{on}) { |
432 |
my $applied_filter = {}; |
|
cleanup
|
433 |
for my $table (@$tables) { |
micro optimization
|
434 |
$applied_filter = { |
435 |
%$applied_filter, |
|
436 |
%{$self->{filter}{out}->{$table} || {}} |
|
437 |
} |
|
added auto_filter method
|
438 |
} |
micro optimization
|
439 |
$filter = {%$applied_filter, %$filter}; |
added auto_filter method
|
440 |
} |
441 |
|
|
cleanup
|
442 |
# Replace filter name to code |
cleanup
|
443 |
for my $column (keys %$filter) { |
cleanup
|
444 |
my $name = $filter->{$column}; |
445 |
if (!defined $name) { |
|
446 |
$filter->{$column} = undef; |
|
renamed auto_filter to apply...
|
447 |
} |
cleanup
|
448 |
elsif (ref $name ne 'CODE') { |
cleanup
|
449 |
croak qq{Filter "$name" is not registered" } . _subname |
cleanup
|
450 |
unless exists $self->filters->{$name}; |
451 |
$filter->{$column} = $self->filters->{$name}; |
|
cleanup
|
452 |
} |
453 |
} |
|
packaging one directory
|
454 |
|
cleanup
|
455 |
# Create bind values |
micro optimization
|
456 |
my ($bind, $bind_types) = $self->_create_bind_values($param, $query->columns, |
457 |
$filter, $type_filters, $opt{bind_type} || $opt{type} || {}); |
|
added EXPERIMENTAL execute m...
|
458 | |
cleanup
|
459 |
# Execute |
micro optimization
|
460 |
my $sth = $query->{sth}; |
cleanup
|
461 |
my $affected; |
cleanup
|
462 |
eval { |
micro optimization
|
463 |
if ($opt{bind_type} || $opt{type}) { |
464 |
$sth->bind_param($_ + 1, $bind->[$_], |
|
465 |
$bind_types->[$_] ? $bind_types->[$_] : ()) |
|
466 |
for (0 .. @$bind - 1); |
|
467 |
$affected = $sth->execute; |
|
468 |
} |
|
469 |
else { |
|
470 |
$affected = $sth->execute(@$bind); |
|
471 |
} |
|
cleanup
|
472 |
}; |
improved error messages
|
473 |
|
micro optimization
|
474 |
$self->_croak($@, qq{. Following SQL is executed.\n} |
475 |
. qq{$query->{sql}\n} . _subname) if $@; |
|
cleanup
|
476 |
|
improved debug message
|
477 |
# DEBUG message |
478 |
if (DEBUG) { |
|
479 |
print STDERR "SQL:\n" . $query->sql . "\n"; |
|
480 |
my @output; |
|
cleanup
|
481 |
for my $b (@$bind) { |
improved debug message
|
482 |
my $value = $b->{value}; |
483 |
$value = 'undef' unless defined $value; |
|
484 |
$value = encode(DEBUG_ENCODING(), $value) |
|
485 |
if utf8::is_utf8($value); |
|
486 |
push @output, $value; |
|
487 |
} |
|
488 |
print STDERR "Bind values: " . join(', ', @output) . "\n\n"; |
|
489 |
} |
|
added environment variable D...
|
490 |
|
micro optimization
|
491 |
# Not select statement |
492 |
return $affected unless $sth->{NUM_OF_FIELDS}; |
|
493 | ||
494 |
# Filter(DEPRECATED!) |
|
495 |
my $infilter = {}; |
|
496 |
if ($self->{filter}{on}) { |
|
497 |
$infilter->{in} = {}; |
|
498 |
$infilter->{end} = {}; |
|
499 |
push @$tables, $main_table if $main_table; |
|
500 |
for my $table (@$tables) { |
|
501 |
for my $way (qw/in end/) { |
|
502 |
$infilter->{$way} = {%{$infilter->{$way}}, |
|
503 |
%{$self->{filter}{$way}{$table} || {}}}; |
|
cleanup
|
504 |
} |
cleanup
|
505 |
} |
cleanup
|
506 |
} |
micro optimization
|
507 |
|
508 |
# Result |
|
509 |
my $result = $self->result_class->new( |
|
510 |
sth => $sth, |
|
511 |
dbi => $self, |
|
512 |
default_filter => $self->{default_in_filter}, |
|
513 |
filter => $infilter->{in} || {}, |
|
514 |
end_filter => $infilter->{end} || {}, |
|
515 |
type_rule => { |
|
516 |
from1 => $self->type_rule->{from1}, |
|
517 |
from2 => $self->type_rule->{from2} |
|
518 |
}, |
|
519 |
); |
|
520 |
$result; |
|
cleanup
|
521 |
} |
522 | ||
added test
|
523 |
sub get_table_info { |
cleanup
|
524 |
my ($self, %opt) = @_; |
added EXPERIMENTAL find_tabl...
|
525 |
|
cleanup
|
526 |
my $exclude = delete $opt{exclude}; |
527 |
croak qq/"$_" is wrong option/ for keys %opt; |
|
added EXPERIMENTAL find_tabl...
|
528 |
|
added test
|
529 |
my $table_info = []; |
530 |
$self->each_table( |
|
531 |
sub { push @$table_info, {table => $_[1], info => $_[2] } }, |
|
532 |
exclude => $exclude |
|
533 |
); |
|
added EXPERIMENTAL find_tabl...
|
534 |
|
cleanup test
|
535 |
return [sort {$a->{table} cmp $b->{table} } @$table_info]; |
added EXPERIMENTAL find_tabl...
|
536 |
} |
537 | ||
- added EXPERIMENTAL get_col...
|
538 |
sub get_column_info { |
cleanup
|
539 |
my ($self, %opt) = @_; |
- added EXPERIMENTAL get_col...
|
540 |
|
cleanup
|
541 |
my $exclude_table = delete $opt{exclude_table}; |
542 |
croak qq/"$_" is wrong option/ for keys %opt; |
|
- added EXPERIMENTAL get_col...
|
543 |
|
544 |
my $column_info = []; |
|
545 |
$self->each_column( |
|
546 |
sub { push @$column_info, {table => $_[1], column => $_[2], info => $_[3] } }, |
|
547 |
exclude_table => $exclude_table |
|
548 |
); |
|
549 |
|
|
550 |
return [ |
|
551 |
sort {$a->{table} cmp $b->{table} || $a->{column} cmp $b->{column} } |
|
cleanup
|
552 |
@$column_info]; |
- added EXPERIMENTAL get_col...
|
553 |
} |
554 | ||
- method method of DBIx::Cus...
|
555 |
sub helper { |
556 |
my $self = shift; |
|
557 |
|
|
558 |
# Register method |
|
559 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
560 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
561 |
|
|
562 |
return $self; |
|
563 |
} |
|
564 | ||
cleanup
|
565 |
sub insert { |
- insert, insert_at, update,...
|
566 |
my $self = shift; |
added EXPERIMENTAL reserved_...
|
567 |
|
cleanup
|
568 |
# Options |
cleanup
|
569 |
my $param = @_ % 2 ? shift : undef; |
cleanup
|
570 |
my %opt = @_; |
micro optimization
|
571 |
warn "insert method param option is DEPRECATED!" if $opt{param}; |
cleanup
|
572 |
$param ||= delete $opt{param} || {}; |
- added EXPERIMENTAL timesta...
|
573 |
|
574 |
# Timestamp |
|
cleanup
|
575 |
if ($opt{timestamp} && (my $insert_timestamp = $self->insert_timestamp)) { |
- added EXPERIMENTAL update_...
|
576 |
my $columns = $insert_timestamp->[0]; |
577 |
$columns = [$columns] unless ref $columns eq 'ARRAY'; |
|
578 |
my $value = $insert_timestamp->[1]; |
|
579 |
$value = $value->() if ref $value eq 'CODE'; |
|
580 |
$param->{$_} = $value for @$columns; |
|
- added EXPERIMENTAL timesta...
|
581 |
} |
cleanup
|
582 |
|
583 |
# Merge id to parameter |
|
584 |
$param = $self->merge_param( |
|
moved DBIx::Custom::Guide to...
|
585 |
$self->_id_to_param(delete $opt{id}, $opt{primary_key}), $param) |
cleanup
|
586 |
if defined $opt{id}; |
cleanup
|
587 |
|
cleanup
|
588 |
# Insert statement |
cleanup
|
589 |
my $sql = "insert "; |
cleanup
|
590 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
591 |
$sql .= "into " . $self->_q($opt{table}) . " " |
|
592 |
. $self->values_clause($param, {wrap => $opt{wrap}}) . " "; |
|
packaging one directory
|
593 |
|
594 |
# Execute query |
|
micro optimization
|
595 |
$self->execute($sql, $param, %opt); |
packaging one directory
|
596 |
} |
597 | ||
- added EXPERIMENTAL update_...
|
598 |
sub insert_timestamp { |
599 |
my $self = shift; |
|
600 |
|
|
601 |
if (@_) { |
|
602 |
$self->{insert_timestamp} = [@_]; |
|
603 |
|
|
604 |
return $self; |
|
605 |
} |
|
606 |
return $self->{insert_timestamp}; |
|
607 |
} |
|
608 | ||
- added EXPERIMENTAL DBIx::C...
|
609 |
sub include_model { |
610 |
my ($self, $name_space, $model_infos) = @_; |
|
611 |
|
|
cleanup
|
612 |
# Name space |
- added EXPERIMENTAL DBIx::C...
|
613 |
$name_space ||= ''; |
cleanup
|
614 |
|
615 |
# Get Model infomations |
|
- added EXPERIMENTAL DBIx::C...
|
616 |
unless ($model_infos) { |
cleanup
|
617 | |
- added EXPERIMENTAL DBIx::C...
|
618 |
# Load name space module |
cleanup
|
619 |
croak qq{"$name_space" is invalid class name } . _subname |
- added EXPERIMENTAL DBIx::C...
|
620 |
if $name_space =~ /[^\w:]/; |
621 |
eval "use $name_space"; |
|
cleanup
|
622 |
croak qq{Name space module "$name_space.pm" is needed. $@ } |
623 |
. _subname |
|
improved error messages
|
624 |
if $@; |
- added EXPERIMENTAL DBIx::C...
|
625 |
|
626 |
# Search model modules |
|
627 |
my $path = $INC{"$name_space.pm"}; |
|
628 |
$path =~ s/\.pm$//; |
|
629 |
opendir my $dh, $path |
|
cleanup
|
630 |
or croak qq{Can't open directory "$path": $! } . _subname |
- added EXPERIMENTAL DBIx::C...
|
631 |
$model_infos = []; |
632 |
while (my $module = readdir $dh) { |
|
633 |
push @$model_infos, $module |
|
634 |
if $module =~ s/\.pm$//; |
|
635 |
} |
|
636 |
close $dh; |
|
637 |
} |
|
638 |
|
|
cleanup
|
639 |
# Include models |
cleanup
|
640 |
for my $model_info (@$model_infos) { |
- added EXPERIMENTAL DBIx::C...
|
641 |
|
cleanup
|
642 |
# Load model |
- added EXPERIMENTAL DBIx::C...
|
643 |
my $model_class; |
644 |
my $model_name; |
|
645 |
my $model_table; |
|
646 |
if (ref $model_info eq 'HASH') { |
|
647 |
$model_class = $model_info->{class}; |
|
648 |
$model_name = $model_info->{name}; |
|
649 |
$model_table = $model_info->{table}; |
|
650 |
|
|
651 |
$model_name ||= $model_class; |
|
652 |
$model_table ||= $model_name; |
|
653 |
} |
|
removed EXPERIMETNAL flag fr...
|
654 |
else { $model_class = $model_name = $model_table = $model_info } |
- added EXPERIMENTAL DBIx::C...
|
655 |
my $mclass = "${name_space}::$model_class"; |
cleanup
|
656 |
croak qq{"$mclass" is invalid class name } . _subname |
- added EXPERIMENTAL DBIx::C...
|
657 |
if $mclass =~ /[^\w:]/; |
658 |
unless ($mclass->can('isa')) { |
|
659 |
eval "use $mclass"; |
|
cleanup
|
660 |
croak "$@ " . _subname if $@; |
- added EXPERIMENTAL DBIx::C...
|
661 |
} |
662 |
|
|
cleanup
|
663 |
# Create model |
cleanup
|
664 |
my $opt = {}; |
665 |
$opt->{model_class} = $mclass if $mclass; |
|
666 |
$opt->{name} = $model_name if $model_name; |
|
667 |
$opt->{table} = $model_table if $model_table; |
|
668 |
$self->create_model($opt); |
|
- added EXPERIMENTAL DBIx::C...
|
669 |
} |
670 |
|
|
671 |
return $self; |
|
672 |
} |
|
673 | ||
added EXPERIMENTAL like_valu...
|
674 |
sub like_value { sub { "%$_[0]%" } } |
675 | ||
added DBIx::Custom::Mapper
|
676 |
sub mapper { |
677 |
my $self = shift; |
|
678 |
return DBIx::Custom::Mapper->new(@_); |
|
679 |
} |
|
680 | ||
added EXPERIMENTAL updat_par...
|
681 |
sub merge_param { |
682 |
my ($self, @params) = @_; |
|
683 |
|
|
cleanup
|
684 |
# Merge parameters |
fixed merge_param bug
|
685 |
my $merge = {}; |
cleanup
|
686 |
for my $param (@params) { |
687 |
for my $column (keys %$param) { |
|
fixed merge_param bug
|
688 |
my $param_is_array = ref $param->{$column} eq 'ARRAY' ? 1 : 0; |
689 |
|
|
690 |
if (exists $merge->{$column}) { |
|
691 |
$merge->{$column} = [$merge->{$column}] |
|
692 |
unless ref $merge->{$column} eq 'ARRAY'; |
|
693 |
push @{$merge->{$column}}, |
|
694 |
ref $param->{$column} ? @{$param->{$column}} : $param->{$column}; |
|
added EXPERIMENTAL updat_par...
|
695 |
} |
696 |
else { |
|
fixed merge_param bug
|
697 |
$merge->{$column} = $param->{$column}; |
added EXPERIMENTAL updat_par...
|
698 |
} |
699 |
} |
|
700 |
} |
|
701 |
|
|
fixed merge_param bug
|
702 |
return $merge; |
added EXPERIMENTAL updat_par...
|
703 |
} |
704 | ||
- added EXPERIMENTAL DBIx::C...
|
705 |
sub model { |
706 |
my ($self, $name, $model) = @_; |
|
707 |
|
|
cleanup
|
708 |
# Set model |
- added EXPERIMENTAL DBIx::C...
|
709 |
if ($model) { |
710 |
$self->models->{$name} = $model; |
|
711 |
return $self; |
|
712 |
} |
|
713 |
|
|
714 |
# Check model existance |
|
cleanup
|
715 |
croak qq{Model "$name" is not included } . _subname |
- added EXPERIMENTAL DBIx::C...
|
716 |
unless $self->models->{$name}; |
717 |
|
|
cleanup
|
718 |
# Get model |
- added EXPERIMENTAL DBIx::C...
|
719 |
return $self->models->{$name}; |
720 |
} |
|
721 | ||
cleanup
|
722 |
sub mycolumn { |
723 |
my ($self, $table, $columns) = @_; |
|
724 |
|
|
cleanup
|
725 |
# Create column clause |
726 |
my @column; |
|
cleanup
|
727 |
$columns ||= []; |
added quote method's two cha...
|
728 |
push @column, $self->_q($table) . "." . $self->_q($_) . |
729 |
" as " . $self->_q($_) |
|
730 |
for @$columns; |
|
cleanup
|
731 |
|
732 |
return join (', ', @column); |
|
733 |
} |
|
734 | ||
added dbi_options attribute
|
735 |
sub new { |
736 |
my $self = shift->SUPER::new(@_); |
|
737 |
|
|
cleanup
|
738 |
# Check attributes |
added dbi_options attribute
|
739 |
my @attrs = keys %$self; |
cleanup
|
740 |
for my $attr (@attrs) { |
- added EXPERIMENTAL DBIx::C...
|
741 |
croak qq{Invalid attribute: "$attr" } . _subname |
added dbi_options attribute
|
742 |
unless $self->can($attr); |
743 |
} |
|
- added EXPERIMENTAL order m...
|
744 | |
added EXPERIMENTAL system_ta...
|
745 |
# DEPRECATED |
cleanup
|
746 |
$self->{_tags} = { |
added EXPERIMENTAL system_ta...
|
747 |
'?' => \&DBIx::Custom::Tag::placeholder, |
748 |
'=' => \&DBIx::Custom::Tag::equal, |
|
749 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
750 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
751 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
752 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
753 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
754 |
'like' => \&DBIx::Custom::Tag::like, |
|
755 |
'in' => \&DBIx::Custom::Tag::in, |
|
756 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
757 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
cleanup
|
758 |
}; |
759 |
|
|
760 |
return $self; |
|
761 |
} |
|
762 | ||
- added EXPERIMENTAL pass at...
|
763 |
sub not_exists { DBIx::Custom::NotExists->singleton } |
cleanup
|
764 | |
765 |
sub order { |
|
766 |
my $self = shift; |
|
767 |
return DBIx::Custom::Order->new(dbi => $self, @_); |
|
added EXPERIMENTAL system_ta...
|
768 |
} |
769 | ||
cleanup
|
770 |
sub register_filter { |
cleanup
|
771 |
my $self = shift; |
cleanup
|
772 |
|
773 |
# Register filter |
|
774 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
cleanup
|
775 |
$self->filters({%{$self->filters}, %$filters}); |
cleanup
|
776 |
|
cleanup
|
777 |
return $self; |
cleanup
|
778 |
} |
packaging one directory
|
779 | |
780 |
sub select { |
|
cleanup
|
781 |
my ($self, %opt) = @_; |
added EXPERIMENTAL reserved_...
|
782 | |
cleanup
|
783 |
# Options |
cleanup
|
784 |
my $tables = ref $opt{table} eq 'ARRAY' ? $opt{table} |
785 |
: defined $opt{table} ? [$opt{table}] |
|
added table not specified ex...
|
786 |
: []; |
cleanup
|
787 |
$opt{table} = $tables; |
cleanup
|
788 |
my $where_param = $opt{where_param} || delete $opt{param} || {}; |
select_at is DEPRECATED! use...
|
789 |
|
cleanup
|
790 |
# Add relation tables(DEPRECATED!); |
cleanup
|
791 |
if ($opt{relation}) { |
792 |
warn "select() relation option is DEPRECATED!"; |
|
793 |
$self->_add_relation_table($tables, $opt{relation}); |
|
794 |
} |
|
packaging one directory
|
795 |
|
cleanup
|
796 |
# Select statement |
micro optimization
|
797 |
my $sql = 'select '; |
packaging one directory
|
798 |
|
added EXPERIMENTAL select pr...
|
799 |
# Prefix |
cleanup
|
800 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
added EXPERIMENTAL select pr...
|
801 |
|
cleanup
|
802 |
# Column |
cleanup
|
803 |
if (defined $opt{column}) { |
804 |
my $columns |
|
805 |
= ref $opt{column} eq 'ARRAY' ? $opt{column} : [$opt{column}]; |
|
cleanup
|
806 |
for my $column (@$columns) { |
- select() column option can...
|
807 |
if (ref $column eq 'HASH') { |
EXPERIMTANL column method th...
|
808 |
$column = $self->column(%$column) if ref $column eq 'HASH'; |
- select() column option can...
|
809 |
} |
810 |
elsif (ref $column eq 'ARRAY') { |
|
- select method column optio...
|
811 |
if (@$column == 3 && $column->[1] eq 'as') { |
812 |
warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]"; |
|
813 |
splice @$column, 1, 1; |
|
814 |
} |
|
815 |
|
|
added quote method's two cha...
|
816 |
$column = join(' ', $column->[0], 'as', $self->_q($column->[1])); |
- select() column option can...
|
817 |
} |
cleanup
|
818 |
unshift @$tables, @{$self->_search_tables($column)}; |
micro optimization
|
819 |
$sql .= "$column, "; |
added select() all_column op...
|
820 |
} |
micro optimization
|
821 |
$sql =~ s/, $/ /; |
added select() all_column op...
|
822 |
} |
micro optimization
|
823 |
else { $sql .= '* ' } |
added select() all_column op...
|
824 |
|
825 |
# Table |
|
micro optimization
|
826 |
$sql .= 'from '; |
cleanup
|
827 |
if ($opt{relation}) { |
cleanup
|
828 |
my $found = {}; |
cleanup
|
829 |
for my $table (@$tables) { |
micro optimization
|
830 |
$sql .= $self->_q($table) . ', ' unless $found->{$table}; |
cleanup
|
831 |
$found->{$table} = 1; |
- added EXPERIMENTAL DBIx::C...
|
832 |
} |
packaging one directory
|
833 |
} |
moved DBIx::Custom::Guide to...
|
834 |
else { $sql .= $self->_q($tables->[-1] || '') . ' ' } |
micro optimization
|
835 |
$sql =~ s/, $/ /; |
cleanup
|
836 |
croak "select method table option must be specified " . _subname |
improved error messages
|
837 |
unless $tables->[-1]; |
cleanup
|
838 | |
cleanup
|
839 |
# Add tables in parameter |
DEPRECATED select() param op...
|
840 |
unshift @$tables, |
841 |
@{$self->_search_tables(join(' ', keys %$where_param) || '')}; |
|
fixed some select() join opi...
|
842 |
|
select() where can't receive...
|
843 |
# Where |
cleanup
|
844 |
my $where = defined $opt{id} |
moved DBIx::Custom::Guide to...
|
845 |
? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $tables->[-1]) |
cleanup
|
846 |
: $opt{where}; |
847 |
my $w = $self->_where_clause_and_param($where, $where_param); |
|
remove experimental DBIx::Cu...
|
848 |
|
fixed some select() join opi...
|
849 |
# Add table names in where clause |
cleanup
|
850 |
unshift @$tables, @{$self->_search_tables($w->{clause})}; |
remove experimental DBIx::Cu...
|
851 |
|
cleanup
|
852 |
# Join statement |
cleanup
|
853 |
$self->_push_join(\$sql, $opt{join}, $tables) if defined $opt{join}; |
remove experimental DBIx::Cu...
|
854 |
|
cleanup
|
855 |
# Add where clause |
cleanup
|
856 |
$sql .= "$w->{clause} "; |
select() where can't receive...
|
857 |
|
cleanup
|
858 |
# Relation(DEPRECATED!); |
cleanup
|
859 |
$self->_push_relation(\$sql, $tables, $opt{relation}, $w->{clause} eq '' ? 1 : 0) |
cleanup
|
860 |
if $opt{relation}; |
cleanup
|
861 |
|
packaging one directory
|
862 |
# Execute query |
cleanup
|
863 |
my $result = $self->execute($sql, $w->{param}, %opt); |
packaging one directory
|
864 |
|
micro optimization
|
865 |
$result; |
packaging one directory
|
866 |
} |
867 | ||
add experimental setup_model...
|
868 |
sub setup_model { |
869 |
my $self = shift; |
|
870 |
|
|
cleanup
|
871 |
# Setup model |
add experimental setup_model...
|
872 |
$self->each_column( |
873 |
sub { |
|
874 |
my ($self, $table, $column, $column_info) = @_; |
|
875 |
if (my $model = $self->models->{$table}) { |
|
876 |
push @{$model->columns}, $column; |
|
877 |
} |
|
878 |
} |
|
879 |
); |
|
add experimental DBIx::Custo...
|
880 |
return $self; |
add experimental setup_model...
|
881 |
} |
882 | ||
update pod
|
883 |
sub show_datatype { |
884 |
my ($self, $table) = @_; |
|
885 |
croak "Table name must be specified" unless defined $table; |
|
886 |
print "$table\n"; |
|
887 |
|
|
888 |
my $result = $self->select(table => $table, where => "'0' <> '0'"); |
|
889 |
my $sth = $result->sth; |
|
890 | ||
891 |
my $columns = $sth->{NAME}; |
|
892 |
my $data_types = $sth->{TYPE}; |
|
893 |
|
|
894 |
for (my $i = 0; $i < @$columns; $i++) { |
|
895 |
my $column = $columns->[$i]; |
|
896 |
my $data_type = $data_types->[$i]; |
|
897 |
print "$column: $data_type\n"; |
|
898 |
} |
|
899 |
} |
|
900 | ||
901 |
sub show_typename { |
|
902 |
my ($self, $t) = @_; |
|
903 |
croak "Table name must be specified" unless defined $t; |
|
904 |
print "$t\n"; |
|
905 |
|
|
906 |
$self->each_column(sub { |
|
907 |
my ($self, $table, $column, $infos) = @_; |
|
908 |
return unless $table eq $t; |
|
909 |
my $typename = $infos->{TYPE_NAME}; |
|
910 |
print "$column: $typename\n"; |
|
911 |
}); |
|
912 |
|
|
913 |
return $self; |
|
914 |
} |
|
915 | ||
test cleanup
|
916 |
sub show_tables { |
917 |
my $self = shift; |
|
918 |
|
|
919 |
my %tables; |
|
920 |
$self->each_table(sub { $tables{$_[1]}++ }); |
|
921 |
print join("\n", sort keys %tables) . "\n"; |
|
922 |
return $self; |
|
923 |
} |
|
924 | ||
added type_rule method and f...
|
925 |
sub type_rule { |
926 |
my $self = shift; |
|
micro optimization
|
927 | |
928 |
$self->{_type_rule_is_called} = 1; |
|
added type_rule method and f...
|
929 |
|
930 |
if (@_) { |
|
changed type_rule arguments ...
|
931 |
my $type_rule = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
fixed bug that type_rule fro...
|
932 |
|
933 |
# Into |
|
cleanup
|
934 |
for my $i (1 .. 2) { |
EXPERIMENTAL type_rule argum...
|
935 |
my $into = "into$i"; |
cleanup
|
936 |
my $exists_into = exists $type_rule->{$into}; |
EXPERIMENTAL type_rule argum...
|
937 |
$type_rule->{$into} = _array_to_hash($type_rule->{$into}); |
938 |
$self->{type_rule} = $type_rule; |
|
939 |
$self->{"_$into"} = {}; |
|
cleanup
|
940 |
for my $type_name (keys %{$type_rule->{$into} || {}}) { |
EXPERIMENTAL type_rule argum...
|
941 |
croak qq{type name of $into section must be lower case} |
942 |
if $type_name =~ /[A-Z]/; |
|
943 |
} |
|
cleanup
|
944 |
|
EXPERIMENTAL type_rule argum...
|
945 |
$self->each_column(sub { |
946 |
my ($dbi, $table, $column, $column_info) = @_; |
|
947 |
|
|
948 |
my $type_name = lc $column_info->{TYPE_NAME}; |
|
949 |
if ($type_rule->{$into} && |
|
950 |
(my $filter = $type_rule->{$into}->{$type_name})) |
|
type_rule can receive filter...
|
951 |
{ |
EXPERIMENTAL type_rule argum...
|
952 |
return unless exists $type_rule->{$into}->{$type_name}; |
953 |
if (defined $filter && ref $filter ne 'CODE') |
|
954 |
{ |
|
955 |
my $fname = $filter; |
|
956 |
croak qq{Filter "$fname" is not registered" } . _subname |
|
957 |
unless exists $self->filters->{$fname}; |
|
958 |
|
|
959 |
$filter = $self->filters->{$fname}; |
|
960 |
} |
|
961 | ||
micro optimization
|
962 |
$self->{"_$into"}{key}{$table}{$column} = $filter; |
963 |
$self->{"_$into"}{dot}{"$table.$column"} = $filter; |
|
EXPERIMENTAL type_rule argum...
|
964 |
} |
965 |
}); |
|
966 |
} |
|
967 | ||
968 |
# From |
|
cleanup
|
969 |
for my $i (1 .. 2) { |
EXPERIMENTAL type_rule argum...
|
970 |
$type_rule->{"from$i"} = _array_to_hash($type_rule->{"from$i"}); |
cleanup
|
971 |
for my $data_type (keys %{$type_rule->{"from$i"} || {}}) { |
EXPERIMENTAL type_rule argum...
|
972 |
croak qq{data type of from$i section must be lower case or number} |
973 |
if $data_type =~ /[A-Z]/; |
|
974 |
my $fname = $type_rule->{"from$i"}{$data_type}; |
|
975 |
if (defined $fname && ref $fname ne 'CODE') { |
|
type_rule can receive filter...
|
976 |
croak qq{Filter "$fname" is not registered" } . _subname |
977 |
unless exists $self->filters->{$fname}; |
|
978 |
|
|
EXPERIMENTAL type_rule argum...
|
979 |
$type_rule->{"from$i"}{$data_type} = $self->filters->{$fname}; |
type_rule can receive filter...
|
980 |
} |
fixed bug that type_rule fro...
|
981 |
} |
982 |
} |
|
983 |
|
|
added type_rule method and f...
|
984 |
return $self; |
985 |
} |
|
986 |
|
|
987 |
return $self->{type_rule} || {}; |
|
988 |
} |
|
989 | ||
cleanup
|
990 |
sub update { |
- insert, insert_at, update,...
|
991 |
my $self = shift; |
added EXPERIMENTAL reserved_...
|
992 | |
cleanup
|
993 |
# Options |
cleanup
|
994 |
my $param = @_ % 2 ? shift : undef; |
cleanup
|
995 |
my %opt = @_; |
cleanup
|
996 |
warn "update param option is DEPRECATED!" if $opt{param}; |
cleanup
|
997 |
warn "update method where_param option is DEPRECATED!" |
998 |
if $opt{where_param}; |
|
cleanup
|
999 |
$param ||= $opt{param} || {}; |
- added EXPERIMENTAL timesta...
|
1000 |
|
cleanup
|
1001 |
# Don't allow update all rows |
1002 |
croak qq{update method where option must be specified } . _subname |
|
1003 |
if !$opt{where} && !defined $opt{id} && !$opt{allow_update_all}; |
|
1004 |
|
|
- added EXPERIMENTAL timesta...
|
1005 |
# Timestamp |
cleanup
|
1006 |
if ($opt{timestamp} && (my $update_timestamp = $self->update_timestamp)) { |
- added EXPERIMENTAL update_...
|
1007 |
my $columns = $update_timestamp->[0]; |
1008 |
$columns = [$columns] unless ref $columns eq 'ARRAY'; |
|
1009 |
my $value = $update_timestamp->[1]; |
|
1010 |
$value = $value->() if ref $value eq 'CODE'; |
|
1011 |
$param->{$_} = $value for @$columns; |
|
- added EXPERIMENTAL timesta...
|
1012 |
} |
1013 | ||
cleanup
|
1014 |
# Assign clause |
cleanup
|
1015 |
my $assign_clause = $self->assign_clause($param, {wrap => $opt{wrap}}); |
cleanup
|
1016 |
|
1017 |
# Convert id to where parameter |
|
1018 |
my $where = defined $opt{id} |
|
moved DBIx::Custom::Guide to...
|
1019 |
? $self->_id_to_param(delete $opt{id}, $opt{primary_key}, $opt{table}) |
cleanup
|
1020 |
: $opt{where}; |
improved delete() and update...
|
1021 | |
1022 |
# Where |
|
cleanup
|
1023 |
my $w = $self->_where_clause_and_param($where, $opt{where_param}); |
removed reconnect method
|
1024 |
|
cleanup
|
1025 |
# Merge where parameter to parameter |
cleanup
|
1026 |
$param = $self->merge_param($param, $w->{param}) if keys %{$w->{param}}; |
DEPRECATED select() param op...
|
1027 |
|
cleanup
|
1028 |
# Update statement |
cleanup
|
1029 |
my $sql = "update "; |
1030 |
$sql .= "$opt{prefix} " if defined $opt{prefix}; |
|
cleanup
|
1031 |
$sql .= $self->_q($opt{table}) . " set $assign_clause $w->{clause} "; |
cleanup
|
1032 |
|
cleanup
|
1033 |
# Execute query |
micro optimization
|
1034 |
$self->execute($sql, $param, %opt); |
removed reconnect method
|
1035 |
} |
1036 | ||
cleanup
|
1037 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
1038 | ||
cleanup
|
1039 |
sub update_or_insert { |
1040 |
my $self = shift; |
|
1041 | ||
cleanup
|
1042 |
# Options |
cleanup
|
1043 |
my $param = shift; |
1044 |
my %opt = @_; |
|
1045 |
my $id = $opt{id}; |
|
1046 |
my $primary_key = $opt{primary_key}; |
|
1047 |
$primary_key = [$primary_key] unless ref $primary_key eq 'ARRAY'; |
|
1048 |
croak "update_or_insert method need primary_key option " . |
|
1049 |
"when id is specified" . _subname |
|
1050 |
if defined $id && !defined $primary_key; |
|
1051 |
my $table = $opt{table}; |
|
1052 |
croak qq{"table" option must be specified } . _subname |
|
1053 |
unless defined $table; |
|
1054 |
my $select_option = $opt{select_option}; |
|
1055 |
|
|
1056 |
my $rows = $self->select(table => $table, id => $id, |
|
1057 |
primary_key => $primary_key, %$select_option)->all; |
|
1058 |
|
|
1059 |
croak "selected row count must be one or zero" . _subname |
|
1060 |
if @$rows > 1; |
|
1061 |
|
|
1062 |
my $row = $rows->[0]; |
|
1063 |
my @opt = (table => $table); |
|
1064 |
push @opt, id => $id, primary_key => $primary_key if defined $id; |
|
1065 |
push @opt, %opt; |
|
1066 |
|
|
1067 |
if ($row) { |
|
1068 |
return $self->update($param, @opt); |
|
1069 |
} |
|
1070 |
else { |
|
1071 |
return $self->insert($param, @opt); |
|
1072 |
} |
|
1073 |
} |
|
1074 | ||
- added EXPERIMENTAL update_...
|
1075 |
sub update_timestamp { |
1076 |
my $self = shift; |
|
1077 |
|
|
1078 |
if (@_) { |
|
1079 |
$self->{update_timestamp} = [@_]; |
|
1080 |
|
|
1081 |
return $self; |
|
1082 |
} |
|
1083 |
return $self->{update_timestamp}; |
|
1084 |
} |
|
1085 | ||
- method method of DBIx::Cus...
|
1086 |
sub values_clause { |
1087 |
my ($self, $param, $opts) = @_; |
|
1088 |
|
|
1089 |
my $wrap = $opts->{wrap} || {}; |
|
1090 |
|
|
1091 |
# Create insert parameter tag |
|
micro optimization
|
1092 |
my $safety = $self->{safety_character} || $self->safety_character; |
improved performance
|
1093 |
my $qp = $self->_q(''); |
fixed some quoted bug
|
1094 |
my $q = substr($qp, 0, 1) || ''; |
1095 |
my $p = substr($qp, 1, 1) || ''; |
|
improved performance
|
1096 |
|
micro optimization
|
1097 |
# Check unsafety keys |
1098 |
unless ((join('', keys %$param) || '') =~ /^[$safety\.]+$/) { |
|
1099 |
for my $column (keys %$param) { |
|
1100 |
croak qq{"$column" is not safety column name } . _subname |
|
1101 |
unless $column =~ /^[$safety\.]+$/; |
|
1102 |
} |
|
1103 |
} |
|
- method method of DBIx::Cus...
|
1104 |
|
micro optimization
|
1105 |
# values clause(performance is important) |
micro optimization
|
1106 |
'(' . |
1107 |
join( |
|
1108 |
', ', |
|
1109 |
map { "$q$_$p" } sort keys %$param |
|
1110 |
) . |
|
1111 |
') values (' . |
|
1112 |
join( |
|
1113 |
', ', |
|
1114 |
map { |
|
1115 |
ref $param->{$_} eq 'SCALAR' ? ${$param->{$_}} : |
|
1116 |
$wrap->{$_} ? $wrap->{$_}->(":$_") : |
|
1117 |
":$_"; |
|
1118 |
} sort keys %$param |
|
1119 |
) . |
|
1120 |
')' |
|
- method method of DBIx::Cus...
|
1121 |
} |
1122 | ||
sub module use DBIx::Custom ...
|
1123 |
sub where { DBIx::Custom::Where->new(dbi => shift, @_) } |
added experimental DBIx::Cus...
|
1124 | |
updated pod
|
1125 |
sub _create_query { |
cleanup
|
1126 |
|
added EXPERIMENTAL reuse_que...
|
1127 |
my ($self, $source, $after_build_sql) = @_; |
cleanup
|
1128 |
|
updated pod
|
1129 |
# Cache |
1130 |
my $cache = $self->cache; |
|
1131 |
|
|
1132 |
# Query |
|
1133 |
my $query; |
|
1134 |
|
|
1135 |
# Get cached query |
|
1136 |
if ($cache) { |
|
cleanup
|
1137 |
|
updated pod
|
1138 |
# Get query |
1139 |
my $q = $self->cache_method->($self, $source); |
|
cleanup
|
1140 |
|
updated pod
|
1141 |
# Create query |
1142 |
if ($q) { |
|
1143 |
$query = DBIx::Custom::Query->new($q); |
|
DBIx::Custom::Query filters ...
|
1144 |
$query->{filters} = $self->filters; |
cleanup
|
1145 |
} |
updated pod
|
1146 |
} |
1147 |
|
|
1148 |
# Create query |
|
1149 |
unless ($query) { |
|
1150 | ||
1151 |
# Create query |
|
1152 |
my $builder = $self->query_builder; |
|
1153 |
$query = $builder->build_query($source); |
|
1154 | ||
1155 |
# Remove reserved word quote |
|
1156 |
if (my $q = $self->_quote) { |
|
added quote method's two cha...
|
1157 |
$q = quotemeta($q); |
1158 |
$_ =~ s/[$q]//g for @{$query->columns} |
|
cleanup
|
1159 |
} |
updated pod
|
1160 | |
1161 |
# Save query to cache |
|
1162 |
$self->cache_method->( |
|
1163 |
$self, $source, |
|
1164 |
{ |
|
1165 |
sql => $query->sql, |
|
1166 |
columns => $query->columns, |
|
DBIx::Custom::Query tables a...
|
1167 |
tables => $query->{tables} || [] |
updated pod
|
1168 |
} |
1169 |
) if $cache; |
|
cleanup
|
1170 |
} |
added EXPERIMENTAL execute m...
|
1171 | |
1172 |
# Filter SQL |
|
sqlfilter option is renamed ...
|
1173 |
if ($after_build_sql) { |
added EXPERIMENTAL execute m...
|
1174 |
my $sql = $query->sql; |
sqlfilter option is renamed ...
|
1175 |
$sql = $after_build_sql->($sql); |
added EXPERIMENTAL execute m...
|
1176 |
$query->sql($sql); |
1177 |
} |
|
1178 |
|
|
added EXPERIMENTAL last_sql ...
|
1179 |
# Save sql |
1180 |
$self->last_sql($query->sql); |
|
1181 |
|
|
updated pod
|
1182 |
# Prepare statement handle |
1183 |
my $sth; |
|
added EXPERIMENTAL reuse_que...
|
1184 |
eval { $sth = $self->dbh->prepare($query->{sql}) }; |
updated pod
|
1185 |
|
1186 |
if ($@) { |
|
1187 |
$self->_croak($@, qq{. Following SQL is executed.\n} |
|
1188 |
. qq{$query->{sql}\n} . _subname); |
|
1189 |
} |
|
1190 |
|
|
1191 |
# Set statement handle |
|
1192 |
$query->sth($sth); |
|
1193 |
|
|
1194 |
# Set filters |
|
DBIx::Custom::Query filters ...
|
1195 |
$query->{filters} = $self->filters; |
updated pod
|
1196 |
|
1197 |
return $query; |
|
cleanup
|
1198 |
} |
1199 | ||
cleanup
|
1200 |
sub _create_bind_values { |
EXPERIMENTAL type_rule argum...
|
1201 |
my ($self, $params, $columns, $filter, $type_filters, $bind_type) = @_; |
removed reconnect method
|
1202 |
|
micro optimization
|
1203 |
$bind_type = _array_to_hash($bind_type) if ref $bind_type eq 'ARRAY'; |
1204 |
|
|
cleanup
|
1205 |
# Create bind values |
micro optimization
|
1206 |
my @bind; |
1207 |
my @types; |
|
1208 |
my %count; |
|
1209 |
my %not_exists; |
|
cleanup
|
1210 |
for my $column (@$columns) { |
removed reconnect method
|
1211 |
|
micro optimization
|
1212 |
# Bind value |
added experimental not_exist...
|
1213 |
if(ref $params->{$column} eq 'ARRAY') { |
micro optimization
|
1214 |
my $i = $count{$column} || 0; |
1215 |
$i += $not_exists{$column} || 0; |
|
added experimental not_exist...
|
1216 |
my $found; |
1217 |
for (my $k = $i; $i < @{$params->{$column}}; $k++) { |
|
1218 |
if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') { |
|
micro optimization
|
1219 |
$not_exists{$column}++; |
added experimental not_exist...
|
1220 |
} |
1221 |
else { |
|
micro optimization
|
1222 |
push @bind, $params->{$column}->[$k]; |
added experimental not_exist...
|
1223 |
$found = 1; |
1224 |
last |
|
1225 |
} |
|
1226 |
} |
|
1227 |
next unless $found; |
|
1228 |
} |
|
micro optimization
|
1229 |
else { push @bind, $params->{$column} } |
removed reconnect method
|
1230 |
|
cleanup
|
1231 |
# Filter |
micro optimization
|
1232 |
if (my $f = $filter->{$column} || $self->{default_out_filter} || '') { |
micro optimization
|
1233 |
$bind[-1] = $f->($bind[-1]); |
micro optimization
|
1234 |
} |
separate DBIx::Custom type_r...
|
1235 |
|
1236 |
# Type rule |
|
micro optimization
|
1237 |
if ($self->{_type_rule_is_called}) { |
1238 |
my $tf1 = $self->{"_into1"}->{dot}->{$column} |
|
1239 |
|| $type_filters->{1}->{$column}; |
|
micro optimization
|
1240 |
$bind[-1] = $tf1->($bind[-1]) if $tf1; |
micro optimization
|
1241 |
my $tf2 = $self->{"_into2"}->{dot}->{$column} |
1242 |
|| $type_filters->{2}->{$column}; |
|
micro optimization
|
1243 |
$bind[-1] = $tf2->($bind[-1]) if $tf2; |
micro optimization
|
1244 |
} |
micro optimization
|
1245 |
|
micro optimization
|
1246 |
# Bind types |
micro optimization
|
1247 |
push @types, $bind_type->{$column}; |
removed reconnect method
|
1248 |
|
1249 |
# Count up |
|
micro optimization
|
1250 |
$count{$column}++; |
removed reconnect method
|
1251 |
} |
1252 |
|
|
micro optimization
|
1253 |
return (\@bind, \@types); |
removed reconnect method
|
1254 |
} |
1255 | ||
cleanup
|
1256 |
sub _id_to_param { |
fixed id option bug when col...
|
1257 |
my ($self, $id, $primary_keys, $table) = @_; |
cleanup
|
1258 |
|
1259 |
# Check primary key |
|
cleanup
|
1260 |
croak "primary_key option " . |
1261 |
"must be specified with id option " . _subname |
|
1262 |
unless defined $primary_keys; |
|
1263 |
$primary_keys = [$primary_keys] unless ref $primary_keys eq 'ARRAY'; |
|
improved error messages
|
1264 |
|
cleanup
|
1265 |
# Create parameter |
1266 |
my $param = {}; |
|
fixed small insert, update, ...
|
1267 |
if (defined $id) { |
cleanup
|
1268 |
$id = [$id] unless ref $id; |
1269 |
croak qq{"id" must be constant value or array reference} |
|
improved error messages
|
1270 |
. " (" . (caller 1)[3] . ")" |
cleanup
|
1271 |
unless !ref $id || ref $id eq 'ARRAY'; |
1272 |
croak qq{"id" must contain values same count as primary key} |
|
improved error messages
|
1273 |
. " (" . (caller 1)[3] . ")" |
cleanup
|
1274 |
unless @$primary_keys eq @$id; |
improved error messages
|
1275 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
fixed id option bug when col...
|
1276 |
my $key = $primary_keys->[$i]; |
1277 |
$key = "$table." . $key if $table; |
|
1278 |
$param->{$key} = $id->[$i]; |
|
improved error messages
|
1279 |
} |
1280 |
} |
|
1281 |
|
|
cleanup
|
1282 |
return $param; |
improved error messages
|
1283 |
} |
1284 | ||
EXPERIMETAL fork safety impl...
|
1285 |
sub _connect { |
1286 |
my $self = shift; |
|
1287 |
|
|
1288 |
# Attributes |
|
added warnings
|
1289 |
my $dsn = $self->data_source; |
- added EXPERIMENTAL order m...
|
1290 |
warn "data_source is DEPRECATED!\n" |
fixed bug that data_source D...
|
1291 |
if $dsn; |
added warnings
|
1292 |
$dsn ||= $self->dsn; |
data_source is DEPRECATED! I...
|
1293 |
croak qq{"dsn" must be specified } . _subname |
1294 |
unless $dsn; |
|
EXPERIMETAL fork safety impl...
|
1295 |
my $user = $self->user; |
1296 |
my $password = $self->password; |
|
- dbi_option attribute is re...
|
1297 |
my $option = $self->_option; |
1298 |
$option = {%{$self->default_option}, %$option}; |
|
cleanup
|
1299 |
|
EXPERIMETAL fork safety impl...
|
1300 |
# Connect |
cleanup
|
1301 |
my $dbh; |
1302 |
eval { |
|
1303 |
$dbh = DBI->connect( |
|
1304 |
$dsn, |
|
1305 |
$user, |
|
1306 |
$password, |
|
- dbi_option attribute is re...
|
1307 |
$option |
cleanup
|
1308 |
); |
1309 |
}; |
|
EXPERIMETAL fork safety impl...
|
1310 |
|
1311 |
# Connect error |
|
cleanup
|
1312 |
croak "$@ " . _subname if $@; |
EXPERIMETAL fork safety impl...
|
1313 |
|
1314 |
return $dbh; |
|
1315 |
} |
|
1316 | ||
cleanup
|
1317 |
sub _croak { |
1318 |
my ($self, $error, $append) = @_; |
|
cleanup
|
1319 |
|
1320 |
# Append |
|
cleanup
|
1321 |
$append ||= ""; |
1322 |
|
|
1323 |
# Verbose |
|
1324 |
if ($Carp::Verbose) { croak $error } |
|
1325 |
|
|
1326 |
# Not verbose |
|
1327 |
else { |
|
1328 |
|
|
1329 |
# Remove line and module infromation |
|
1330 |
my $at_pos = rindex($error, ' at '); |
|
1331 |
$error = substr($error, 0, $at_pos); |
|
1332 |
$error =~ s/\s+$//; |
|
1333 |
croak "$error$append"; |
|
1334 |
} |
|
1335 |
} |
|
1336 | ||
prepare oracle test
|
1337 |
sub _driver { lc shift->{dbh}->{Driver}->{Name} } |
1338 | ||
added select() all_column op...
|
1339 |
sub _need_tables { |
1340 |
my ($self, $tree, $need_tables, $tables) = @_; |
|
1341 |
|
|
cleanup
|
1342 |
# Get needed tables |
cleanup
|
1343 |
for my $table (@$tables) { |
added select() all_column op...
|
1344 |
if ($tree->{$table}) { |
1345 |
$need_tables->{$table} = 1; |
|
1346 |
$self->_need_tables($tree, $need_tables, [$tree->{$table}{parent}]) |
|
1347 |
} |
|
1348 |
} |
|
1349 |
} |
|
1350 | ||
- dbi_option attribute is re...
|
1351 |
sub _option { |
1352 |
my $self = shift; |
|
1353 |
my $option = {%{$self->dbi_options}, %{$self->dbi_option}, %{$self->option}}; |
|
1354 |
warn "dbi_options is DEPRECATED! use option instead\n" |
|
1355 |
if keys %{$self->dbi_options}; |
|
1356 |
warn "dbi_option is DEPRECATED! use option instead\n" |
|
1357 |
if keys %{$self->dbi_option}; |
|
1358 |
return $option; |
|
1359 |
} |
|
1360 | ||
fixed some select() join opi...
|
1361 |
sub _push_join { |
1362 |
my ($self, $sql, $join, $join_tables) = @_; |
|
1363 |
|
|
cleanup
|
1364 |
$join = [$join] unless ref $join eq 'ARRAY'; |
cleanup
|
1365 |
|
cleanup
|
1366 |
# No join |
fixed some select() join opi...
|
1367 |
return unless @$join; |
1368 |
|
|
cleanup
|
1369 |
# Push join clause |
fixed some select() join opi...
|
1370 |
my $tree = {}; |
1371 |
for (my $i = 0; $i < @$join; $i++) { |
|
1372 |
|
|
cleanup
|
1373 |
# Arrange |
added join new syntax
|
1374 |
my $join_clause;; |
1375 |
my $option; |
|
1376 |
if (ref $join->[$i] eq 'HASH') { |
|
1377 |
$join_clause = $join->[$i]->{clause}; |
|
1378 |
$option = {table => $join->[$i]->{table}}; |
|
1379 |
} |
|
1380 |
else { |
|
1381 |
$join_clause = $join->[$i]; |
|
1382 |
$option = {}; |
|
1383 |
}; |
|
cleanup
|
1384 | |
1385 |
# Find tables in join clause |
|
added join new syntax
|
1386 |
my $table1; |
1387 |
my $table2; |
|
1388 |
if (my $table = $option->{table}) { |
|
1389 |
$table1 = $table->[0]; |
|
1390 |
$table2 = $table->[1]; |
|
fixed some select() join opi...
|
1391 |
} |
cleanup
|
1392 |
else { |
1393 |
my $q = $self->_quote; |
|
1394 |
my $j_clause = (split /\s+on\s+/, $join_clause)[-1]; |
|
1395 |
$j_clause =~ s/'.+?'//g; |
|
1396 |
my $q_re = quotemeta($q); |
|
added quote method's two cha...
|
1397 |
$j_clause =~ s/[$q_re]//g; |
improved join clause parsing
|
1398 |
|
1399 |
my @j_clauses = reverse split /\s(and|on)\s/, $j_clause; |
|
cleanup
|
1400 |
my $c = $self->safety_character; |
- update_param is DEPRECATED...
|
1401 |
my $join_re = qr/($c+)\.$c+[^$c].*?($c+)\.$c+/sm; |
improved join clause parsing
|
1402 |
for my $clause (@j_clauses) { |
1403 |
if ($clause =~ $join_re) { |
|
1404 |
$table1 = $1; |
|
1405 |
$table2 = $2; |
|
1406 |
last; |
|
1407 |
} |
|
cleanup
|
1408 |
} |
fixed some select() join opi...
|
1409 |
} |
added join new syntax
|
1410 |
croak qq{join clause must have two table name after "on" keyword. } . |
1411 |
qq{"$join_clause" is passed } . _subname |
|
1412 |
unless defined $table1 && defined $table2; |
|
1413 |
croak qq{right side table of "$join_clause" must be unique } |
|
1414 |
. _subname |
|
1415 |
if exists $tree->{$table2}; |
|
1416 |
croak qq{Same table "$table1" is specified} . _subname |
|
1417 |
if $table1 eq $table2; |
|
1418 |
$tree->{$table2} |
|
1419 |
= {position => $i, parent => $table1, join => $join_clause}; |
|
fixed some select() join opi...
|
1420 |
} |
1421 |
|
|
cleanup
|
1422 |
# Search need tables |
fixed some select() join opi...
|
1423 |
my $need_tables = {}; |
1424 |
$self->_need_tables($tree, $need_tables, $join_tables); |
|
cleanup
|
1425 |
my @need_tables = sort { $tree->{$a}{position} <=> $tree->{$b}{position} } |
1426 |
keys %$need_tables; |
|
cleanup
|
1427 |
|
1428 |
# Add join clause |
|
cleanup
|
1429 |
$$sql .= $tree->{$_}{join} . ' ' for @need_tables; |
fixed some select() join opi...
|
1430 |
} |
cleanup
|
1431 | |
reserved_word_quote is DEPRE...
|
1432 |
sub _quote { |
1433 |
my $self = shift; |
|
micro optimization
|
1434 |
return $self->{reserved_word_quote} || $self->quote || ''; |
reserved_word_quote is DEPRE...
|
1435 |
} |
1436 | ||
cleanup
|
1437 |
sub _q { |
fixex [] reserved_word_quote...
|
1438 |
my ($self, $value, $quotemeta) = @_; |
cleanup
|
1439 |
|
micro optimization
|
1440 |
my $quote = $self->{reserved_word_quote} |
1441 |
|| $self->{quote} || $self->quote || ''; |
|
1442 |
return "$quote$value$quote" |
|
1443 |
if !$quotemeta && ($quote eq '`' || $quote eq '"'); |
|
1444 |
|
|
cleanup
|
1445 |
my $q = substr($quote, 0, 1) || ''; |
added quote method's two cha...
|
1446 |
my $p; |
1447 |
if (defined $quote && length $quote > 1) { |
|
1448 |
$p = substr($quote, 1, 1); |
|
1449 |
} |
|
1450 |
else { $p = $q } |
|
cleanup
|
1451 |
|
fixex [] reserved_word_quote...
|
1452 |
if ($quotemeta) { |
1453 |
$q = quotemeta($q); |
|
1454 |
$p = quotemeta($p); |
|
1455 |
} |
|
1456 |
|
|
added quote method's two cha...
|
1457 |
return "$q$value$p"; |
cleanup
|
1458 |
} |
1459 | ||
cleanup
|
1460 |
sub _remove_duplicate_table { |
1461 |
my ($self, $tables, $main_table) = @_; |
|
1462 |
|
|
1463 |
# Remove duplicate table |
|
1464 |
my %tables = map {defined $_ ? ($_ => 1) : ()} @$tables; |
|
1465 |
delete $tables{$main_table} if $main_table; |
|
1466 |
|
|
micro optimization
|
1467 |
my $new_tables = [keys %tables, $main_table ? $main_table : ()]; |
1468 |
if (my $q = $self->_quote) { |
|
1469 |
$q = quotemeta($q); |
|
1470 |
$_ =~ s/[$q]//g for @$new_tables; |
|
1471 |
} |
|
1472 | ||
1473 |
return $new_tables; |
|
cleanup
|
1474 |
} |
1475 | ||
cleanup
|
1476 |
sub _search_tables { |
cleanup
|
1477 |
my ($self, $source) = @_; |
1478 |
|
|
cleanup
|
1479 |
# Search tables |
cleanup
|
1480 |
my $tables = []; |
1481 |
my $safety_character = $self->safety_character; |
|
reserved_word_quote is DEPRE...
|
1482 |
my $q = $self->_quote; |
fixex [] reserved_word_quote...
|
1483 |
my $quoted_safety_character_re = $self->_q("?([$safety_character]+)", 1); |
1484 |
my $table_re = $q ? qr/(?:^|[^$safety_character])${quoted_safety_character_re}?\./ |
|
improved table search in col...
|
1485 |
: qr/(?:^|[^$safety_character])([$safety_character]+)\./; |
cleanup
|
1486 |
while ($source =~ /$table_re/g) { |
1487 |
push @$tables, $1; |
|
1488 |
} |
|
1489 |
|
|
1490 |
return $tables; |
|
1491 |
} |
|
1492 | ||
cleanup
|
1493 |
sub _where_to_obj { |
where can recieve array refr...
|
1494 |
my ($self, $where) = @_; |
1495 |
|
|
cleanup
|
1496 |
my $obj; |
1497 |
|
|
1498 |
# Hash |
|
where can recieve array refr...
|
1499 |
if (ref $where eq 'HASH') { |
1500 |
my $clause = ['and']; |
|
reserved_word_quote is DEPRE...
|
1501 |
my $q = $self->_quote; |
cleanup
|
1502 |
for my $column (keys %$where) { |
fixex [] reserved_word_quote...
|
1503 |
my $table; |
1504 |
my $c; |
|
1505 |
if ($column =~ /(?:(.*?)\.)?(.*)/) { |
|
1506 |
$table = $1; |
|
1507 |
$c = $2; |
|
1508 |
} |
|
1509 |
|
|
1510 |
my $table_quote; |
|
1511 |
$table_quote = $self->_q($table) if defined $table; |
|
1512 |
my $column_quote = $self->_q($c); |
|
1513 |
$column_quote = $table_quote . '.' . $column_quote |
|
1514 |
if defined $table_quote; |
|
- update_param_tag is DEPREC...
|
1515 |
push @$clause, "$column_quote = :$column" for keys %$where; |
added EXPERIMENTAL reserved_...
|
1516 |
} |
cleanup
|
1517 |
$obj = $self->where(clause => $clause, param => $where); |
where can recieve array refr...
|
1518 |
} |
cleanup
|
1519 |
|
1520 |
# DBIx::Custom::Where object |
|
where can recieve array refr...
|
1521 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
cleanup
|
1522 |
$obj = $where; |
where can recieve array refr...
|
1523 |
} |
cleanup
|
1524 |
|
updated pod
|
1525 |
# Array |
where can recieve array refr...
|
1526 |
elsif (ref $where eq 'ARRAY') { |
cleanup
|
1527 |
$obj = $self->where( |
where can recieve array refr...
|
1528 |
clause => $where->[0], |
1529 |
param => $where->[1] |
|
1530 |
); |
|
1531 |
} |
|
1532 |
|
|
cleanup
|
1533 |
# Check where argument |
improved error messages
|
1534 |
croak qq{"where" must be hash reference or DBIx::Custom::Where object} |
DBIx::Custom::Model type att...
|
1535 |
. qq{or array reference, which contains where clause and parameter} |
cleanup
|
1536 |
. _subname |
cleanup
|
1537 |
unless ref $obj eq 'DBIx::Custom::Where'; |
where can recieve array refr...
|
1538 |
|
cleanup
|
1539 |
return $obj; |
where can recieve array refr...
|
1540 |
} |
1541 | ||
cleanup
|
1542 |
sub _where_clause_and_param { |
1543 |
my ($self, $where, $param) = @_; |
|
1544 |
|
|
1545 |
$where ||= {}; |
|
1546 |
$param ||= {}; |
|
1547 |
my $w = {}; |
|
1548 |
my $where_clause = ''; |
|
1549 |
if (ref $where eq 'ARRAY' && !ref $where->[0]) { |
|
1550 |
$w->{clause} = "where " . $where->[0]; |
|
1551 |
$w->{param} = $where->[1]; |
|
1552 |
} |
|
1553 |
elsif (ref $where) { |
|
1554 |
$where = $self->_where_to_obj($where); |
|
1555 |
$w->{param} = keys %$param |
|
1556 |
? $self->merge_param($param, $where->param) |
|
1557 |
: $where->param; |
|
1558 |
$w->{clause} = $where->to_string; |
|
1559 |
} |
|
1560 |
elsif ($where) { |
|
1561 |
$w->{clause} = "where $where"; |
|
1562 |
$w->{param} = $param; |
|
1563 |
} |
|
1564 |
|
|
1565 |
return $w; |
|
1566 |
} |
|
1567 | ||
updated pod
|
1568 |
sub _apply_filter { |
1569 |
my ($self, $table, @cinfos) = @_; |
|
1570 | ||
1571 |
# Initialize filters |
|
1572 |
$self->{filter} ||= {}; |
|
micro optimization
|
1573 |
$self->{filter}{on} = 1; |
updated pod
|
1574 |
$self->{filter}{out} ||= {}; |
1575 |
$self->{filter}{in} ||= {}; |
|
1576 |
$self->{filter}{end} ||= {}; |
|
1577 |
|
|
1578 |
# Usage |
|
1579 |
my $usage = "Usage: \$dbi->apply_filter(" . |
|
1580 |
"TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " . |
|
1581 |
"COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)"; |
|
1582 |
|
|
1583 |
# Apply filter |
|
1584 |
for (my $i = 0; $i < @cinfos; $i += 2) { |
|
1585 |
|
|
1586 |
# Column |
|
1587 |
my $column = $cinfos[$i]; |
|
1588 |
if (ref $column eq 'ARRAY') { |
|
cleanup
|
1589 |
for my $c (@$column) { |
updated pod
|
1590 |
push @cinfos, $c, $cinfos[$i + 1]; |
1591 |
} |
|
1592 |
next; |
|
1593 |
} |
|
1594 |
|
|
1595 |
# Filter infomation |
|
1596 |
my $finfo = $cinfos[$i + 1] || {}; |
|
1597 |
croak "$usage (table: $table) " . _subname |
|
1598 |
unless ref $finfo eq 'HASH'; |
|
cleanup
|
1599 |
for my $ftype (keys %$finfo) { |
updated pod
|
1600 |
croak "$usage (table: $table) " . _subname |
1601 |
unless $ftype eq 'in' || $ftype eq 'out' || $ftype eq 'end'; |
|
1602 |
} |
|
1603 |
|
|
1604 |
# Set filters |
|
cleanup
|
1605 |
for my $way (qw/in out end/) { |
updated pod
|
1606 |
|
1607 |
# Filter |
|
1608 |
my $filter = $finfo->{$way}; |
|
1609 |
|
|
1610 |
# Filter state |
|
1611 |
my $state = !exists $finfo->{$way} ? 'not_exists' |
|
1612 |
: !defined $filter ? 'not_defined' |
|
1613 |
: ref $filter eq 'CODE' ? 'code' |
|
1614 |
: 'name'; |
|
1615 |
|
|
1616 |
# Filter is not exists |
|
1617 |
next if $state eq 'not_exists'; |
|
1618 |
|
|
1619 |
# Check filter name |
|
1620 |
croak qq{Filter "$filter" is not registered } . _subname |
|
1621 |
if $state eq 'name' |
|
1622 |
&& ! exists $self->filters->{$filter}; |
|
1623 |
|
|
1624 |
# Set filter |
|
1625 |
my $f = $state eq 'not_defined' ? undef |
|
1626 |
: $state eq 'code' ? $filter |
|
1627 |
: $self->filters->{$filter}; |
|
1628 |
$self->{filter}{$way}{$table}{$column} = $f; |
|
1629 |
$self->{filter}{$way}{$table}{"$table.$column"} = $f; |
|
1630 |
$self->{filter}{$way}{$table}{"${table}__$column"} = $f; |
|
1631 |
$self->{filter}{$way}{$table}{"${table}-$column"} = $f; |
|
1632 |
} |
|
1633 |
} |
|
1634 |
|
|
1635 |
return $self; |
|
1636 |
} |
|
1637 | ||
- update_param is DEPRECATED...
|
1638 |
# DEPRECATED! |
1639 |
has 'data_source'; |
|
1640 |
has dbi_options => sub { {} }; |
|
1641 |
has filter_check => 1; |
|
1642 |
has 'reserved_word_quote'; |
|
- dbi_option attribute is re...
|
1643 |
has dbi_option => sub { {} }; |
1644 |
has default_dbi_option => sub { |
|
1645 |
warn "default_dbi_option is DEPRECATED! use default_option instead"; |
|
1646 |
return shift->default_option; |
|
1647 |
}; |
|
1648 | ||
- method method of DBIx::Cus...
|
1649 |
# DEPRECATED! |
1650 |
sub method { |
|
1651 |
warn "method is DEPRECATED! use helper instead"; |
|
1652 |
return shift->helper(@_); |
|
1653 |
} |
|
- update_param is DEPRECATED...
|
1654 | |
1655 |
# DEPRECATED! |
|
1656 |
sub assign_param { |
|
1657 |
my $self = shift; |
|
1658 |
warn "assing_param is DEPRECATED! use assign_clause instead"; |
|
1659 |
return $self->assign_clause(@_); |
|
1660 |
} |
|
1661 | ||
1662 |
# DEPRECATED |
|
1663 |
sub update_param { |
|
1664 |
my ($self, $param, $opts) = @_; |
|
1665 |
|
|
micro optimization
|
1666 |
warn "update_param is DEPRECATED! use assign_clause instead."; |
- update_param is DEPRECATED...
|
1667 |
|
1668 |
# Create update parameter tag |
|
1669 |
my $tag = $self->assign_clause($param, $opts); |
|
1670 |
$tag = "set $tag" unless $opts->{no_set}; |
|
1671 | ||
1672 |
return $tag; |
|
1673 |
} |
|
1674 | ||
updated pod
|
1675 |
# DEPRECATED! |
1676 |
sub create_query { |
|
1677 |
warn "create_query is DEPRECATED! use query option of each method"; |
|
1678 |
shift->_create_query(@_); |
|
1679 |
} |
|
1680 | ||
cleanup
|
1681 |
# DEPRECATED! |
1682 |
sub apply_filter { |
|
1683 |
my $self = shift; |
|
1684 |
|
|
- added EXPERIMENTAL order m...
|
1685 |
warn "apply_filter is DEPRECATED!"; |
cleanup
|
1686 |
return $self->_apply_filter(@_); |
1687 |
} |
|
1688 | ||
select_at is DEPRECATED! use...
|
1689 |
# DEPRECATED! |
1690 |
sub select_at { |
|
cleanup
|
1691 |
my ($self, %opt) = @_; |
select_at is DEPRECATED! use...
|
1692 | |
cleanup
|
1693 |
warn "select_at is DEPRECATED! use select method id option instead"; |
updated pod
|
1694 | |
cleanup
|
1695 |
# Options |
cleanup
|
1696 |
my $primary_keys = delete $opt{primary_key}; |
select_at is DEPRECATED! use...
|
1697 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
cleanup
|
1698 |
my $where = delete $opt{where}; |
1699 |
my $param = delete $opt{param}; |
|
select_at is DEPRECATED! use...
|
1700 |
|
1701 |
# Table |
|
1702 |
croak qq{"table" option must be specified } . _subname |
|
cleanup
|
1703 |
unless $opt{table}; |
1704 |
my $table = ref $opt{table} ? $opt{table}->[-1] : $opt{table}; |
|
select_at is DEPRECATED! use...
|
1705 |
|
1706 |
# Create where parameter |
|
cleanup
|
1707 |
my $where_param = $self->_id_to_param($where, $primary_keys); |
select_at is DEPRECATED! use...
|
1708 |
|
cleanup
|
1709 |
return $self->select(where => $where_param, %opt); |
select_at is DEPRECATED! use...
|
1710 |
} |
1711 | ||
delete_at is DEPRECATED! use...
|
1712 |
# DEPRECATED! |
1713 |
sub delete_at { |
|
cleanup
|
1714 |
my ($self, %opt) = @_; |
updated pod
|
1715 | |
cleanup
|
1716 |
warn "delete_at is DEPRECATED! use delete method id option instead"; |
delete_at is DEPRECATED! use...
|
1717 |
|
cleanup
|
1718 |
# Options |
cleanup
|
1719 |
my $primary_keys = delete $opt{primary_key}; |
delete_at is DEPRECATED! use...
|
1720 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
cleanup
|
1721 |
my $where = delete $opt{where}; |
delete_at is DEPRECATED! use...
|
1722 |
|
1723 |
# Create where parameter |
|
cleanup
|
1724 |
my $where_param = $self->_id_to_param($where, $primary_keys); |
delete_at is DEPRECATED! use...
|
1725 |
|
cleanup
|
1726 |
return $self->delete(where => $where_param, %opt); |
delete_at is DEPRECATED! use...
|
1727 |
} |
1728 | ||
cleanup
|
1729 |
# DEPRECATED! |
1730 |
sub update_at { |
|
1731 |
my $self = shift; |
|
1732 | ||
cleanup
|
1733 |
warn "update_at is DEPRECATED! use update method id option instead"; |
cleanup
|
1734 |
|
cleanup
|
1735 |
# Options |
cleanup
|
1736 |
my $param; |
1737 |
$param = shift if @_ % 2; |
|
cleanup
|
1738 |
my %opt = @_; |
1739 |
my $primary_keys = delete $opt{primary_key}; |
|
cleanup
|
1740 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
cleanup
|
1741 |
my $where = delete $opt{where}; |
1742 |
my $p = delete $opt{param} || {}; |
|
cleanup
|
1743 |
$param ||= $p; |
1744 |
|
|
1745 |
# Create where parameter |
|
cleanup
|
1746 |
my $where_param = $self->_id_to_param($where, $primary_keys); |
cleanup
|
1747 |
|
cleanup
|
1748 |
return $self->update(where => $where_param, param => $param, %opt); |
cleanup
|
1749 |
} |
1750 | ||
insert_at is DEPRECATED! add...
|
1751 |
# DEPRECATED! |
1752 |
sub insert_at { |
|
1753 |
my $self = shift; |
|
1754 |
|
|
cleanup
|
1755 |
warn "insert_at is DEPRECATED! use insert method id option instead"; |
insert_at is DEPRECATED! add...
|
1756 |
|
cleanup
|
1757 |
# Options |
insert_at is DEPRECATED! add...
|
1758 |
my $param; |
1759 |
$param = shift if @_ % 2; |
|
cleanup
|
1760 |
my %opt = @_; |
1761 |
my $primary_key = delete $opt{primary_key}; |
|
insert_at is DEPRECATED! add...
|
1762 |
$primary_key = [$primary_key] unless ref $primary_key; |
cleanup
|
1763 |
my $where = delete $opt{where}; |
1764 |
my $p = delete $opt{param} || {}; |
|
insert_at is DEPRECATED! add...
|
1765 |
$param ||= $p; |
1766 |
|
|
1767 |
# Create where parameter |
|
cleanup
|
1768 |
my $where_param = $self->_id_to_param($where, $primary_key); |
insert_at is DEPRECATED! add...
|
1769 |
$param = $self->merge_param($where_param, $param); |
1770 |
|
|
cleanup
|
1771 |
return $self->insert(param => $param, %opt); |
insert_at is DEPRECATED! add...
|
1772 |
} |
1773 | ||
added warnings
|
1774 |
# DEPRECATED! |
1775 |
sub register_tag { |
|
test cleanup
|
1776 |
my $self = shift; |
1777 |
|
|
added warnings
|
1778 |
warn "register_tag is DEPRECATED!"; |
test cleanup
|
1779 |
|
1780 |
# Merge tag |
|
1781 |
my $tags = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
1782 |
$self->{_tags} = {%{$self->{_tags} || {}}, %$tags}; |
|
1783 |
|
|
1784 |
return $self; |
|
1785 |
} |
|
1786 | ||
1787 |
# DEPRECATED! |
|
1788 |
sub register_tag_processor { |
|
1789 |
my $self = shift; |
|
1790 |
warn "register_tag_processor is DEPRECATED!"; |
|
1791 |
# Merge tag |
|
1792 |
my $tag_processors = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
1793 |
$self->{_tags} = {%{$self->{_tags} || {}}, %{$tag_processors}}; |
|
1794 |
return $self; |
|
added warnings
|
1795 |
} |
1796 | ||
cleanup
|
1797 |
# DEPRECATED! |
cleanup
|
1798 |
sub default_bind_filter { |
1799 |
my $self = shift; |
|
1800 |
|
|
cleanup
|
1801 |
warn "default_bind_filter is DEPRECATED!"; |
added warnings
|
1802 |
|
cleanup
|
1803 |
if (@_) { |
1804 |
my $fname = $_[0]; |
|
1805 |
|
|
1806 |
if (@_ && !$fname) { |
|
1807 |
$self->{default_out_filter} = undef; |
|
1808 |
} |
|
1809 |
else { |
|
many changed
|
1810 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1811 |
unless exists $self->filters->{$fname}; |
1812 |
|
|
1813 |
$self->{default_out_filter} = $self->filters->{$fname}; |
|
1814 |
} |
|
1815 |
return $self; |
|
1816 |
} |
|
1817 |
|
|
1818 |
return $self->{default_out_filter}; |
|
1819 |
} |
|
1820 | ||
cleanup
|
1821 |
# DEPRECATED! |
cleanup
|
1822 |
sub default_fetch_filter { |
1823 |
my $self = shift; |
|
added warnings
|
1824 | |
cleanup
|
1825 |
warn "default_fetch_filter is DEPRECATED!"; |
cleanup
|
1826 |
|
1827 |
if (@_) { |
|
many changed
|
1828 |
my $fname = $_[0]; |
1829 | ||
cleanup
|
1830 |
if (@_ && !$fname) { |
1831 |
$self->{default_in_filter} = undef; |
|
1832 |
} |
|
1833 |
else { |
|
many changed
|
1834 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1835 |
unless exists $self->filters->{$fname}; |
1836 |
|
|
1837 |
$self->{default_in_filter} = $self->filters->{$fname}; |
|
1838 |
} |
|
1839 |
|
|
1840 |
return $self; |
|
1841 |
} |
|
1842 |
|
|
many changed
|
1843 |
return $self->{default_in_filter}; |
cleanup
|
1844 |
} |
1845 | ||
- update_param is DEPRECATED...
|
1846 |
# DEPRECATED! |
1847 |
sub insert_param { |
|
1848 |
my $self = shift; |
|
1849 |
warn "insert_param is DEPRECATED! use values_clause instead"; |
|
1850 |
return $self->values_clause(@_); |
|
1851 |
} |
|
1852 | ||
- renamed update_param to up...
|
1853 |
# DEPRECATED! |
- update_param_tag is DEPREC...
|
1854 |
sub insert_param_tag { |
1855 |
warn "insert_param_tag is DEPRECATED! " . |
|
1856 |
"use insert_param instead!"; |
|
1857 |
return shift->insert_param(@_); |
|
- renamed update_param to up...
|
1858 |
} |
1859 | ||
1860 |
# DEPRECATED! |
|
- update_param_tag is DEPREC...
|
1861 |
sub update_param_tag { |
fixed DEPRECATED message bug
|
1862 |
warn "update_param_tag is DEPRECATED! " . |
- update_param_tag is DEPREC...
|
1863 |
"use update_param instead"; |
1864 |
return shift->update_param(@_); |
|
- renamed update_param to up...
|
1865 |
} |
cleanup
|
1866 |
# DEPRECATED! |
1867 |
sub _push_relation { |
|
1868 |
my ($self, $sql, $tables, $relation, $need_where) = @_; |
|
1869 |
|
|
1870 |
if (keys %{$relation || {}}) { |
|
micro optimization
|
1871 |
$$sql .= $need_where ? 'where ' : 'and '; |
cleanup
|
1872 |
for my $rcolumn (keys %$relation) { |
cleanup
|
1873 |
my $table1 = (split (/\./, $rcolumn))[0]; |
1874 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1875 |
push @$tables, ($table1, $table2); |
|
micro optimization
|
1876 |
$$sql .= "$rcolumn = " . $relation->{$rcolumn} . 'and '; |
cleanup
|
1877 |
} |
1878 |
} |
|
micro optimization
|
1879 |
$$sql =~ s/and $/ /; |
cleanup
|
1880 |
} |
1881 | ||
1882 |
# DEPRECATED! |
|
1883 |
sub _add_relation_table { |
|
cleanup
|
1884 |
my ($self, $tables, $relation) = @_; |
cleanup
|
1885 |
|
1886 |
if (keys %{$relation || {}}) { |
|
cleanup
|
1887 |
for my $rcolumn (keys %$relation) { |
cleanup
|
1888 |
my $table1 = (split (/\./, $rcolumn))[0]; |
1889 |
my $table2 = (split (/\./, $relation->{$rcolumn}))[0]; |
|
1890 |
my $table1_exists; |
|
1891 |
my $table2_exists; |
|
cleanup
|
1892 |
for my $table (@$tables) { |
cleanup
|
1893 |
$table1_exists = 1 if $table eq $table1; |
1894 |
$table2_exists = 1 if $table eq $table2; |
|
1895 |
} |
|
1896 |
unshift @$tables, $table1 unless $table1_exists; |
|
1897 |
unshift @$tables, $table2 unless $table2_exists; |
|
1898 |
} |
|
1899 |
} |
|
1900 |
} |
|
1901 | ||
fixed DBIx::Custom::QueryBui...
|
1902 |
1; |
1903 | ||
removed reconnect method
|
1904 |
=head1 NAME |
1905 | ||
moved DBIx::Custom::Guide to...
|
1906 |
DBIx::Custom - DBI extension to execute insert, update, delete, and select easily |
removed reconnect method
|
1907 | |
fix heading typos
|
1908 |
=head1 SYNOPSIS |
cleanup
|
1909 | |
renamed build_query to creat...
|
1910 |
use DBIx::Custom; |
- remaned experimental safty...
|
1911 |
|
1912 |
# Connect |
|
1913 |
my $dbi = DBIx::Custom->connect( |
|
data_source is DEPRECATED! I...
|
1914 |
dsn => "dbi:mysql:database=dbname", |
- remaned experimental safty...
|
1915 |
user => 'ken', |
1916 |
password => '!LFKD%$&', |
|
- dbi_option attribute is re...
|
1917 |
option => {mysql_enable_utf8 => 1} |
- remaned experimental safty...
|
1918 |
); |
cleanup
|
1919 | |
removed reconnect method
|
1920 |
# Insert |
updated pod
|
1921 |
$dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book'); |
removed reconnect method
|
1922 |
|
1923 |
# Update |
|
updated pod
|
1924 |
$dbi->update({title => 'Perl', author => 'Ken'}, table => 'book', |
1925 |
where => {id => 5}); |
|
removed reconnect method
|
1926 |
|
1927 |
# Delete |
|
updated pod
|
1928 |
$dbi->delete(table => 'book', where => {author => 'Ken'}); |
cleanup
|
1929 | |
removed reconnect method
|
1930 |
# Select |
updated pod
|
1931 |
my $result = $dbi->select(table => 'book', |
1932 |
column => ['title', 'author'], where => {author => 'Ken'}); |
|
cleanup
|
1933 | |
- remaned experimental safty...
|
1934 |
# Select, more complex |
1935 |
my $result = $dbi->select( |
|
1936 |
table => 'book', |
|
1937 |
column => [ |
|
cleanup
|
1938 |
{book => [qw/title author/]}, |
1939 |
{company => ['name']} |
|
- remaned experimental safty...
|
1940 |
], |
1941 |
where => {'book.author' => 'Ken'}, |
|
1942 |
join => ['left outer join company on book.company_id = company.id'], |
|
1943 |
append => 'order by id limit 5' |
|
removed reconnect method
|
1944 |
); |
- remaned experimental safty...
|
1945 |
|
removed register_format()
|
1946 |
# Fetch |
1947 |
while (my $row = $result->fetch) { |
|
- remaned experimental safty...
|
1948 |
|
removed register_format()
|
1949 |
} |
1950 |
|
|
- remaned experimental safty...
|
1951 |
# Fetch as hash |
removed register_format()
|
1952 |
while (my $row = $result->fetch_hash) { |
1953 |
|
|
1954 |
} |
|
1955 |
|
|
- remaned experimental safty...
|
1956 |
# Execute SQL with parameter. |
1957 |
$dbi->execute( |
|
- update_param_tag is DEPREC...
|
1958 |
"select id from book where author = :author and title like :title", |
updated pod
|
1959 |
{author => 'ken', title => '%Perl%'} |
- remaned experimental safty...
|
1960 |
); |
1961 |
|
|
fix heading typos
|
1962 |
=head1 DESCRIPTION |
removed reconnect method
|
1963 | |
cleanup
|
1964 |
L<DBIx::Custom> is L<DBI> wrapper module to execute SQL easily. |
updated pod
|
1965 |
This module have the following features. |
- remaned experimental safty...
|
1966 | |
updated pod
|
1967 |
=over 4 |
- remaned experimental safty...
|
1968 | |
cleanup
|
1969 |
=item * |
- remaned experimental safty...
|
1970 | |
cleanup
|
1971 |
Execute C<insert>, C<update>, C<delete>, or C<select> statement easily |
- remaned experimental safty...
|
1972 | |
cleanup
|
1973 |
=item * |
- remaned experimental safty...
|
1974 | |
cleanup
|
1975 |
Create C<where> clause flexibly |
- remaned experimental safty...
|
1976 | |
cleanup
|
1977 |
=item * |
- remaned experimental safty...
|
1978 | |
micro optimization
|
1979 |
Named place holder support |
1980 | ||
1981 |
=item * |
|
1982 | ||
cleanup
|
1983 |
Model support |
1984 | ||
1985 |
=item * |
|
1986 | ||
1987 |
Connection manager support |
|
1988 | ||
1989 |
=item * |
|
pod fix
|
1990 | |
cleanup
|
1991 |
Choice your favorite relational database management system, |
cleanup
|
1992 |
C<MySQL>, C<SQLite>, C<PostgreSQL>, C<Oracle>, |
1993 |
C<Microsoft SQL Server>, C<Microsoft Access>, C<DB2> or anything, |
|
1994 | ||
1995 |
=item * |
|
1996 | ||
- removed EXPERIMENTAL flag ...
|
1997 |
Filtering by data type or column name |
cleanup
|
1998 | |
1999 |
=item * |
|
2000 | ||
- removed EXPERIMENTAL flag ...
|
2001 |
Create C<order by> clause flexibly |
cleanup
|
2002 | |
2003 |
=back |
|
pod fix
|
2004 | |
fix heading typos
|
2005 |
=head1 DOCUMENTATION |
pod fix
|
2006 | |
cleanup
|
2007 |
L<DBIx::Custom::Guide> - How to use L<DBIx::Custom> |
pod fix
|
2008 | |
- remaned experimental safty...
|
2009 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> |
cleanup
|
2010 |
- Theare are various examples. |
2011 | ||
micro optimization
|
2012 |
Module documentations - |
cleanup
|
2013 |
L<DBIx::Custom::Result>, |
2014 |
L<DBIx::Custom::Query>, |
|
2015 |
L<DBIx::Custom::Where>, |
|
2016 |
L<DBIx::Custom::Model>, |
|
2017 |
L<DBIx::Custom::Order> |
|
updated document
|
2018 | |
update document
|
2019 |
=head1 ATTRIBUTES |
packaging one directory
|
2020 | |
- removed DEPRECATED DBIx::C...
|
2021 |
=head2 C<connector> |
- removed EXPERIMENTAL Prefo...
|
2022 | |
2023 |
my $connector = $dbi->connector; |
|
micro optimization
|
2024 |
$dbi = $dbi->connector($connector); |
- removed EXPERIMENTAL Prefo...
|
2025 | |
micro optimization
|
2026 |
Connection manager object. if C<connector> is set, you can get C<dbh> |
2027 |
through connection manager. Conection manager object must have C<dbh> mehtod. |
|
- removed EXPERIMENTAL Prefo...
|
2028 | |
2029 |
This is L<DBIx::Connector> example. Please pass |
|
- dbi_option attribute is re...
|
2030 |
C<default_option> to L<DBIx::Connector> C<new> method. |
- removed EXPERIMENTAL Prefo...
|
2031 | |
2032 |
my $connector = DBIx::Connector->new( |
|
cleanup
|
2033 |
"dbi:mysql:database=$database", |
2034 |
$user, |
|
2035 |
$password, |
|
- dbi_option attribute is re...
|
2036 |
DBIx::Custom->new->default_option |
- removed EXPERIMENTAL Prefo...
|
2037 |
); |
2038 |
|
|
updated pod
|
2039 |
my $dbi = DBIx::Custom->connect(connector => $connector); |
- removed EXPERIMENTAL Prefo...
|
2040 | |
cleanup
|
2041 |
If C<connector> is set to 1 when connect method is called, |
2042 |
L<DBIx::Connector> is automatically set to C<connector> |
|
2043 | ||
2044 |
my $dbi = DBIx::Custom->connect( |
|
2045 |
dsn => $dsn, user => $user, password => $password, connector => 1); |
|
2046 |
|
|
2047 |
my $connector = $dbi->connector; # DBIx::Connector |
|
2048 | ||
2049 |
Note that L<DBIx::Connector> must be installed. |
|
2050 | ||
data_source is DEPRECATED! I...
|
2051 |
=head2 C<dsn> |
2052 | ||
2053 |
my $dsn = $dbi->dsn; |
|
reserved_word_quote is DEPRE...
|
2054 |
$dbi = $dbi->dsn("DBI:mysql:database=dbname"); |
packaging one directory
|
2055 | |
updated pod
|
2056 |
Data source name, used when C<connect> method is executed. |
removed DESTROY method(not b...
|
2057 | |
- dbi_option attribute is re...
|
2058 |
=head2 C<default_option> |
add default_dbi_option()
|
2059 | |
- dbi_option attribute is re...
|
2060 |
my $default_option = $dbi->default_option; |
2061 |
$dbi = $dbi->default_option($default_option); |
|
add default_dbi_option()
|
2062 | |
updated pod
|
2063 |
L<DBI> default option, used when C<connect> method is executed, |
- remaned experimental safty...
|
2064 |
default to the following values. |
add default_dbi_option()
|
2065 | |
- remaned experimental safty...
|
2066 |
{ |
2067 |
RaiseError => 1, |
|
2068 |
PrintError => 0, |
|
2069 |
AutoCommit => 1, |
|
2070 |
} |
|
packaging one directory
|
2071 | |
removed EXPERIMETNAL flag fr...
|
2072 |
=head2 C<exclude_table> |
2073 | ||
2074 |
my $exclude_table = $dbi->exclude_table; |
|
2075 |
$dbi = $dbi->exclude_table(qr/pg_/); |
|
2076 | ||
2077 |
Excluded table regex. |
|
2078 |
C<each_column>, C<each_table>, C<type_rule>, |
|
2079 |
and C<setup_model> methods ignore matching tables. |
|
2080 | ||
cleanup
|
2081 |
=head2 C<filters> |
bind_filter argument is chan...
|
2082 | |
cleanup
|
2083 |
my $filters = $dbi->filters; |
reserved_word_quote is DEPRE...
|
2084 |
$dbi = $dbi->filters(\%filters); |
packaging one directory
|
2085 | |
updated pod
|
2086 |
Filters, registered by C<register_filter> method. |
add models() attribute
|
2087 | |
- removed EXPERIMENTAL statu...
|
2088 |
=head2 C<last_sql> |
added EXPERIMENTAL last_sql ...
|
2089 | |
2090 |
my $last_sql = $dbi->last_sql; |
|
2091 |
$dbi = $dbi->last_sql($last_sql); |
|
2092 | ||
2093 |
Get last successed SQL executed by C<execute> method. |
|
2094 | ||
- removed DEPRECATED DBIx::C...
|
2095 |
=head2 C<models> |
add models() attribute
|
2096 | |
2097 |
my $models = $dbi->models; |
|
reserved_word_quote is DEPRE...
|
2098 |
$dbi = $dbi->models(\%models); |
add models() attribute
|
2099 | |
updated pod
|
2100 |
Models, included by C<include_model> method. |
add models() attribute
|
2101 | |
removed EXPERIMETNAL flag fr...
|
2102 |
=head2 C<option> |
2103 | ||
2104 |
my $option = $dbi->option; |
|
2105 |
$dbi = $dbi->option($option); |
|
2106 | ||
2107 |
L<DBI> option, used when C<connect> method is executed. |
|
2108 |
Each value in option override the value of C<default_option>. |
|
2109 | ||
cleanup
|
2110 |
=head2 C<password> |
2111 | ||
2112 |
my $password = $dbi->password; |
|
reserved_word_quote is DEPRE...
|
2113 |
$dbi = $dbi->password('lkj&le`@s'); |
cleanup
|
2114 | |
updated pod
|
2115 |
Password, used when C<connect> method is executed. |
update document
|
2116 | |
renamed update tag to update...
|
2117 |
=head2 C<query_builder> |
added commit method
|
2118 | |
test cleanup
|
2119 |
my $builder = $dbi->query_builder; |
added commit method
|
2120 | |
test cleanup
|
2121 |
Creat query builder. This is L<DBIx::Custom::QueryBuilder>. |
cleanup
|
2122 | |
reserved_word_quote is DEPRE...
|
2123 |
=head2 C<quote> |
added EXPERIMENTAL reserved_...
|
2124 | |
reserved_word_quote is DEPRE...
|
2125 |
my quote = $dbi->quote; |
2126 |
$dbi = $dbi->quote('"'); |
|
added EXPERIMENTAL reserved_...
|
2127 | |
DBIx::Custom::Model type att...
|
2128 |
Reserved word quote. |
2129 |
Default to double quote '"' except for mysql. |
|
2130 |
In mysql, default to back quote '`' |
|
added EXPERIMENTAL reserved_...
|
2131 | |
cleanup
|
2132 |
You can set quote pair. |
2133 | ||
2134 |
$dbi->quote('[]'); |
|
2135 | ||
cleanup
|
2136 |
=head2 C<result_class> |
cleanup
|
2137 | |
cleanup
|
2138 |
my $result_class = $dbi->result_class; |
reserved_word_quote is DEPRE...
|
2139 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
cleanup
|
2140 | |
- remaned experimental safty...
|
2141 |
Result class, default to L<DBIx::Custom::Result>. |
cleanup
|
2142 | |
removed EXPERIMETNAL flag fr...
|
2143 |
=head2 C<safety_character> |
update pod
|
2144 | |
fixed pod
|
2145 |
my $safety_character = $dbi->safety_character; |
2146 |
$dbi = $dbi->safety_character($character); |
|
update pod
|
2147 | |
update pod
|
2148 |
Regex of safety character for table and column name, default to '\w'. |
cleanup
|
2149 |
Note that you don't have to specify like '[\w]'. |
update pod
|
2150 | |
cleanup test
|
2151 |
=head2 C<separator> |
2152 | ||
fixed pod
|
2153 |
my $separator = $dbi->separator; |
2154 |
$dbi = $dbi->separator('-'); |
|
improved join clause parsing
|
2155 | |
2156 |
Separator which join table name and column name. |
|
2157 |
This have effect to C<column> and C<mycolumn> method, |
|
2158 |
and C<select> method's column option. |
|
cleanup test
|
2159 | |
improved join clause parsing
|
2160 |
Default to C<.>. |
cleanup test
|
2161 | |
added tag_parse attribute
|
2162 |
=head2 C<tag_parse> |
2163 | ||
2164 |
my $tag_parse = $dbi->tag_parse(0); |
|
2165 |
$dbi = $dbi->tag_parse; |
|
2166 | ||
2167 |
Enable DEPRECATED tag parsing functionality, default to 1. |
|
2168 |
If you want to disable tag parsing functionality, set to 0. |
|
2169 | ||
cleanup
|
2170 |
=head2 C<user> |
cleanup
|
2171 | |
cleanup
|
2172 |
my $user = $dbi->user; |
reserved_word_quote is DEPRE...
|
2173 |
$dbi = $dbi->user('Ken'); |
cleanup
|
2174 | |
updated pod
|
2175 |
User name, used when C<connect> method is executed. |
update pod
|
2176 | |
- removed EXPERIMENTAL flag ...
|
2177 |
=head2 C<user_column_info> |
- added EXPERIMENTAL get_col...
|
2178 | |
2179 |
my $user_column_info = $dbi->user_column_info; |
|
2180 |
$dbi = $dbi->user_column_info($user_column_info); |
|
2181 | ||
improved join clause parsing
|
2182 |
You can set the date like the following one. |
- added EXPERIMENTAL get_col...
|
2183 | |
2184 |
[ |
|
2185 |
{table => 'book', column => 'title', info => {...}}, |
|
2186 |
{table => 'author', column => 'name', info => {...}} |
|
2187 |
] |
|
2188 | ||
improved join clause parsing
|
2189 |
Usually, you set return value of C<get_column_info>. |
- added EXPERIMENTAL get_col...
|
2190 | |
2191 |
my $user_column_info |
|
2192 |
= $dbi->get_column_info(exclude_table => qr/^system/); |
|
2193 |
$dbi->user_column_info($user_column_info); |
|
2194 | ||
2195 |
If C<user_column_info> is set, C<each_column> use C<user_column_info> |
|
- removed EXPERIMENTAL flag ...
|
2196 |
to find column info. this is very fast. |
- added EXPERIMENTAL get_col...
|
2197 | |
- removed EXPERIMENTAL flag ...
|
2198 |
=head2 C<user_table_info> |
added test
|
2199 | |
2200 |
my $user_table_info = $dbi->user_table_info; |
|
2201 |
$dbi = $dbi->user_table_info($user_table_info); |
|
2202 | ||
2203 |
You can set the following data. |
|
2204 | ||
2205 |
[ |
|
2206 |
{table => 'book', info => {...}}, |
|
2207 |
{table => 'author', info => {...}} |
|
2208 |
] |
|
2209 | ||
2210 |
Usually, you can set return value of C<get_table_info>. |
|
2211 | ||
2212 |
my $user_table_info = $dbi->get_table_info(exclude => qr/^system/); |
|
2213 |
$dbi->user_table_info($user_table_info); |
|
2214 | ||
2215 |
If C<user_table_info> is set, C<each_table> use C<user_table_info> |
|
2216 |
to find table info. |
|
2217 | ||
cleanup
|
2218 |
=head1 METHODS |
added commit method
|
2219 | |
cleanup
|
2220 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
cleanup
|
2221 |
and use all methods of L<DBI> |
cleanup
|
2222 |
and implements the following new ones. |
added check_filter attribute
|
2223 | |
- removed EXPERIMENTAL flag ...
|
2224 |
=head2 C<available_datatype> |
changed type_rule arguments ...
|
2225 | |
added EXPERIMENTAL DBIx::Cus...
|
2226 |
print $dbi->available_datatype; |
changed type_rule arguments ...
|
2227 | |
added EXPERIMENTAL available...
|
2228 |
Get available data types. You can use these data types |
updated pod
|
2229 |
in C<type rule>'s C<from1> and C<from2> section. |
added EXPERIMENTAL available...
|
2230 | |
- removed EXPERIMENTAL flag ...
|
2231 |
=head2 C<available_typename> |
added EXPERIMENTAL available...
|
2232 | |
added EXPERIMENTAL DBIx::Cus...
|
2233 |
print $dbi->available_typename; |
added EXPERIMENTAL available...
|
2234 | |
2235 |
Get available type names. You can use these type names in |
|
updated pod
|
2236 |
C<type_rule>'s C<into1> and C<into2> section. |
changed type_rule arguments ...
|
2237 | |
- update_param is DEPRECATED...
|
2238 |
=head2 C<assign_clause> |
added EXPERIMENTAL assign_ta...
|
2239 | |
- update_param is DEPRECATED...
|
2240 |
my $assign_clause = $dbi->assign_clause({title => 'a', age => 2}); |
added EXPERIMENTAL assign_ta...
|
2241 | |
- update_param is DEPRECATED...
|
2242 |
Create assign clause |
added EXPERIMENTAL assign_ta...
|
2243 | |
- update_param_tag is DEPREC...
|
2244 |
title = :title, author = :author |
added EXPERIMENTAL assign_ta...
|
2245 | |
- update_param is DEPRECATED...
|
2246 |
This is used to create update clause. |
2247 | ||
2248 |
"update book set " . $dbi->assign_clause({title => 'a', age => 2}); |
|
added EXPERIMENTAL assign_ta...
|
2249 | |
added EXPERIMENTAL parameter...
|
2250 |
=head2 C<column> |
- select() EXPERIMETNAL colu...
|
2251 | |
cleanup
|
2252 |
my $column = $dbi->column(book => ['author', 'title']); |
- select() EXPERIMETNAL colu...
|
2253 | |
2254 |
Create column clause. The follwoing column clause is created. |
|
2255 | ||
2256 |
book.author as "book.author", |
|
2257 |
book.title as "book.title" |
|
2258 | ||
cleanup test
|
2259 |
You can change separator by C<separator> attribute. |
- select() EXPERIMETNAL colu...
|
2260 | |
cleanup
|
2261 |
# Separator is hyphen |
2262 |
$dbi->separator('-'); |
|
2263 |
|
|
2264 |
book.author as "book-author", |
|
2265 |
book.title as "book-title" |
|
2266 |
|
|
removed DBIx::Custom commit ...
|
2267 |
=head2 C<connect> |
packaging one directory
|
2268 | |
update pod
|
2269 |
my $dbi = DBIx::Custom->connect( |
data_source is DEPRECATED! I...
|
2270 |
dsn => "dbi:mysql:database=dbname", |
update pod
|
2271 |
user => 'ken', |
2272 |
password => '!LFKD%$&', |
|
- dbi_option attribute is re...
|
2273 |
option => {mysql_enable_utf8 => 1} |
update pod
|
2274 |
); |
2275 | ||
2276 |
Connect to the database and create a new L<DBIx::Custom> object. |
|
bind_filter argument is chan...
|
2277 | |
renamed build_query to creat...
|
2278 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
2279 |
C<AutoCommit> and C<RaiseError> options are true, |
update pod
|
2280 |
and C<PrintError> option is false by default. |
packaging one directory
|
2281 | |
- removed EXPERIMENTAL flag ...
|
2282 |
=head2 C<count> |
- added EXPERIMENTAL DBIx::C...
|
2283 | |
fixed id option bug when col...
|
2284 |
my $count = $dbi->count(table => 'book'); |
- added EXPERIMENTAL DBIx::C...
|
2285 | |
2286 |
Get rows count. |
|
2287 | ||
2288 |
Options is same as C<select> method's ones. |
|
2289 | ||
2290 |
=head2 C<create_model> |
|
removed EXPERIMETNAL flag fr...
|
2291 | |
adeed EXPERIMENTAL DBIx::Cus...
|
2292 |
my $model = $dbi->create_model( |
removed EXPERIMETNAL flag fr...
|
2293 |
table => 'book', |
2294 |
primary_key => 'id', |
|
2295 |
join => [ |
|
2296 |
'inner join company on book.comparny_id = company.id' |
|
2297 |
], |
|
2298 |
); |
|
2299 | ||
2300 |
Create L<DBIx::Custom::Model> object and initialize model. |
|
updated pod
|
2301 |
the module is also used from C<model> method. |
removed EXPERIMETNAL flag fr...
|
2302 | |
2303 |
$dbi->model('book')->select(...); |
|
2304 | ||
EXPERIMETAL fork safety impl...
|
2305 |
=head2 C<dbh> |
2306 | ||
2307 |
my $dbh = $dbi->dbh; |
|
2308 | ||
- removed EXPERIMENTAL Prefo...
|
2309 |
Get L<DBI> database handle. if C<connector> is set, you can get |
updated pod
|
2310 |
database handle through C<connector> object. |
removed EXPERIMETNAL flag fr...
|
2311 | |
added EXPERIMENTAL find_tabl...
|
2312 |
=head2 C<delete> |
2313 | ||
2314 |
$dbi->delete(table => 'book', where => {title => 'Perl'}); |
|
2315 | ||
2316 |
Execute delete statement. |
|
2317 | ||
2318 |
The following opitons are available. |
|
2319 | ||
cleanup
|
2320 |
B<OPTIONS> |
added EXPERIMENTAL find_tabl...
|
2321 | |
cleanup
|
2322 |
C<delete> method use all of C<execute> method's options, |
2323 |
and use the following new ones. |
|
added EXPERIMENTAL find_tabl...
|
2324 | |
cleanup
|
2325 |
=over 4 |
added EXPERIMENTAL find_tabl...
|
2326 | |
2327 |
=item C<id> |
|
2328 | ||
2329 |
id => 4 |
|
2330 |
id => [4, 5] |
|
2331 | ||
2332 |
ID corresponding to C<primary_key>. |
|
2333 |
You can delete rows by C<id> and C<primary_key>. |
|
2334 | ||
2335 |
$dbi->delete( |
|
fixed pod
|
2336 |
primary_key => ['id1', 'id2'], |
added EXPERIMENTAL find_tabl...
|
2337 |
id => [4, 5], |
2338 |
table => 'book', |
|
2339 |
); |
|
2340 | ||
2341 |
The above is same as the followin one. |
|
2342 | ||
2343 |
$dbi->delete(where => {id1 => 4, id2 => 5}, table => 'book'); |
|
2344 | ||
2345 |
=item C<prefix> |
|
2346 | ||
2347 |
prefix => 'some' |
|
2348 | ||
2349 |
prefix before table name section. |
|
2350 | ||
2351 |
delete some from book |
|
2352 | ||
2353 |
=item C<table> |
|
2354 | ||
2355 |
table => 'book' |
|
2356 | ||
2357 |
Table name. |
|
2358 | ||
2359 |
=item C<where> |
|
2360 | ||
2361 |
Same as C<select> method's C<where> option. |
|
2362 | ||
2363 |
=back |
|
2364 | ||
2365 |
=head2 C<delete_all> |
|
2366 | ||
2367 |
$dbi->delete_all(table => $table); |
|
2368 | ||
2369 |
Execute delete statement for all rows. |
|
2370 |
Options is same as C<delete>. |
|
2371 | ||
removed EXPERIMETNAL flag fr...
|
2372 |
=head2 C<each_column> |
2373 | ||
2374 |
$dbi->each_column( |
|
2375 |
sub { |
|
2376 |
my ($dbi, $table, $column, $column_info) = @_; |
|
2377 |
|
|
2378 |
my $type = $column_info->{TYPE_NAME}; |
|
2379 |
|
|
2380 |
if ($type eq 'DATE') { |
|
2381 |
# ... |
|
2382 |
} |
|
2383 |
} |
|
2384 |
); |
|
2385 | ||
improved pod
|
2386 |
Iterate all column informations in database. |
2387 |
Argument is callback which is executed when one column is found. |
|
2388 |
Callback receive four arguments. C<DBIx::Custom object>, C<table name>, |
|
2389 |
C<column name>, and C<column information>. |
|
2390 | ||
2391 |
If C<user_column_info> is set, C<each_column> method use C<user_column_info> |
|
2392 |
infromation, you can improve the performance of C<each_column> in |
|
2393 |
the following way. |
|
2394 | ||
2395 |
my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/); |
|
2396 |
$dbi->user_column_info($column_info); |
|
2397 |
$dbi->each_column(sub { ... }); |
|
EXPERIMETAL fork safety impl...
|
2398 | |
- removed EXPERIMENTAL statu...
|
2399 |
=head2 C<each_table> |
added EXPERIMENTAL each_tabl...
|
2400 | |
2401 |
$dbi->each_table( |
|
2402 |
sub { |
|
2403 |
my ($dbi, $table, $table_info) = @_; |
|
2404 |
|
|
2405 |
my $table_name = $table_info->{TABLE_NAME}; |
|
2406 |
} |
|
2407 |
); |
|
2408 | ||
improved pod
|
2409 |
Iterate all table informationsfrom in database. |
2410 |
Argument is callback which is executed when one table is found. |
|
2411 |
Callback receive three arguments, C<DBIx::Custom object>, C<table name>, |
|
2412 |
C<table information>. |
|
2413 | ||
2414 |
If C<user_table_info> is set, C<each_table> method use C<user_table_info> |
|
2415 |
infromation, you can improve the performance of C<each_table> in |
|
2416 |
the following way. |
|
2417 | ||
2418 |
my $table_infos = $dbi->get_table_info(exclude => qr/^system_/); |
|
2419 |
$dbi->user_table_info($table_info); |
|
2420 |
$dbi->each_table(sub { ... }); |
|
added EXPERIMENTAL each_tabl...
|
2421 | |
cleanup
|
2422 |
=head2 C<execute> |
packaging one directory
|
2423 | |
update pod
|
2424 |
my $result = $dbi->execute( |
updated pod
|
2425 |
"select * from book where title = :title and author like :author", |
2426 |
{title => 'Perl', author => '%Ken%'} |
|
2427 |
); |
|
2428 | ||
2429 |
my $result = $dbi->execute( |
|
2430 |
"select * from book where title = :book.title and author like :book.author", |
|
2431 |
{'book.title' => 'Perl', 'book.author' => '%Ken%'} |
|
update pod
|
2432 |
); |
2433 | ||
updated pod
|
2434 |
Execute SQL. SQL can contain column parameter such as :author and :title. |
2435 |
You can append table name to column name such as :book.title and :book.author. |
|
2436 |
Second argunet is data, embedded into column parameter. |
|
2437 |
Return value is L<DBIx::Custom::Result> object when select statement is executed, |
|
2438 |
or the count of affected rows when insert, update, delete statement is executed. |
|
update pod
|
2439 | |
I call :title named placehol...
|
2440 |
Named placeholder such as C<:title> is replaced by placeholder C<?>. |
added EXPERIMENTAL parameter...
|
2441 |
|
micro optimization
|
2442 |
# Original |
added EXPERIMENTAL parameter...
|
2443 |
select * from book where title = :title and author like :author |
2444 |
|
|
micro optimization
|
2445 |
# Replaced |
added EXPERIMENTAL parameter...
|
2446 |
select * from where title = ? and author like ?; |
update pod
|
2447 | |
I call :title named placehol...
|
2448 |
You can specify operator with named placeholder |
fixed pod
|
2449 |
by C<name{operator}> syntax. |
added EXPERIMENTAL parameter...
|
2450 | |
micro optimization
|
2451 |
# Original |
added EXPERIMENTAL parameter...
|
2452 |
select * from book where :title{=} and :author{like} |
2453 |
|
|
micro optimization
|
2454 |
# Replaced |
update pod
|
2455 |
select * from where title = ? and author like ?; |
2456 | ||
fixed named placeholder bug ...
|
2457 |
Note that colons in time format such as 12:13:15 is exeption, |
2458 |
it is not parsed as named placeholder. |
|
2459 |
If you want to use colon generally, you must escape it by C<\\> |
|
2460 | ||
2461 |
select * from where title = "aa\\:bb"; |
|
2462 | ||
cleanup
|
2463 |
B<OPTIONS> |
2464 | ||
updated pod
|
2465 |
The following opitons are available. |
update pod
|
2466 | |
2467 |
=over 4 |
|
2468 | ||
added EXPERIMENTAL reuse_sth...
|
2469 |
=item C<after_build_sql> |
2470 | ||
2471 |
You can filter sql after the sql is build. |
|
2472 | ||
2473 |
after_build_sql => $code_ref |
|
2474 | ||
2475 |
The following one is one example. |
|
2476 | ||
2477 |
$dbi->select( |
|
2478 |
table => 'book', |
|
2479 |
column => 'distinct(name)', |
|
2480 |
after_build_sql => sub { |
|
2481 |
"select count(*) from ($_[0]) as t1" |
|
2482 |
} |
|
2483 |
); |
|
2484 | ||
2485 |
The following SQL is executed. |
|
2486 | ||
2487 |
select count(*) from (select distinct(name) from book) as t1; |
|
2488 | ||
cleanup
|
2489 |
=item C<append> |
2490 | ||
2491 |
append => 'order by name' |
|
2492 | ||
2493 |
Append some statement after SQL. |
|
2494 | ||
added EXPERIMENTAL execute m...
|
2495 |
=item C<bind_type> |
2496 | ||
2497 |
Specify database bind data type. |
|
2498 | ||
2499 |
bind_type => [image => DBI::SQL_BLOB] |
|
2500 |
bind_type => [[qw/image audio/] => DBI::SQL_BLOB] |
|
2501 | ||
2502 |
This is used to bind parameter by C<bind_param> of statment handle. |
|
2503 | ||
2504 |
$sth->bind_param($pos, $value, DBI::SQL_BLOB); |
|
2505 | ||
update pod
|
2506 |
=item C<filter> |
updated pod
|
2507 |
|
2508 |
filter => { |
|
2509 |
title => sub { uc $_[0] } |
|
2510 |
author => sub { uc $_[0] } |
|
2511 |
} |
|
update pod
|
2512 | |
updated pod
|
2513 |
# Filter name |
2514 |
filter => { |
|
2515 |
title => 'upper_case', |
|
2516 |
author => 'upper_case' |
|
2517 |
} |
|
2518 |
|
|
2519 |
# At once |
|
2520 |
filter => [ |
|
2521 |
[qw/title author/] => sub { uc $_[0] } |
|
2522 |
] |
|
2523 | ||
separate DBIx::Custom type_r...
|
2524 |
Filter. You can set subroutine or filter name |
updated pod
|
2525 |
registered by by C<register_filter>. |
separate DBIx::Custom type_r...
|
2526 |
This filter is executed before data is saved into database. |
2527 |
and before type rule filter is executed. |
|
added EXPERIMENTAL execute()...
|
2528 | |
- removed placeholder count ...
|
2529 |
=item C<id> |
2530 | ||
2531 |
id => 4 |
|
2532 |
id => [4, 5] |
|
2533 | ||
2534 |
ID corresponding to C<primary_key>. |
|
2535 |
You can delete rows by C<id> and C<primary_key>. |
|
2536 | ||
2537 |
$dbi->execute( |
|
2538 |
"select * from book where id1 = :id1 and id2 = :id2", |
|
2539 |
{}, |
|
fixed pod
|
2540 |
primary_key => ['id1', 'id2'], |
- removed placeholder count ...
|
2541 |
id => [4, 5], |
2542 |
); |
|
2543 | ||
2544 |
The above is same as the followin one. |
|
2545 | ||
2546 |
$dbi->execute( |
|
2547 |
"select * from book where id1 = :id1 and id2 = :id2", |
|
2548 |
{id1 => 4, id2 => 5} |
|
2549 |
); |
|
2550 | ||
updated document
|
2551 |
=item C<query> |
2552 | ||
2553 |
query => 1 |
|
2554 | ||
2555 |
C<execute> method return L<DBIx::Custom::Query> object, not executing SQL. |
|
cleanup
|
2556 |
You can check SQL or get statment handle. |
updated pod
|
2557 | |
2558 |
my $sql = $query->sql; |
|
cleanup
|
2559 |
my $sth = $query->sth; |
Added execute method's query...
|
2560 |
my $columns = $query->columns; |
2561 |
|
|
2562 |
If you want to execute SQL fast, you can do the following way. |
|
2563 | ||
2564 |
my $query; |
|
cleanup
|
2565 |
for my $row (@$rows) { |
Added execute method's query...
|
2566 |
$query ||= $dbi->insert($row, table => 'table1', query => 1); |
cleanup
|
2567 |
$dbi->execute($query, $row); |
Added execute method's query...
|
2568 |
} |
2569 | ||
2570 |
Statement handle is reused and SQL parsing is finished, |
|
2571 |
so you can get more performance than normal way. |
|
cleanup
|
2572 | |
2573 |
If you want to execute SQL as possible as fast and don't need filtering. |
|
Added execute method's query...
|
2574 |
You can do the following way. |
cleanup
|
2575 |
|
2576 |
my $query; |
|
2577 |
my $sth; |
|
cleanup
|
2578 |
for my $row (@$rows) { |
cleanup
|
2579 |
$query ||= $dbi->insert($row, table => 'book', query => 1); |
2580 |
$sth ||= $query->sth; |
|
2581 |
$sth->execute(map { $row->{$_} } sort keys %$row); |
|
2582 |
} |
|
2583 | ||
2584 |
Note that $row must be simple hash reference, such as |
|
2585 |
{title => 'Perl', author => 'Ken'}. |
|
2586 |
and don't forget to sort $row values by $row key asc order. |
|
updated document
|
2587 | |
- removed placeholder count ...
|
2588 |
=item C<primary_key> |
2589 | ||
cleanup
|
2590 |
primary_key => 'id' |
2591 |
primary_key => ['id1', 'id2'] |
|
2592 | ||
2593 |
Priamry key. This is used when C<id> option find primary key. |
|
- removed placeholder count ...
|
2594 | |
updated pod
|
2595 |
=item C<table> |
2596 |
|
|
2597 |
table => 'author' |
|
2598 | ||
updated pod
|
2599 |
If you want to omit table name in column name |
2600 |
and enable C<into1> and C<into2> type filter, |
|
2601 |
You must set C<table> option. |
|
updated pod
|
2602 | |
updated pod
|
2603 |
$dbi->execute("select * from book where title = :title and author = :author", |
2604 |
{title => 'Perl', author => 'Ken', table => 'book'); |
|
updated pod
|
2605 | |
updated pod
|
2606 |
# Same |
2607 |
$dbi->execute( |
|
2608 |
"select * from book where title = :book.title and author = :book.author", |
|
2609 |
{title => 'Perl', author => 'Ken'); |
|
added EXPERIMENTAL execute()...
|
2610 | |
- removed EXPERIMENTAL flag ...
|
2611 |
=item C<table_alias> |
added EXPERIMENTAL execute m...
|
2612 | |
cleanup
|
2613 |
table_alias => {user => 'worker'} |
added EXPERIMENTAL execute m...
|
2614 | |
2615 |
Table alias. Key is real table name, value is alias table name. |
|
2616 |
If you set C<table_alias>, you can enable C<into1> and C<into2> type rule |
|
2617 |
on alias table name. |
|
2618 | ||
added EXPERIMENTAL reuse_que...
|
2619 |
=item C<reuse EXPERIMENTAL> |
added EXPERIMENTAL reuse_sth...
|
2620 |
|
added EXPERIMENTAL reuse_que...
|
2621 |
reuse_query => $has_ref |
added EXPERIMENTAL reuse_sth...
|
2622 | |
added EXPERIMENTAL reuse_que...
|
2623 |
Reuse query object if the hash reference variable is set. |
added EXPERIMENTAL reuse_sth...
|
2624 |
|
added EXPERIMENTAL reuse_que...
|
2625 |
my $queries = {}; |
2626 |
$dbi->execute($sql, $param, reuse => $queries); |
|
added EXPERIMENTAL reuse_sth...
|
2627 | |
added EXPERIMENTAL reuse_que...
|
2628 |
This will improved performance when you want to execute same query repeatedly |
2629 |
because generally creating query object is slow. |
|
added EXPERIMENTAL reuse_sth...
|
2630 | |
- removed EXPERIMENTAL flag ...
|
2631 |
=item C<type_rule_off> |
added EXPERIMENTAL execute()...
|
2632 | |
2633 |
type_rule_off => 1 |
|
2634 | ||
EXPERIMENTAL type_rule argum...
|
2635 |
Turn C<into1> and C<into2> type rule off. |
2636 | ||
- removed EXPERIMENTAL flag ...
|
2637 |
=item C<type_rule1_off> |
EXPERIMENTAL type_rule argum...
|
2638 | |
2639 |
type_rule1_off => 1 |
|
2640 | ||
2641 |
Turn C<into1> type rule off. |
|
2642 | ||
- removed EXPERIMENTAL flag ...
|
2643 |
=item C<type_rule2_off> |
EXPERIMENTAL type_rule argum...
|
2644 | |
2645 |
type_rule2_off => 1 |
|
2646 | ||
2647 |
Turn C<into2> type rule off. |
|
update document
|
2648 | |
update pod
|
2649 |
=back |
version 0.0901
|
2650 | |
- removed EXPERIMENTAL flag ...
|
2651 |
=head2 C<get_column_info> |
- added EXPERIMENTAL get_col...
|
2652 | |
improved pod
|
2653 |
my $column_infos = $dbi->get_column_info(exclude_table => qr/^system_/); |
- added EXPERIMENTAL get_col...
|
2654 | |
2655 |
get column infomation except for one which match C<exclude_table> pattern. |
|
2656 | ||
2657 |
[ |
|
2658 |
{table => 'book', column => 'title', info => {...}}, |
|
2659 |
{table => 'author', column => 'name' info => {...}} |
|
2660 |
] |
|
2661 | ||
- removed EXPERIMENTAL flag ...
|
2662 |
=head2 C<get_table_info> |
added test
|
2663 | |
improved pod
|
2664 |
my $table_infos = $dbi->get_table_info(exclude => qr/^system_/); |
update pod
|
2665 | |
added test
|
2666 |
get table infomation except for one which match C<exclude> pattern. |
2667 | ||
2668 |
[ |
|
2669 |
{table => 'book', info => {...}}, |
|
2670 |
{table => 'author', info => {...}} |
|
2671 |
] |
|
add experimental update_at()...
|
2672 | |
added test
|
2673 |
You can set this value to C<user_table_info>. |
update pod
|
2674 | |
removed EXPERIMETNAL flag fr...
|
2675 |
=head2 C<helper> |
2676 | ||
2677 |
$dbi->helper( |
|
2678 |
update_or_insert => sub { |
|
2679 |
my $self = shift; |
|
2680 |
|
|
2681 |
# Process |
|
2682 |
}, |
|
2683 |
find_or_create => sub { |
|
2684 |
my $self = shift; |
|
2685 |
|
|
2686 |
# Process |
|
2687 |
} |
|
2688 |
); |
|
2689 | ||
2690 |
Register helper. These helper is called directly from L<DBIx::Custom> object. |
|
2691 | ||
2692 |
$dbi->update_or_insert; |
|
2693 |
$dbi->find_or_create; |
|
2694 | ||
cleanup
|
2695 |
=head2 C<insert> |
2696 | ||
cleanup
|
2697 |
$dbi->insert({title => 'Perl', author => 'Ken'}, table => 'book'); |
update pod
|
2698 | |
updated pod
|
2699 |
Execute insert statement. First argument is row data. Return value is |
2700 |
affected row count. |
|
update pod
|
2701 | |
insert and update method's p...
|
2702 |
If you want to set constant value to row data, use scalar reference |
2703 |
as parameter value. |
|
2704 | ||
2705 |
{date => \"NOW()"} |
|
2706 | ||
cleanup
|
2707 |
B<options> |
2708 | ||
cleanup
|
2709 |
C<insert> method use all of C<execute> method's options, |
cleanup
|
2710 |
and use the following new ones. |
update pod
|
2711 | |
cleanup
|
2712 |
=over 4 |
- insert, insert_at, update,...
|
2713 | |
added EXPERIMENTAL execute()...
|
2714 |
=item C<id> |
2715 | ||
updated document
|
2716 |
id => 4 |
2717 |
id => [4, 5] |
|
update pod
|
2718 | |
updated document
|
2719 |
ID corresponding to C<primary_key>. |
2720 |
You can insert a row by C<id> and C<primary_key>. |
|
added EXPERIMENTAL execute()...
|
2721 | |
update pod
|
2722 |
$dbi->insert( |
updated document
|
2723 |
{title => 'Perl', author => 'Ken'} |
fixed pod
|
2724 |
primary_key => ['id1', 'id2'], |
added EXPERIMENTAL execute()...
|
2725 |
id => [4, 5], |
updated document
|
2726 |
table => 'book' |
update pod
|
2727 |
); |
added EXPERIMENTAL execute()...
|
2728 | |
updated document
|
2729 |
The above is same as the followin one. |
update pod
|
2730 | |
added EXPERIMENTAL execute()...
|
2731 |
$dbi->insert( |
updated document
|
2732 |
{id1 => 4, id2 => 5, title => 'Perl', author => 'Ken'}, |
2733 |
table => 'book' |
|
added EXPERIMENTAL execute()...
|
2734 |
); |
update pod
|
2735 | |
- removed EXPERIMENTAL statu...
|
2736 |
=item C<prefix> |
added EXPERIMENTAL insert, u...
|
2737 | |
2738 |
prefix => 'or replace' |
|
2739 | ||
2740 |
prefix before table name section |
|
2741 | ||
2742 |
insert or replace into book |
|
2743 | ||
updated document
|
2744 |
=item C<table> |
2745 | ||
2746 |
table => 'book' |
|
2747 | ||
2748 |
Table name. |
|
2749 | ||
sqlfilter option is renamed ...
|
2750 |
=item C<timestamp> |
- added EXPERIMENTAL timesta...
|
2751 | |
2752 |
timestamp => 1 |
|
2753 | ||
2754 |
If this value is set to 1, |
|
2755 |
automatically created timestamp column is set based on |
|
2756 |
C<timestamp> attribute's C<insert> value. |
|
2757 | ||
- removed EXPERIMENTAL flag ...
|
2758 |
=item C<wrap> |
updated pod
|
2759 | |
2760 |
wrap => {price => sub { "max($_[0])" }} |
|
2761 | ||
2762 |
placeholder wrapped string. |
|
2763 | ||
2764 |
If the following statement |
|
2765 | ||
2766 |
$dbi->insert({price => 100}, table => 'book', |
|
2767 |
{price => sub { "$_[0] + 5" }}); |
|
2768 | ||
2769 |
is executed, the following SQL is executed. |
|
2770 | ||
2771 |
insert into book price values ( ? + 5 ); |
|
2772 | ||
update pod
|
2773 |
=back |
2774 | ||
2775 |
=over 4 |
|
2776 | ||
- removed DEPRECATED DBIx::C...
|
2777 |
=head2 C<include_model> |
removed experimental base_ta...
|
2778 | |
update pod
|
2779 |
$dbi->include_model('MyModel'); |
removed experimental base_ta...
|
2780 | |
update pod
|
2781 |
Include models from specified namespace, |
2782 |
the following layout is needed to include models. |
|
removed experimental base_ta...
|
2783 | |
update pod
|
2784 |
lib / MyModel.pm |
2785 |
/ MyModel / book.pm |
|
2786 |
/ company.pm |
|
add feture. all model class ...
|
2787 | |
update pod
|
2788 |
Name space module, extending L<DBIx::Custom::Model>. |
add feture. all model class ...
|
2789 | |
update pod
|
2790 |
B<MyModel.pm> |
add feture. all model class ...
|
2791 | |
2792 |
package MyModel; |
|
updated pod
|
2793 |
use DBIx::Custom::Model -base; |
update pod
|
2794 |
|
2795 |
1; |
|
add feture. all model class ...
|
2796 | |
update pod
|
2797 |
Model modules, extending name space module. |
removed experimental base_ta...
|
2798 | |
update pod
|
2799 |
B<MyModel/book.pm> |
removed experimental base_ta...
|
2800 | |
update pod
|
2801 |
package MyModel::book; |
updated pod
|
2802 |
use MyModel -base; |
update pod
|
2803 |
|
2804 |
1; |
|
removed experimental base_ta...
|
2805 | |
update pod
|
2806 |
B<MyModel/company.pm> |
removed experimental base_ta...
|
2807 | |
update pod
|
2808 |
package MyModel::company; |
updated pod
|
2809 |
use MyModel -base; |
update pod
|
2810 |
|
2811 |
1; |
|
2812 |
|
|
updated pod
|
2813 |
MyModel::book and MyModel::company is included by C<include_model>. |
removed experimental base_ta...
|
2814 | |
updated pod
|
2815 |
You can get model object by C<model>. |
update pod
|
2816 | |
updated pod
|
2817 |
my $book_model = $dbi->model('book'); |
update pod
|
2818 |
my $company_model = $dbi->model('company'); |
removed experimental base_ta...
|
2819 | |
update pod
|
2820 |
See L<DBIx::Custom::Model> to know model features. |
2821 | ||
sqlfilter option is renamed ...
|
2822 |
=head2 C<insert_timestamp> |
- added EXPERIMENTAL update_...
|
2823 | |
moved DBIx::Custom::Guide to...
|
2824 |
$dbi->insert_timestamp( |
2825 |
[qw/created_at updated_at/] |
|
2826 |
=> sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") } |
|
2827 |
); |
|
- added EXPERIMENTAL update_...
|
2828 | |
removed EXPERIMETNAL flag fr...
|
2829 |
Timestamp value when C<insert> method is executed |
- added EXPERIMENTAL update_...
|
2830 |
with C<timestamp> option. |
2831 | ||
removed EXPERIMETNAL flag fr...
|
2832 |
If C<insert_timestamp> is set and C<insert> method is executed |
2833 |
with C<timestamp> option, column C<created_at> and C<update_at> |
|
2834 |
is automatically set to the value like "2010-10-11 10:12:54". |
|
2835 | ||
moved DBIx::Custom::Guide to...
|
2836 |
$dbi->insert($param, table => 'book', timestamp => 1); |
sqlfilter option is renamed ...
|
2837 | |
cleanup
|
2838 |
=head2 C<like_value> |
added EXPERIMENTAL like_valu...
|
2839 | |
2840 |
my $like_value = $dbi->like_value |
|
2841 | ||
cleanup
|
2842 |
Code reference which return a value for the like value. |
added EXPERIMENTAL like_valu...
|
2843 | |
2844 |
sub { "%$_[0]%" } |
|
2845 | ||
sqlfilter option is renamed ...
|
2846 |
=head2 C<mapper> |
- added EXPERIMENTAL pass at...
|
2847 | |
2848 |
my $mapper = $dbi->mapper(param => $param); |
|
2849 | ||
2850 |
Create a new L<DBIx::Custom::Mapper> object. |
|
2851 | ||
- removed DEPRECATED DBIx::C...
|
2852 |
=head2 C<merge_param> |
added EXPERIMENTAL updat_par...
|
2853 | |
2854 |
my $param = $dbi->merge_param({key1 => 1}, {key1 => 1, key2 => 2}); |
|
2855 | ||
cleanup
|
2856 |
Merge parameters. The following new parameter is created. |
added EXPERIMENTAL updat_par...
|
2857 | |
2858 |
{key1 => [1, 1], key2 => 2} |
|
2859 | ||
cleanup
|
2860 |
If same keys contains, the value is converted to array reference. |
2861 | ||
- removed DEPRECATED DBIx::C...
|
2862 |
=head2 C<model> |
update pod
|
2863 | |
2864 |
my $model = $dbi->model('book'); |
|
2865 | ||
cleanup
|
2866 |
Get a L<DBIx::Custom::Model> object |
2867 |
create by C<create_model> or C<include_model> |
|
update pod
|
2868 | |
- removed DEPRECATED DBIx::C...
|
2869 |
=head2 C<mycolumn> |
cleanup
|
2870 | |
fixed pod
|
2871 |
my $column = $dbi->mycolumn(book => ['author', 'title']); |
cleanup
|
2872 | |
2873 |
Create column clause for myself. The follwoing column clause is created. |
|
2874 | ||
2875 |
book.author as author, |
|
2876 |
book.title as title |
|
2877 | ||
added experimental not_exist...
|
2878 |
=head2 C<new> |
2879 | ||
update pod
|
2880 |
my $dbi = DBIx::Custom->new( |
data_source is DEPRECATED! I...
|
2881 |
dsn => "dbi:mysql:database=dbname", |
update pod
|
2882 |
user => 'ken', |
2883 |
password => '!LFKD%$&', |
|
- dbi_option attribute is re...
|
2884 |
option => {mysql_enable_utf8 => 1} |
update pod
|
2885 |
); |
added experimental not_exist...
|
2886 | |
2887 |
Create a new L<DBIx::Custom> object. |
|
2888 | ||
removed EXPERIMETNAL flag fr...
|
2889 |
=head2 C<not_exists> |
added experimental not_exist...
|
2890 | |
2891 |
my $not_exists = $dbi->not_exists; |
|
2892 | ||
update pod
|
2893 |
DBIx::Custom::NotExists object, indicating the column is not exists. |
cleanup
|
2894 |
This is used in C<param> of L<DBIx::Custom::Where> . |
experimental extended select...
|
2895 | |
- removed EXPERIMENTAL flag ...
|
2896 |
=head2 C<order> |
- added EXPERIMENTAL order m...
|
2897 | |
2898 |
my $order = $dbi->order; |
|
2899 | ||
2900 |
Create a new L<DBIx::Custom::Order> object. |
|
2901 | ||
cleanup
|
2902 |
=head2 C<register_filter> |
2903 | ||
update pod
|
2904 |
$dbi->register_filter( |
2905 |
# Time::Piece object to database DATE format |
|
2906 |
tp_to_date => sub { |
|
2907 |
my $tp = shift; |
|
2908 |
return $tp->strftime('%Y-%m-%d'); |
|
2909 |
}, |
|
2910 |
# database DATE format to Time::Piece object |
|
2911 |
date_to_tp => sub { |
|
2912 |
my $date = shift; |
|
2913 |
return Time::Piece->strptime($date, '%Y-%m-%d'); |
|
2914 |
} |
|
2915 |
); |
|
cleanup
|
2916 |
|
update pod
|
2917 |
Register filters, used by C<filter> option of many methods. |
cleanup
|
2918 | |
removed DBIx::Custom commit ...
|
2919 |
=head2 C<select> |
added select() all_column op...
|
2920 | |
select method column option ...
|
2921 |
my $result = $dbi->select( |
added select() all_column op...
|
2922 |
table => 'book', |
2923 |
column => ['author', 'title'], |
|
2924 |
where => {author => 'Ken'}, |
|
select method column option ...
|
2925 |
); |
added select() all_column op...
|
2926 |
|
updated document
|
2927 |
Execute select statement. |
added select() all_column op...
|
2928 | |
cleanup
|
2929 |
B<OPTIONS> |
added select() all_column op...
|
2930 | |
cleanup
|
2931 |
C<select> method use all of C<execute> method's options, |
2932 |
and use the following new ones. |
|
added EXPERIMENTAL execute m...
|
2933 | |
cleanup
|
2934 |
=over 4 |
added EXPERIMENTAL execute m...
|
2935 | |
added select() all_column op...
|
2936 |
=item C<column> |
2937 |
|
|
updated document
|
2938 |
column => 'author' |
2939 |
column => ['author', 'title'] |
|
2940 | ||
2941 |
Column clause. |
|
updated pod
|
2942 |
|
updated document
|
2943 |
if C<column> is not specified, '*' is set. |
added select() all_column op...
|
2944 | |
updated document
|
2945 |
column => '*' |
added select() all_column op...
|
2946 | |
- removed EXPERIMENTAL statu...
|
2947 |
You can specify hash of array reference. |
updated pod
|
2948 | |
updated document
|
2949 |
column => [ |
updated pod
|
2950 |
{book => [qw/author title/]}, |
2951 |
{person => [qw/name age/]} |
|
updated document
|
2952 |
] |
updated pod
|
2953 | |
updated pod
|
2954 |
This is expanded to the following one by using C<colomn> method. |
- select() column option can...
|
2955 | |
2956 |
book.author as "book.author", |
|
2957 |
book.title as "book.title", |
|
2958 |
person.name as "person.name", |
|
2959 |
person.age as "person.age" |
|
2960 | ||
- select method column optio...
|
2961 |
You can specify array of array reference, first argument is |
2962 |
column name, second argument is alias. |
|
- select() column option can...
|
2963 | |
updated document
|
2964 |
column => [ |
- select method column optio...
|
2965 |
['date(book.register_datetime)' => 'book.register_date'] |
updated document
|
2966 |
]; |
- select() column option can...
|
2967 | |
- select method column optio...
|
2968 |
Alias is quoted properly and joined. |
- select() column option can...
|
2969 | |
2970 |
date(book.register_datetime) as "book.register_date" |
|
updated pod
|
2971 | |
updated document
|
2972 |
=item C<filter> |
added select() all_column op...
|
2973 | |
updated document
|
2974 |
Same as C<execute> method's C<filter> option. |
2975 | ||
2976 |
=item C<id> |
|
2977 | ||
2978 |
id => 4 |
|
2979 |
id => [4, 5] |
|
2980 | ||
2981 |
ID corresponding to C<primary_key>. |
|
2982 |
You can select rows by C<id> and C<primary_key>. |
|
2983 | ||
2984 |
$dbi->select( |
|
fixed pod
|
2985 |
primary_key => ['id1', 'id2'], |
updated document
|
2986 |
id => [4, 5], |
2987 |
table => 'book' |
|
added select() all_column op...
|
2988 |
); |
2989 | ||
updated document
|
2990 |
The above is same as the followin one. |
2991 | ||
updated pod
|
2992 |
$dbi->select( |
updated document
|
2993 |
where => {id1 => 4, id2 => 5}, |
2994 |
table => 'book' |
|
where can recieve array refr...
|
2995 |
); |
2996 |
|
|
cleanup
|
2997 |
=item C<param> |
added select() all_column op...
|
2998 | |
updated document
|
2999 |
param => {'table2.key3' => 5} |
update pod
|
3000 | |
updated document
|
3001 |
Parameter shown before where clause. |
3002 |
|
|
3003 |
For example, if you want to contain tag in join clause, |
|
3004 |
you can pass parameter by C<param> option. |
|
update pod
|
3005 | |
updated document
|
3006 |
join => ['inner join (select * from table2 where table2.key3 = :table2.key3)' . |
3007 |
' as table2 on table1.key1 = table2.key1'] |
|
3008 | ||
- removed EXPERIMENTAL statu...
|
3009 |
=itme C<prefix> |
added EXPERIMENTAL select pr...
|
3010 | |
3011 |
prefix => 'SQL_CALC_FOUND_ROWS' |
|
3012 | ||
3013 |
Prefix of column cluase |
|
3014 | ||
3015 |
select SQL_CALC_FOUND_ROWS title, author from book; |
|
3016 | ||
updated document
|
3017 |
=item C<join> |
3018 | ||
3019 |
join => [ |
|
3020 |
'left outer join company on book.company_id = company_id', |
|
3021 |
'left outer join location on company.location_id = location.id' |
|
3022 |
] |
|
3023 |
|
|
3024 |
Join clause. If column cluase or where clause contain table name like "company.name", |
|
3025 |
join clausees needed when SQL is created is used automatically. |
|
update pod
|
3026 | |
3027 |
$dbi->select( |
|
3028 |
table => 'book', |
|
cleanup
|
3029 |
column => ['company.location_id as location_id'], |
update pod
|
3030 |
where => {'company.name' => 'Orange'}, |
3031 |
join => [ |
|
3032 |
'left outer join company on book.company_id = company.id', |
|
3033 |
'left outer join location on company.location_id = location.id' |
|
3034 |
] |
|
3035 |
); |
|
3036 | ||
updated document
|
3037 |
In above select, column and where clause contain "company" table, |
3038 |
the following SQL is created |
|
update pod
|
3039 | |
cleanup
|
3040 |
select company.location_id as location_id |
update pod
|
3041 |
from book |
3042 |
left outer join company on book.company_id = company.id |
|
cleanup
|
3043 |
where company.name = ?; |
update pod
|
3044 | |
added join new syntax
|
3045 |
You can specify two table by yourself. This is useful when join parser can't parse |
- removed EXPERIMENTAL flag ...
|
3046 |
the join clause correctly. |
added join new syntax
|
3047 | |
3048 |
$dbi->select( |
|
3049 |
table => 'book', |
|
3050 |
column => ['company.location_id as location_id'], |
|
3051 |
where => {'company.name' => 'Orange'}, |
|
3052 |
join => [ |
|
3053 |
{ |
|
3054 |
clause => 'left outer join location on company.location_id = location.id', |
|
3055 |
table => ['company', 'location'] |
|
3056 |
} |
|
3057 |
] |
|
3058 |
); |
|
3059 | ||
updated document
|
3060 |
=item C<table> |
updated pod
|
3061 | |
updated document
|
3062 |
table => 'book' |
updated pod
|
3063 | |
updated document
|
3064 |
Table name. |
updated pod
|
3065 | |
updated document
|
3066 |
=item C<where> |
3067 |
|
|
3068 |
# Hash refrence |
|
3069 |
where => {author => 'Ken', 'title' => 'Perl'} |
|
3070 |
|
|
3071 |
# DBIx::Custom::Where object |
|
3072 |
where => $dbi->where( |
|
3073 |
clause => ['and', 'author = :author', 'title like :title'], |
|
3074 |
param => {author => 'Ken', title => '%Perl%'} |
|
3075 |
); |
|
updated pod
|
3076 |
|
3077 |
# Array reference 1 (array reference, hash referenc). same as above |
|
3078 |
where => [ |
|
3079 |
['and', 'author = :author', 'title like :title'], |
|
3080 |
{author => 'Ken', title => '%Perl%'} |
|
3081 |
]; |
|
3082 |
|
|
3083 |
# Array reference 2 (String, hash reference) |
|
3084 |
where => [ |
|
3085 |
'title like :title', |
|
3086 |
{title => '%Perl%'} |
|
3087 |
] |
|
3088 |
|
|
3089 |
# String |
|
3090 |
where => 'title is null' |
|
update pod
|
3091 | |
cleanup
|
3092 |
Where clause. See L<DBIx::Custom::Where>. |
updated document
|
3093 |
|
update pod
|
3094 |
=back |
cleanup
|
3095 | |
removed EXPERIMETNAL flag fr...
|
3096 |
=head2 C<setup_model> |
3097 | ||
3098 |
$dbi->setup_model; |
|
3099 | ||
3100 |
Setup all model objects. |
|
3101 |
C<columns> of model object is automatically set, parsing database information. |
|
3102 | ||
3103 |
=head2 C<type_rule> |
|
3104 | ||
3105 |
$dbi->type_rule( |
|
3106 |
into1 => { |
|
3107 |
date => sub { ... }, |
|
3108 |
datetime => sub { ... } |
|
3109 |
}, |
|
3110 |
into2 => { |
|
3111 |
date => sub { ... }, |
|
3112 |
datetime => sub { ... } |
|
3113 |
}, |
|
3114 |
from1 => { |
|
3115 |
# DATE |
|
3116 |
9 => sub { ... }, |
|
3117 |
# DATETIME or TIMESTAMP |
|
3118 |
11 => sub { ... }, |
|
3119 |
} |
|
3120 |
from2 => { |
|
3121 |
# DATE |
|
3122 |
9 => sub { ... }, |
|
3123 |
# DATETIME or TIMESTAMP |
|
3124 |
11 => sub { ... }, |
|
3125 |
} |
|
3126 |
); |
|
3127 | ||
3128 |
Filtering rule when data is send into and get from database. |
|
3129 |
This has a little complex problem. |
|
3130 | ||
3131 |
In C<into1> and C<into2> you can specify |
|
3132 |
type name as same as type name defined |
|
3133 |
by create table, such as C<DATETIME> or C<DATE>. |
|
3134 | ||
3135 |
Note that type name and data type don't contain upper case. |
|
3136 |
If these contain upper case charactor, you convert it to lower case. |
|
3137 | ||
3138 |
C<into2> is executed after C<into1>. |
|
3139 | ||
3140 |
Type rule of C<into1> and C<into2> is enabled on the following |
|
3141 |
column name. |
|
3142 | ||
3143 |
=over 4 |
|
3144 | ||
3145 |
=item 1. column name |
|
3146 | ||
3147 |
issue_date |
|
3148 |
issue_datetime |
|
3149 | ||
3150 |
This need C<table> option in each method. |
|
3151 | ||
3152 |
=item 2. table name and column name, separator is dot |
|
3153 | ||
3154 |
book.issue_date |
|
3155 |
book.issue_datetime |
|
3156 | ||
3157 |
=back |
|
3158 | ||
3159 |
You get all type name used in database by C<available_typename>. |
|
3160 | ||
3161 |
print $dbi->available_typename; |
|
3162 | ||
3163 |
In C<from1> and C<from2> you specify data type, not type name. |
|
3164 |
C<from2> is executed after C<from1>. |
|
3165 |
You get all data type by C<available_datatype>. |
|
3166 | ||
3167 |
print $dbi->available_datatype; |
|
3168 | ||
3169 |
You can also specify multiple types at once. |
|
3170 | ||
3171 |
$dbi->type_rule( |
|
3172 |
into1 => [ |
|
3173 |
[qw/DATE DATETIME/] => sub { ... }, |
|
3174 |
], |
|
3175 |
); |
|
3176 | ||
cleanup
|
3177 |
=head2 C<update> |
removed reconnect method
|
3178 | |
updated document
|
3179 |
$dbi->update({title => 'Perl'}, table => 'book', where => {id => 4}); |
removed reconnect method
|
3180 | |
insert and update method's p...
|
3181 |
Execute update statement. First argument is update row data. |
3182 | ||
3183 |
If you want to set constant value to row data, use scalar reference |
|
3184 |
as parameter value. |
|
3185 | ||
3186 |
{date => \"NOW()"} |
|
added experimental update_pa...
|
3187 | |
cleanup
|
3188 |
B<OPTIONS> |
- insert, insert_at, update,...
|
3189 | |
cleanup
|
3190 |
C<update> method use all of C<execute> method's options, |
3191 |
and use the following new ones. |
|
- insert, insert_at, update,...
|
3192 | |
cleanup
|
3193 |
=over 4 |
- insert, insert_at, update,...
|
3194 | |
updated document
|
3195 |
=item C<id> |
- insert, insert_at, update,...
|
3196 | |
updated document
|
3197 |
id => 4 |
3198 |
id => [4, 5] |
|
- insert, insert_at, update,...
|
3199 | |
updated document
|
3200 |
ID corresponding to C<primary_key>. |
3201 |
You can update rows by C<id> and C<primary_key>. |
|
update pod
|
3202 | |
DEPRECATED select() param op...
|
3203 |
$dbi->update( |
updated document
|
3204 |
{title => 'Perl', author => 'Ken'} |
fixed pod
|
3205 |
primary_key => ['id1', 'id2'], |
updated document
|
3206 |
id => [4, 5], |
3207 |
table => 'book' |
|
where can recieve array refr...
|
3208 |
); |
update pod
|
3209 | |
updated document
|
3210 |
The above is same as the followin one. |
update pod
|
3211 | |
updated document
|
3212 |
$dbi->update( |
3213 |
{title => 'Perl', author => 'Ken'} |
|
3214 |
where => {id1 => 4, id2 => 5}, |
|
3215 |
table => 'book' |
|
3216 |
); |
|
update pod
|
3217 | |
- removed EXPERIMENTAL statu...
|
3218 |
=item C<prefix> |
added EXPERIMENTAL insert, u...
|
3219 | |
3220 |
prefix => 'or replace' |
|
3221 | ||
3222 |
prefix before table name section |
|
3223 | ||
3224 |
update or replace book |
|
3225 | ||
updated document
|
3226 |
=item C<table> |
update pod
|
3227 | |
updated document
|
3228 |
table => 'book' |
update pod
|
3229 | |
updated document
|
3230 |
Table name. |
update pod
|
3231 | |
sqlfilter option is renamed ...
|
3232 |
=item C<timestamp> |
- added EXPERIMENTAL timesta...
|
3233 | |
3234 |
timestamp => 1 |
|
3235 | ||
3236 |
If this value is set to 1, |
|
3237 |
automatically updated timestamp column is set based on |
|
3238 |
C<timestamp> attribute's C<update> value. |
|
3239 | ||
added EXPERIMENTAL execute m...
|
3240 |
=item C<where> |
3241 | ||
3242 |
Same as C<select> method's C<where> option. |
|
3243 | ||
- removed EXPERIMENTAL flag ...
|
3244 |
=item C<wrap> |
updated pod
|
3245 | |
3246 |
wrap => {price => sub { "max($_[0])" }} |
|
3247 | ||
3248 |
placeholder wrapped string. |
|
3249 | ||
3250 |
If the following statement |
|
3251 | ||
3252 |
$dbi->update({price => 100}, table => 'book', |
|
3253 |
{price => sub { "$_[0] + 5" }}); |
|
3254 | ||
3255 |
is executed, the following SQL is executed. |
|
3256 | ||
3257 |
update book set price = ? + 5; |
|
3258 | ||
updated pod
|
3259 |
=back |
update pod
|
3260 | |
updated pod
|
3261 |
=head2 C<update_all> |
update pod
|
3262 | |
updated pod
|
3263 |
$dbi->update_all({title => 'Perl'}, table => 'book', ); |
update pod
|
3264 | |
updated document
|
3265 |
Execute update statement for all rows. |
updated pod
|
3266 |
Options is same as C<update> method. |
update pod
|
3267 | |
- removed DEPRECATED status ...
|
3268 |
=head2 C<update_or_insert EXPERIMENTAL> |
3269 |
|
|
3270 |
# Where |
|
3271 |
$dbi->update_or_insert( |
|
3272 |
{id => 1, title => 'Perl'}, |
|
3273 |
table => 'book', |
|
3274 |
where => {id => 1}, |
|
3275 |
select_option => {append => 'for update'} |
|
3276 |
); |
|
3277 |
|
|
3278 |
# ID |
|
3279 |
$dbi->update_or_insert( |
|
3280 |
{title => 'Perl'}, |
|
3281 |
table => 'book', |
|
3282 |
id => 1, |
|
3283 |
primary_key => 'id', |
|
3284 |
select_option => {append => 'for update'} |
|
3285 |
); |
|
3286 |
|
|
3287 |
Update or insert. |
|
3288 | ||
3289 |
In both examples, the following SQL is executed. |
|
3290 | ||
3291 |
# In case insert |
|
3292 |
insert into book (id, title) values (?, ?) |
|
3293 |
|
|
3294 |
# In case update |
|
3295 |
update book set (id = ?, title = ?) where book.id = ? |
|
3296 | ||
3297 |
The following opitons are available adding to C<update> option. |
|
3298 | ||
3299 |
=over 4 |
|
3300 | ||
3301 |
=item C<select_option> |
|
3302 | ||
3303 |
select_option => {append => 'for update'} |
|
3304 | ||
3305 |
select method option, |
|
3306 |
select method is used to check the row is already exists. |
|
3307 | ||
sqlfilter option is renamed ...
|
3308 |
=head2 C<update_timestamp> |
- added EXPERIMENTAL update_...
|
3309 | |
removed EXPERIMETNAL flag fr...
|
3310 |
$dbi->update_timestamp( |
3311 |
updated_at |
|
3312 |
=> sub { Time::Piece->localtime->strftime("%Y-%m-%d %H:%M:%S") } |
|
cleanup
|
3313 |
); |
fix tests
|
3314 | |
removed EXPERIMETNAL flag fr...
|
3315 |
Timestamp value when C<update> method is executed |
3316 |
with C<timestamp> option. |
|
cleanup
|
3317 | |
removed EXPERIMETNAL flag fr...
|
3318 |
If C<insert_timestamp> is set and C<insert> method is executed |
3319 |
with C<timestamp> option, column C<update_at> |
|
3320 |
is automatically set to the value like "2010-10-11 10:12:54". |
|
cleanup
|
3321 | |
removed EXPERIMETNAL flag fr...
|
3322 |
>|perl| |
3323 |
$dbi->update($param, table => 'book', timestamp => 1); |
|
3324 |
||< |
|
cleanup
|
3325 | |
- removed EXPERIMENTAL flag ...
|
3326 |
=head2 C<show_datatype> |
update pod
|
3327 | |
3328 |
$dbi->show_datatype($table); |
|
3329 | ||
3330 |
Show data type of the columns of specified table. |
|
3331 | ||
3332 |
book |
|
3333 |
title: 5 |
|
3334 |
issue_date: 91 |
|
3335 | ||
3336 |
This data type is used in C<type_rule>'s C<from1> and C<from2>. |
|
3337 | ||
- removed EXPERIMENTAL the f...
|
3338 |
=head2 C<show_tables> |
test cleanup
|
3339 | |
3340 |
$dbi->show_tables; |
|
3341 | ||
3342 |
Show tables. |
|
3343 | ||
- removed EXPERIMENTAL flag ...
|
3344 |
=head2 C<show_typename> |
update pod
|
3345 | |
3346 |
$dbi->show_typename($table); |
|
3347 | ||
3348 |
Show type name of the columns of specified table. |
|
3349 | ||
3350 |
book |
|
3351 |
title: varchar |
|
3352 |
issue_date: date |
|
3353 | ||
3354 |
This type name is used in C<type_rule>'s C<into1> and C<into2>. |
|
3355 | ||
removed EXPERIMETNAL flag fr...
|
3356 |
=head2 C<values_clause> |
3357 | ||
3358 |
my $values_clause = $dbi->values_clause({title => 'a', age => 2}); |
|
3359 | ||
3360 |
Create values clause. |
|
3361 | ||
3362 |
(title, author) values (title = :title, age = :age); |
|
3363 | ||
3364 |
You can use this in insert statement. |
|
3365 | ||
3366 |
my $insert_sql = "insert into book $values_clause"; |
|
3367 | ||
3368 |
=head2 C<where> |
|
3369 | ||
3370 |
my $where = $dbi->where( |
|
3371 |
clause => ['and', 'title = :title', 'author = :author'], |
|
3372 |
param => {title => 'Perl', author => 'Ken'} |
|
3373 |
); |
|
3374 | ||
3375 |
Create a new L<DBIx::Custom::Where> object. |
|
3376 | ||
- added EXPERIMENTAL update_...
|
3377 |
=head1 ENVIRONMENTAL VARIABLES |
3378 | ||
3379 |
=head2 C<DBIX_CUSTOM_DEBUG> |
|
3380 | ||
3381 |
If environment variable C<DBIX_CUSTOM_DEBUG> is set to true, |
|
3382 |
executed SQL and bind values are printed to STDERR. |
|
3383 | ||
improved debug message
|
3384 |
=head2 C<DBIX_CUSTOM_DEBUG_ENCODING> |
3385 | ||
3386 |
DEBUG output encoding. Default to UTF-8. |
|
added environment variable D...
|
3387 | |
fix heading typos
|
3388 |
=head1 DEPRECATED FUNCTIONALITY |
- added EXPERIMENTAL order m...
|
3389 | |
3390 |
L<DBIx::Custom> |
|
3391 | ||
3392 |
# Attribute methods |
|
- dbi_option attribute is re...
|
3393 |
default_dbi_option # will be removed 2017/1/1 |
3394 |
dbi_option # will be removed 2017/1/1 |
|
added EXPERIMENTAL each_tabl...
|
3395 |
data_source # will be removed at 2017/1/1 |
3396 |
dbi_options # will be removed at 2017/1/1 |
|
3397 |
filter_check # will be removed at 2017/1/1 |
|
3398 |
reserved_word_quote # will be removed at 2017/1/1 |
|
3399 |
cache_method # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3400 |
|
3401 |
# Methods |
|
- method method of DBIx::Cus...
|
3402 |
method # will be removed at 2017/1/1 |
- update_param is DEPRECATED...
|
3403 |
assign_param # will be removed at 2017/1/1 |
3404 |
update_param # will be removed at 2017/1/1 |
|
3405 |
insert_param # will be removed at 2017/1/1 |
|
added EXPERIMENTAL each_tabl...
|
3406 |
create_query # will be removed at 2017/1/1 |
3407 |
apply_filter # will be removed at 2017/1/1 |
|
3408 |
select_at # will be removed at 2017/1/1 |
|
3409 |
delete_at # will be removed at 2017/1/1 |
|
3410 |
update_at # will be removed at 2017/1/1 |
|
3411 |
insert_at # will be removed at 2017/1/1 |
|
3412 |
register_tag # will be removed at 2017/1/1 |
|
3413 |
default_bind_filter # will be removed at 2017/1/1 |
|
3414 |
default_fetch_filter # will be removed at 2017/1/1 |
|
3415 |
insert_param_tag # will be removed at 2017/1/1 |
|
update pod
|
3416 |
register_tag # will be removed at 2017/1/1 |
added EXPERIMENTAL each_tabl...
|
3417 |
register_tag_processor # will be removed at 2017/1/1 |
3418 |
update_param_tag # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3419 |
|
3420 |
# Options |
|
cleanup
|
3421 |
select method where_param option # will be removed 2017/1/1 |
cleanup
|
3422 |
delete method where_param option # will be removed 2017/1/1 |
cleanup
|
3423 |
update method where_param option # will be removed 2017/1/1 |
cleanup
|
3424 |
insert method param option # will be removed at 2017/1/1 |
insert method's id option is...
|
3425 |
insert method id option # will be removed at 2017/1/1 |
added EXPERIMENTAL each_tabl...
|
3426 |
select method relation option # will be removed at 2017/1/1 |
3427 |
select method column option [COLUMN, as => ALIAS] format |
|
3428 |
# will be removed at 2017/1/1 |
|
sqlfilter option is renamed ...
|
3429 |
execute method's sqlfilter option # will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3430 |
|
3431 |
# Others |
|
cleanup
|
3432 |
execute("select * from {= title}"); # execute method's |
3433 |
# tag parsing functionality |
|
added EXPERIMENTAL each_tabl...
|
3434 |
# will be removed at 2017/1/1 |
3435 |
Query caching # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3436 | |
3437 |
L<DBIx::Custom::Model> |
|
3438 | ||
DBIx::Custom::Query filters ...
|
3439 |
# Attribute methods |
- method method of DBIx::Cus...
|
3440 |
method # will be removed at 2017/1/1 |
added EXPERIMENTAL each_tabl...
|
3441 |
filter # will be removed at 2017/1/1 |
3442 |
name # will be removed at 2017/1/1 |
|
3443 |
type # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3444 | |
3445 |
L<DBIx::Custom::Query> |
|
3446 |
|
|
DBIx::Custom::Query filters ...
|
3447 |
# Attribute methods |
added EXPERIMENTAL each_tabl...
|
3448 |
default_filter # will be removed at 2017/1/1 |
DBIx::Custom::Query filters ...
|
3449 |
table # will be removed at 2017/1/1 |
3450 |
filters # will be removed at 2017/1/1 |
|
3451 |
|
|
3452 |
# Methods |
|
3453 |
filter # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3454 | |
3455 |
L<DBIx::Custom::QueryBuilder> |
|
3456 |
|
|
DBIx::Custom::Query filters ...
|
3457 |
# Attribute methods |
added EXPERIMENTAL each_tabl...
|
3458 |
tags # will be removed at 2017/1/1 |
3459 |
tag_processors # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3460 |
|
DBIx::Custom::Query filters ...
|
3461 |
# Methods |
added EXPERIMENTAL each_tabl...
|
3462 |
register_tag # will be removed at 2017/1/1 |
3463 |
register_tag_processor # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3464 |
|
3465 |
# Others |
|
3466 |
build_query("select * from {= title}"); # tag parsing functionality |
|
added EXPERIMENTAL each_tabl...
|
3467 |
# will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3468 | |
3469 |
L<DBIx::Custom::Result> |
|
3470 |
|
|
DBIx::Custom::Query filters ...
|
3471 |
# Attribute methods |
added EXPERIMENTAL each_tabl...
|
3472 |
filter_check # will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3473 |
|
3474 |
# Methods |
|
added EXPERIMENTAL each_tabl...
|
3475 |
end_filter # will be removed at 2017/1/1 |
3476 |
remove_end_filter # will be removed at 2017/1/1 |
|
3477 |
remove_filter # will be removed at 2017/1/1 |
|
3478 |
default_filter # will be removed at 2017/1/1 |
|
- added EXPERIMENTAL order m...
|
3479 | |
3480 |
L<DBIx::Custom::Tag> |
|
3481 | ||
added EXPERIMENTAL each_tabl...
|
3482 |
This module is DEPRECATED! # will be removed at 2017/1/1 |
- added EXPERIMENTAL order m...
|
3483 | |
fix heading typos
|
3484 |
=head1 BACKWARDS COMPATIBILITY POLICY |
- added EXPERIMENTAL order m...
|
3485 | |
3486 |
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings |
|
3487 |
except for attribute method. |
|
3488 |
You can check all DEPRECATED functionalities by document. |
|
3489 |
DEPRECATED functionality is removed after five years, |
|
3490 |
but if at least one person use the functionality and tell me that thing |
|
added EXPERIMENTAL each_tabl...
|
3491 |
I extend one year each time he tell me it. |
- added EXPERIMENTAL order m...
|
3492 | |
3493 |
EXPERIMENTAL functionality will be changed without warnings. |
|
DBIx::Custom is now stable
|
3494 | |
removed DESTROY method(not b...
|
3495 |
=head1 BUGS |
3496 | ||
renamed build_query to creat...
|
3497 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
3498 | |
3499 |
C<< <kimoto.yuki at gmail.com> >> |
|
3500 | ||
3501 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
3502 | ||
removed reconnect method
|
3503 |
=head1 AUTHOR |
3504 | ||
3505 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
3506 | |
packaging one directory
|
3507 |
=head1 COPYRIGHT & LICENSE |
3508 | ||
cleanup
|
3509 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
3510 | |
3511 |
This program is free software; you can redistribute it and/or modify it |
|
3512 |
under the same terms as Perl itself. |
|
3513 | ||
3514 |
=cut |