DB::Object::SQLite::Query - SQLite Query Object
my $q = DB::Object::SQLite::Query->new;
v0.3.8
This is a SQLite specific query object.
Sets or gets the array object (Module::Generic::Array) for the binded value in HAVING clauses.
HAVING
This takes the parameters bind and value and returns a formatted DATETIME(?, 'unixepoch', 'localtime') expression.
DATETIME(?, 'unixepoch', 'localtime')
This takes the parameters bind, value and quote and returns a formatted expression STRFTIME('%s',?) to returns the epoch value out of the given field.
STRFTIME('%s',?)
Calls "_where_having" in DB::Object::Query to build a having clause.
having
See SQLite documentation for more information
Build a new DB::Object::Query::Clause clause object by calling "_process_limit" and return it.
Provided with some options and this will build a ON CONFLICT clause (DB::Object::Query::Clause). This is only available for SQLite version 3.35.0 released on 2021-03-12 or above.
ON CONFLICT
Valid value can be nothing and in which case, nothing will be done by the database upon conflict.
nothing
INSERT INTO distributors (did, dname) VALUES (7, 'Redline GmbH') ON CONFLICT (did) DO NOTHING;
or
INSERT INTO distributors (did, dname) VALUES (9, 'Antwerp Design') ON CONFLICT ON CONSTRAINT distributors_pkey DO NOTHING;
Value can also be ignore instructing the database to simply ignore conflict.
ignore
If the value is update, then this will set a callback routine to format an update statement using "format_update" in DB::Object::Query
update
If the original insert or update uses placeholders, then the DO UPDATE will also use the same placeholders and the DB::Object::Statement object will act accordingly when being provided the binded values. That is, it will double them to allocate those binded value also for the DO UPDATE part of the query.
insert
DO UPDATE
The callback will be called by "insert" in DB::Object::Query or "update" in DB::Object::Query, because the "on_conflict" relies on query columns being previously set.
An array (or array object) of fields to use with action set to update
$q->on_conflict({ target => 'name', action => 'update, fields => [qw( first_name last_name )], });
This will turn the DO UPDATE prepending each field with the special keyword EXCLUDED
EXCLUDED
INSERT INTO distributors (did, dname) VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc') ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;
Target can be a table column.
$q->on_conflict({ target => 'name', action => 'ignore', });
or it can also be a constraint name:
$q->on_conflict({ target => 'on constraint my_table_idx_name', action => 'ignore', });
Value for target can also be a scalar reference and it will be used as-is
$q->on_conflict({ target => \'on constraint my_table_idx_name', action => 'ignore', });
Value for target can also be an array or array object (like Module::Generic::Array) and the array will be joined using a comma.
If no target argument was provided, then action must be set to nothing or this will return an error.
You can also provide a WHERE expression in the conflict and it will be added literally.
WHERE
$q->on_conflict({ target => 'did', action => 'ignore', where => 'is_active', }); INSERT INTO distributors (did, dname) VALUES (10, 'Conrad International') ON CONFLICT (did) WHERE is_active DO NOTHING;
See SQLite documentation for more information.
If the object property query_reset is not already set, this will remove the following properties from the current query object, set "enhance" in DB::Object::Query to true and return the query object.
query_reset
Properties removed are: alias local binded binded_values binded_where binded_limit binded_group binded_having binded_order where limit group_by order_by reverse from_unixtime unix_timestamp sorted
Reset all the following object properties to an anonymous array: binded binded_where binded_group binded_having binded_order binded_limit
This feature is available with SQLite version 3.35.0 or above, otherwise an error is returned.
It expects a string that is used to build the RETURNING clause.
RETURNING
# will instruct the database to return all the table columns $q->returning( '*' );
$q->returning( 'id' );
But don't pass a reference:
$q->returning( [qw( id name age )] );
It returns a new DB::Object::SQLite::Query::Clause object.
This is called by the various query methods like "select" in DB::Object::Query, "insert" in DB::Object::Query, "update" in DB::Object::Query, "delete" in DB::Object::Query
It will get the various query components (group, having, sort, order, limit) that have been set and add them formatted to an array that is returned.
This version of "_query_components" exists here to provide PostgreSQL specific implementation. See also the generic one in "_query_components" in DB::Object::Query
perl
Jacques Deguest <jack@deguest.jp>
Copyright (c) 2019-2021 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated files under the same terms as Perl itself.
To install DB::Object, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DB::Object
CPAN shell
perl -MCPAN -e shell install DB::Object
For more information on module installation, please visit the detailed CPAN module installation guide.