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