- DBIx::Custom
- here
Delete row with delete method
Use the delete method to delete a table row.
$dbi->delete( table =>'book', where => {id => 1}, );
Specify the target table with table . Specify the condition of the row to be deleted with where . Where can be a hash reference or a DBIx::Custom::Where object.
The following SQL is issued:
delete from book where id =?;
The corresponding value is embedded in the placeholder.
Delete method options
The delete method can use all the options of " execute method". It also implements the following options.
Specifying conditions by ID id
You can specify the condition by ID by using the id option. The primary_key must be set.
id => 4 id => [4, 5]
Suppose you want to execute a delete like the one below.
$dbi->delete( primary_key => ['id1','id2'], id => [4, 5], table =>'book', );
This is the same as delete below.
$dbi->delete(where => {id1 => 4, id2 => 5}, table =>'book');
prefix prefix
Use the prefix option to set a string between delete and from table.
prefix =>'some'
For example, the following SQL is executed.
delete some from book
table name table
Specify the table name with the table option.
table =>'book'
Where clause where
Use the where option to write a Where clause.
where => {author =>'Ken','title' =>'Perl'} where => [ ['and',': author {=}',': title {like}'], {author =>'Ken', title =>'%Perl%'} ]
See "where option" in " select method" for how to specify the where option. See Dynamic Where Clause Generation for more information on Where clause generation.
Delete all lines delete_all
Use the delete_all method to delete all the rows in the table. The delete method cannot delete all rows for safety reasons, so use the delete_all method.
$dbi->delete_all(table =>'book');
Specify the target table with table .
The following SQL is issued:
delete from book;