Egg-Release-DBI
view release on metacpan or search on metacpan
lib/Egg/Mod/EasyDBI.pm view on Meta::CPAN
=item * Alias = up
=back
=head2 update_insert ([STATEMENT], [HASH])
The record is added if the update is tested and it fails.
When succeeding in the update, 0E0 is restored. Undefined returns when failing
in the addition.
The way to give STATEMENT and HASH is the same as update.
However, the data used to add and subtract the numerical value is excluded from
an additional object.
* A still clear specification is not decided about how to treat this numerical value.
# UPDATE $table SET user = 'zoo', age = age + 1 WHERE user = 'hoge'
# INSERT INTO $table (user) VALUES ('zoo')
$table->update_insert(\'user = ?', { user=> [qw/ hoge zoo /], age=> \1 });
or
$table->update_insert( user=> [qw/ hoge zoo /], age=> \1 );
# UPDATE $table SET user = 'zoo', age = 20 WHERE id = 1
# INSERT INTO $table (user, age) VALUES ('zoo', 20)
$table->update_insert(\'id => ?', { id=> [1], user=> 'zoo', age=> 20 });
or
$table->update_insert( id=> [1], user=> 'zoo', age=> 20 );
=head2 find_insert ([COLUMN], [HASH])
If the record doesn't exist, the record is added.
If the record already exists, 0E0 is restored.
Undefined returns when failing in the addition.
COLUMN specifies only one column used for the retrieval.
When the value of this column cannot be received from HASH, it becomes an error.
When COLUMN is omitted, HASH is made the first argument, and it passes it as
usual HASH. The first key to HASH is handled by this as a column for the retrieval.
Please omit the second element specifying the value for the retrieval of HASH by
the ARRAY reference when there is a column that doesn't want to be included when
adding it.
# SELECT user FROM $table WHERE user = 'banban'
# INSERT INTO $table (user, age) VALUES ('baban', 20)
$table->find_insert(\'user', { user=> 'banban', age=> 20 });
or
$table->find_insert( user=> 'banban', age=> 20 );
# SELECT id FROM $table WHERE id = 1
# INSERT INTO $table (user, age) VALUES ('banban', 20)
$table->find_insert(\'id', { id=> [1], user=> 'banban', age=> 20 });
or
$table->find_insert( id=> [1], user=> 'banban', age=> 20 );
=head2 for_update ([PRIMARY_KEY], [VALUE])
The record by FOR UPDATE is locked.
0 returns when failing.
# SELECT * FROM $table WHERE id = ? FOR UPDATE
$table->for_update( id=> 1 );
=head2 delete ([STATEMENT], [EXECUTE_ARGS])
The record is deleted.
# DELETE FROM $table WHERE id = ?
$table->delete('id = ?', $id);
=head2 upgrade ([HASH])
UPDATE is done to all the records.
If upgrade_ok is not effective, this method returns the exception.
# UPDATE $table SET age = 20
$table->upgrade( age => 20 );
=head2 clear
All the records are deleted.
If clear_ok is not effective, this method returns the exception.
# DELETE FROM $table
$table->clear;
* I think that it is more efficient to do TRUNCATE by the do method.
=head2 abs_hashref ([FIELDS], [WHERE], [ORDER])
After SQL Statement is received from L<SQL::Abstract>, hashref is done.
Please set 'sql_abstract' to enable this method use.
All the arguments extend to L<SQL::Abstract>. There is no table name needing.
Please see at the document of L<SQL::Abstract> of how to give the argument in
detail.
# SELECT * FROM $table WHERE id = 1 AND user = 'hooo'
my $hash= $table->abs_hashref({ id=> 1, user=> 'hooo' });
=head2 abs_arrayref ([FIELDS], [WHERE], [ORDER], [CODE_REF])
After SQL Statement is received from L<SQL::Abstract>, arrayref is done.
As for the argument, it is the same as abs_hashref accepting CODE_REF.
The treatment of CODE_REF is the same as arrayref.
Because it is picked up as CODE_REF if the last element of the argument is CODE
reference, the argument without the necessity need not be buried with undef etc.
# SELECT * FROM $table WHERE age > 18
my $list= $table->abs_arrayref({ age => { '>', 18 } });
( run in 0.712 second using v1.01-cache-2.11-cpan-364913b4093 )