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