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