DBD-SQLite
view release on metacpan or search on metacpan
109310941095109610971098109911001101110211031104110511061107110811091110111111121113The callback will be called as
$code_ref
->(
$statement
)
where
$statement
is a UTF-8 rendering of the SQL statement text as the
statement first begins executing.
Additional callbacks might occur as
each
triggered subprogram is
entered. The callbacks
for
triggers contain a UTF-8 SQL comment
that identifies the trigger.
See also
"TRACING"
in DBI
for
better tracing options.
$dbh
->sqlite_profile(
$code_ref
)
This method registers a profile callback to be invoked whenever a
SQL statement finishes.
The callback will be called as
118311841185118611871188118911901191119211931194119511961197119811991200120112021203
DBD::SQLite::strlike(
$pattern
,
$string
,
$escape_char
), DBD::SQLite::strglob(
$pattern
,
$string
)
see
if
a string matches a pattern. These may be useful
when
you
create a virtual table or a custom function. See
DRIVER CONSTANTS
A subset of SQLite C constants are made available to Perl, because
they may be needed
when
writing hooks or authorizer callbacks. For
accessing such constants, the
"DBD::SQLite"
module must be
explicitly
"use"
d at compile
time
. For example, an authorizer that
forbids any DELETE operation would be written as follows :
$dbh
->sqlite_set_authorizer(
sub
{
my
$action_code
=
shift
;
return
$action_code
== DBD::SQLite::DELETE ? DBD::SQLite::DENY
: DBD::SQLite::OK;
});
140314041405140614071408140914101411141214131414141514161417141814191420142114221423
AND maxLat >= ? AND minLat <= ?
my
$contained
=
$dbh
->selectcol_arrayref(
$contained_sql
,
undef
,
$minLong
,
$maxLong
,
$minLat
,
$maxLat
);
my
$overlapping
=
$dbh
->selectcol_arrayref(
$overlap_sql
,
undef
,
$minLong
,
$maxLong
,
$minLat
,
$maxLat
);
For more detail, please see the SQLite R-Tree page
(<http://www.sqlite.org/rtree.html>). Note that custom R-Tree
queries using callbacks, as mentioned in the prior
link
, have not
been implemented yet.
VIRTUAL TABLES IMPLEMENTED IN PERL
SQLite
has
a concept of
"virtual tables"
which look like regular
tables but are implemented internally through specific functions.
The fulltext or R* tree features described in the previous
chapters are examples of such virtual tables, implemented in C
code.
"DBD::SQLite"
also supports virtual tables implemented in
*Perl
147414751476147714781479148014811482148314841485148614871488148914901491149214931494
Leak Detection
Implement one or more leak detection tests that only run during
AUTOMATED_TESTING and RELEASE_TESTING and validate that none of
the C code we work
with
leaks.
Stream API
for
Blobs
Reading/writing into blobs using
"sqlite2_blob_open"
/
"sqlite2_blob_close"
.
Support
for
custom callbacks
for
R-Tree queries
Custom queries of a R-Tree
index
using a callback are possible
based on a specific need, such as querying
for
overlapping
circles.
SUPPORT
Bugs should be reported via the CPAN bug tracker at
lib/DBD/SQLite.pm view on Meta::CPAN
165916601661166216631664166516661667166816691670167116721673167416751676167716781679
$dbh
->{sqlite_string_mode} = DBD_SQLITE_STRING_MODE_UNICODE_FALLBACK;
my
$sth
=
$dbh
->prepare(
"INSERT INTO mytable (blobcolumn) VALUES (?)"
);
# Binary_data will be stored as is.
$sth
->bind_param(1,
$binary_data
, SQL_BLOB);
Defining the column type as C<BLOB> in the DDL is B<not> sufficient.
=item * DBD_SQLITE_STRING_MODE_UNICODE_STRICT: Like
DBD_SQLITE_STRING_MODE_UNICODE_FALLBACK but usually throws an exception
rather than a warning if SQLite sends invalid UTF-8. (In Perl callbacks
from SQLite we still warn instead.)
=item * DBD_SQLITE_STRING_MODE_UNICODE_NAIVE: Like
DBD_SQLITE_STRING_MODE_UNICODE_FALLBACK but uses a "naïve" UTF-8 decoding
method that forgoes validation. This is marginally faster than a validated
decode, but it can also B<corrupt> B<Perl> B<itself!>
=item * DBD_SQLITE_STRING_MODE_PV (default, but B<DO> B<NOT> B<USE>): Like
DBD_SQLITE_STRING_MODE_BYTES, but when translating Perl strings to SQLite
the Perl string's internal byte buffer is given to SQLite. B<This> B<is>
lib/DBD/SQLite.pm view on Meta::CPAN
2327232823292330233123322333233423352336233723382339234023412342234323442345234623472348=over
=item $statement
is a UTF-8 rendering of the SQL statement text as the statement
first begins executing.
=back
Additional callbacks might occur as each triggered subprogram is
entered. The callbacks for triggers contain a UTF-8 SQL comment
that identifies the trigger.
See also L<DBI/TRACING> for better tracing options.
=head2 $dbh->sqlite_profile( $code_ref )
This method registers a profile callback to be invoked whenever
a SQL statement finishes.
The callback will be called as
lib/DBD/SQLite.pm view on Meta::CPAN
246224632464246524662467246824692470247124722473247424752476247724782479248024812482see
if
a string matches a pattern. These may be useful
when
you
create a virtual table or a custom function.
See L<http://sqlite.org/c3ref/strlike.html> and
=head1 DRIVER CONSTANTS
A subset of SQLite C constants are made available to Perl,
because they may be needed when writing
hooks or authorizer callbacks. For accessing such constants,
the C<DBD::SQLite> module must be explicitly C<use>d at compile
time. For example, an authorizer that forbids any
DELETE operation would be written as follows :
use DBD::SQLite;
$dbh->sqlite_set_authorizer(sub {
my $action_code = shift;
return $action_code == DBD::SQLite::DELETE ? DBD::SQLite::DENY
: DBD::SQLite::OK;
});
lib/DBD/SQLite.pm view on Meta::CPAN
270027012702270327042705270627072708270927102711271227132714271527162717271827192720
AND maxLat >= ? AND minLat <= ?
my
$contained
=
$dbh
->selectcol_arrayref(
$contained_sql
,
undef
,
$minLong
,
$maxLong
,
$minLat
,
$maxLat
);
my
$overlapping
=
$dbh
->selectcol_arrayref(
$overlap_sql
,
undef
,
$minLong
,
$maxLong
,
$minLat
,
$maxLat
);
For more detail, please see the SQLite R-Tree page
(L<https://www.sqlite.org/rtree.html>). Note that custom R-Tree
queries using callbacks, as mentioned in the prior
link
, have not been
implemented yet.
=head1 VIRTUAL TABLES IMPLEMENTED IN PERL
SQLite has a concept of "virtual tables" which look like regular
tables but are implemented internally through specific functions.
The fulltext or R* tree features described in the previous chapters
are examples of such virtual tables, implemented in C code.
C<DBD::SQLite> also supports virtual tables implemented in I<Perl code>:
lib/DBD/SQLite.pm view on Meta::CPAN
27802781278227832784278527862787278827892790279127922793279427952796279727982799=head2 Leak Detection
Implement one or more leak detection tests that only run during
AUTOMATED_TESTING and RELEASE_TESTING and validate that none of the C
code we work with leaks.
=head2 Stream API for Blobs
Reading/writing into blobs using C<sqlite2_blob_open> / C<sqlite2_blob_close>.
=head2 Support for custom callbacks for R-Tree queries
Custom queries of a R-Tree index using a callback are possible with
the SQLite C API (L<https://www.sqlite.org/rtree.html>), so one could
potentially use a callback that narrowed the result set down based
on a specific need, such as querying for overlapping circles.
=head1 SUPPORT
Bugs should be reported to GitHub issues:
lib/DBD/SQLite/VirtualTable.pm view on Meta::CPAN
299300301302303304305306307308309310311312313314315316317318the B<cursor> class implements methods
for
performing a specific
SQL statement
=back
=head2 Methods
Most methods in both classes are not called directly from Perl
code : instead, they are callbacks, called from the sqlite kernel.
Following common Perl conventions, such methods have names in
uppercase.
=head1 TABLE METHODS
=head2 Class methods for registering the module
=head3 CREATE_MODULE
3624362536263627362836293630363136323633363436353636363736383639364036413642364336443645** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
** instead of the routines described here.
**
** These routines register callback functions that can be used
for
** tracing and profiling the execution of SQL statements.
**
** ^The callback function registered by sqlite3_trace() is invoked at
** various
times
when
an SQL statement is being run by [sqlite3_step()].
** ^The sqlite3_trace() callback is invoked
with
a UTF-8 rendering of the
** SQL statement text as the statement first begins executing.
** ^(Additional sqlite3_trace() callbacks might occur
** as
each
triggered subprogram is entered. The callbacks
for
triggers
** contain a UTF-8 SQL comment that identifies the trigger.)^
**
** The [SQLITE_TRACE_SIZE_LIMIT] compile-
time
option can be used to limit
** the
length
of [bound parameter] expansion in the output of sqlite3_trace().
**
** ^The callback function registered by sqlite3_profile() is invoked
** as
each
SQL statement finishes. ^The profile callback contains
** the original statement text and an estimate of wall-clock
time
** of how long that statement took to run. ^The profile callback
**
time
is in units of nanoseconds, however the current implementation
5736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760** function can gain access to this pointer using [sqlite3_user_data()].)^
**
** ^The sixth, seventh and eighth parameters passed to the three
**
"sqlite3_create_function*"
functions, xFunc, xStep and xFinal, are
** pointers to C-language functions that implement the SQL function or
** aggregate. ^A
scalar
SQL function requires an implementation of the xFunc
** callback only; NULL pointers must be passed as the xStep and xFinal
** parameters. ^An aggregate SQL function requires an implementation of xStep
** and xFinal and NULL pointer must be passed
for
xFunc. ^To
delete
an existing
** SQL function or aggregate, pass NULL pointers
for
all three function
** callbacks.
**
** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue
** and xInverse) passed to sqlite3_create_window_function are pointers to
** C-language callbacks that implement the new function. xStep and xFinal
** must both be non-NULL. xValue and xInverse may either both be NULL, in
** which case a regular aggregate function is created, or must both be
** non-NULL, in which case the new function may be used as either an aggregate
** or aggregate window function. More details regarding the implementation
** of aggregate window functions are
** [user-
defined
window functions|available here].
**
** ^(If the final parameter to sqlite3_create_function_v2() or
** sqlite3_create_window_function() is not NULL, then it is destructor
for
** the application data pointer. The destructor is invoked
when
the function
637263736374637563766377637863796380638163826383638463856386638763886389639063916392** C++ compilers.
*/
typedef void (
*sqlite3_destructor_type
)(void*);
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
/*
** CAPI3REF: Setting The Result Of An SQL Function
** METHOD: sqlite3_context
**
** These routines are used by the xFunc or xFinal callbacks that
** implement SQL functions and aggregates. See
** [sqlite3_create_function()] and [sqlite3_create_function16()]
**
for
additional information.
**
** These functions work very much like the [parameter binding] family of
** functions used to
bind
values
to host parameters in prepared statements.
** Refer to the [SQL parameter] documentation
for
additional information.
**
** ^The sqlite3_result_blob() interface sets the result from
** an application-
defined
function to be the BLOB whose content is pointed
706470657066706770687069707070717072707370747075707670777078707970807081708270837084**
for
the same database connection is overridden.
** ^The pArg argument is passed through to the callback.
** ^If the callback on a commit hook function returns non-zero,
** then the commit is converted into a rollback.
**
** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
**
return
the P argument from the previous call of the same function
** on the same [database connection] D, or NULL
for
** the first call
for
each
function on D.
**
** The commit and rollback hook callbacks are not reentrant.
** The callback implementation must not
do
anything that will modify
** the database connection that invoked the callback. Any actions
** to modify the database connection must be deferred
until
after
the
** completion of the [sqlite3_step()] call that triggered the commit
** or rollback hook in the first place.
** Note that running any other SQL statements, including SELECT statements,
** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
** the database connections
for
the meaning of
"modify"
in this paragraph.
**
** ^Registering a NULL function disables the callback.
106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700**
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
** that is invoked prior to
each
[INSERT], [UPDATE], and [DELETE] operation
** on a database table.
** ^At most one preupdate hook may be registered at a
time
on a single
** [database connection];
each
call to [sqlite3_preupdate_hook()] overrides
** the previous setting.
** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
**
with
a NULL pointer as the second parameter.
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
** the first parameter to callbacks.
**
** ^The preupdate hook only fires
for
changes to real database tables; the
** preupdate hook is not invoked
for
changes to [virtual tables] or to
**
system
tables like sqlite_sequence or sqlite_stat1.
**
** ^The second parameter to the preupdate callback is a pointer to
** the [database connection] that registered the preupdate hook.
** ^The third parameter to the preupdate callback is one of the constants
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
** kind of update operation that is about to occur.
107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759** behavior.
**
** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
** in the row that is being inserted, updated, or deleted.
**
** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row
before
it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
** preupdate callbacks;
if
it is used by an SQLITE_INSERT callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed
when
the preupdate callback returns.
**
** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row
after
it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
** preupdate callbacks;
if
it is used by an SQLITE_DELETE callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed
when
the preupdate callback returns.
**
** ^The [sqlite3_preupdate_depth(D)] interface returns 0
if
the preupdate
** callback was invoked as a result of a direct insert, update, or
delete
** operation; or 1
for
inserts, updates, or deletes invoked by top-level
** triggers; or 2
for
changes resulting from triggers called by top-level
** triggers; and so forth.
**
** When the [sqlite3_blob_write()] API is used to update a blob column,
112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223SQLITE_API
int
sqlite3_rtree_geometry_callback(
sqlite3
*db
,
const char
*zGeom
,
int
(
*xGeom
)(sqlite3_rtree_geometry*,
int
, sqlite3_rtree_dbl*,
int
*),
void
*pContext
);
/*
** A pointer to a structure of the following type is passed as the first
** argument to callbacks registered using rtree_geometry_callback().
*/
struct sqlite3_rtree_geometry {
void
*pContext
; /* Copy of pContext passed to s_r_g_c() */
int
nParam; /* Size of array aParam[] */
sqlite3_rtree_dbl
*aParam
; /* Parameters passed to SQL geom function */
void
*pUser
; /* Callback implementation user data */
void (
*xDelUser
)(void *); /* Called by SQLite to clean up pUser */
};
/*
180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067**
** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
**
** SFUNCTION(zName, nArg, iArg, bNC, xFunc)
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
** adds the SQLITE_DIRECTONLY flag.
**
** INLINE_FUNC(zName, nArg, iFuncId, mFlags)
** zName is the name of a function that is implemented by in-line
** byte code rather than by the usual callbacks. The iFuncId
** parameter determines the function id. The mFlags parameter is
** optional SQLITE_FUNC_ flags
for
this function.
**
** TEST_FUNC(zName, nArg, iFuncId, mFlags)
** zName is the name of a test-only function implemented by in-line
** byte code rather than by the usual callbacks. The iFuncId
** parameter determines the function id. The mFlags parameter is
** optional SQLITE_FUNC_ flags
for
this function.
**
** DFUNCTION(zName, nArg, iArg, bNC, xFunc)
** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and
** adds the SQLITE_FUNC_SLOCHNG flag. Used
for
date &
time
functions
** and functions like sqlite_version() that can change, but not during
** a single query. The iArg is ignored. The user-data is always set
** to a NULL pointer. The bNC parameter is not used.
**
1988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901
int
addrExplain; /* Address of current OP_Explain opcode */
#endif
VList
*pVList
; /* Mapping between variable names and numbers */
Vdbe
*pReprepare
; /* VM being reprepared (sqlite3Reprepare()) */
const char
*zTail
; /* All SQL text past the
last
semicolon parsed */
Table
*pNewTable
; /* A table being constructed by CREATE TABLE */
Index
*pNewIndex
; /* An
index
being constructed by CREATE INDEX.
** Also used to hold redundant UNIQUE constraints
** during a RENAME COLUMN */
Trigger
*pNewTrigger
; /* Trigger under construct by a CREATE TRIGGER */
const char
*zAuthContext
; /* The 6th parameter to db->xAuth callbacks */
#ifndef SQLITE_OMIT_VIRTUALTABLE
Token sArg; /* Complete text of a module argument */
Table *
*apVtabLock
; /* Pointer to virtual tables needing locking */
#endif
With
*pWith
; /* Current WITH clause, or NULL */
#ifndef SQLITE_OMIT_ALTERTABLE
RenameToken
*pRename
; /* Tokens subject to renaming by ALTER TABLE */
#endif
};
203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359#endif
#ifndef SQLITE_OMIT_CTE
SQLITE_PRIVATE void sqlite3SelectPopWith(Walker*, Select*);
#else
# define sqlite3SelectPopWith 0
#endif
/*
** Return code from the parse-tree walking primitives and their
** callbacks.
*/
#define WRC_Continue 0 /* Continue down into children */
#define WRC_Prune 1 /* Omit children but continue walking siblings */
#define WRC_Abort 2 /* Abandon the tree walk */
/*
** A single common table expression
*/
struct Cte {
char
*zName
; /* Name of this CTE */
8230282303823048230582306823078230882309823108231182312823138231482315823168231782318823198232082321
i64 iCurrent;
int
rc = sqlite3OsFileSize(pFile,
&iCurrent
);
if
( rc==SQLITE_OK && iCurrent>iSize ){
rc = sqlite3OsTruncate(pFile, iSize);
}
return
rc;
}
/*
** Register this backup object
with
the associated source pager
for
** callbacks
when
pages are changed or the cache invalidated.
*/
static void attachBackupObject(sqlite3_backup
*p
){
sqlite3_backup *
*pp
;
assert( sqlite3BtreeHoldsMutex(p->pSrc) );
pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
p->pNext =
*pp
;
*pp
= p;
p->isAttached = 1;
}
88302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320
assert( db->nVdbeRead>=db->nVdbeWrite );
assert( db->nVdbeWrite>=0 );
p->eVdbeState = VDBE_HALT_STATE;
checkActiveVdbeCnt(db);
if
( db->mallocFailed ){
p->rc = SQLITE_NOMEM_BKPT;
}
/* If the auto-commit flag is set to true, then any locks that were held
** by connection db have now been released. Call sqlite3ConnectionUnlocked()
** to invoke any required unlock-notify callbacks.
*/
if
( db->autoCommit ){
sqlite3ConnectionUnlocked(db);
}
assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 );
return
(p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK);
}
910889108991090910919109291093910949109591096910979109891099911009110191102911039110491105911069110791108
if
( pCtx->pOut->flags & MEM_Int ){
pCtx->pOut->flags &= ~MEM_Int;
pCtx->pOut->flags |= MEM_IntReal;
}
}
#endif
/*
** This function is called
after
a transaction
has
been committed. It
** invokes callbacks registered
with
sqlite3_wal_hook() as required.
*/
static
int
doWalCallbacks(sqlite3
*db
){
int
rc = SQLITE_OK;
#ifndef SQLITE_OMIT_WAL
int
i;
for
(i=0; i<db->nDb; i++){
Btree
*pBt
= db->aDb[i].pBt;
if
( pBt ){
int
nEntry;
sqlite3BtreeEnter(pBt);
968729687396874968759687696877968789687996880968819688296883968849688596886968879688896889968909689196892
/* A new savepoint cannot be created
if
there are active
write
** statements (i.e.
open
read
/
write
incremental blob handles).
*/
sqlite3VdbeError(p,
"cannot open savepoint - SQL statements in progress"
);
rc = SQLITE_BUSY;
}
else
{
nName = sqlite3Strlen30(zName);
#ifndef SQLITE_OMIT_VIRTUALTABLE
/* This call is Ok even
if
this savepoint is actually a transaction
** savepoint (and therefore should not prompt xSavepoint()) callbacks.
** If this is a transaction savepoint being opened, it is guaranteed
** that the db->aVTrans[] array is empty. */
assert( db->autoCommit==0 || db->nVTrans==0 );
rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN,
db->nStatement+db->nSavepoint);
if
( rc!=SQLITE_OK )
goto
abort_due_to_error;
#endif
/* Create a new savepoint structure. */
pNew = sqlite3DbMallocRawNN(db, sizeof(Savepoint)+nName+1);
100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054
pOut->u.i = pgno;
break;
}
/* Opcode: SqlExec P1 P2 * P4 *
**
** Run the SQL statement or statements specified in the P4 string.
**
** The P1 parameter is a bitmask of options:
**
** 0x0001 Disable Auth and Trace callbacks
while
the statements
** in P4 are running.
**
** 0x0002 Set db->nAnalysisLimit to P2
while
the statements in
** P4 are running.
**
*/
case OP_SqlExec: {
char
*zErr
;
#ifndef SQLITE_OMIT_AUTHORIZATION
sqlite3_xauth xAuth;
106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530** is invoked
before
visiting children.)
**
** The
return
value from the callback should be one of the WRC_*
** constants to specify how to proceed
with
the walk.
**
** WRC_Continue Continue descending down the tree.
**
** WRC_Prune Do not descend into child nodes, but allow
** the walk to
continue
with
sibling nodes.
**
** WRC_Abort Do
no
more callbacks. Unwind the stack and
**
return
from the top-level walk call.
**
** The
return
value from this routine is WRC_Abort to abandon the tree walk
** and WRC_Continue to
continue
.
*/
SQLITE_PRIVATE SQLITE_NOINLINE
int
sqlite3WalkExprNN(Walker
*pWalker
, Expr
*pExpr
){
int
rc;
testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
testcase( ExprHasProperty(pExpr, EP_Reduced) );
while
(1){
106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602*/
SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker
*pWalker
, Select
*p
){
UNUSED_PARAMETER(pWalker);
UNUSED_PARAMETER(p);
/* No-op */
}
/*
** Walk all expressions associated
with
SELECT statement p. Do
** not invoke the SELECT callback on p, but
do
(of course) invoke
** any expr callbacks and SELECT callbacks that come from subqueries.
** Return WRC_Abort or WRC_Continue.
*/
SQLITE_PRIVATE
int
sqlite3WalkSelectExpr(Walker
*pWalker
, Select
*p
){
if
( sqlite3WalkExprList(pWalker, p->pEList) )
return
WRC_Abort;
if
( sqlite3WalkExpr(pWalker, p->pWhere) )
return
WRC_Abort;
if
( sqlite3WalkExprList(pWalker, p->pGroupBy) )
return
WRC_Abort;
if
( sqlite3WalkExpr(pWalker, p->pHaving) )
return
WRC_Abort;
if
( sqlite3WalkExprList(pWalker, p->pOrderBy) )
return
WRC_Abort;
if
( sqlite3WalkExpr(pWalker, p->pLimit) )
return
WRC_Abort;
#if !defined(SQLITE_OMIT_WINDOWFUNC)
111415111416111417111418111419111420111421111422111423111424111425111426111427111428111429111430111431111432111433111434111435111436111437111438111439111440111441111442111443111444111445111446111447
|| ExprHasProperty(pExpr, EP_WinFunc)
){
pWalker->eCode = 0;
return
WRC_Abort;
}
return
WRC_Prune;
}
/*
** These routines are Walker callbacks used to check expressions to
** see
if
they are
"constant"
for
some definition of constant. The
** Walker.eCode value determines the type of
"constant"
we are looking
**
for
.
**
** These callback routines are used to implement the following:
**
** sqlite3ExprIsConstant() pWalker->eCode==1
** sqlite3ExprIsConstantNotJoin() pWalker->eCode==2
** sqlite3ExprIsTableConstant() pWalker->eCode==3
** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5
**
** In all cases, the callbacks set Walker.eCode=0 and abort
if
the expression
** is found to not be a constant.
**
** The sqlite3ExprIsConstantOrFunction() is used
for
evaluating DEFAULT
** expressions in a CREATE TABLE statement. The Walker.eCode value is 5
**
when
parsing an existing schema out of the sqlite_schema table and 4
**
when
processing a new CREATE TABLE statement. A bound parameter raises
** an error
for
new statements, but is silently converted
** to NULL
for
existing schemas. This allows sqlite_schema tables that
** contain a bound parameter because they were generated by older versions
** of SQLite to be parsed by newer versions of SQLite without raising a
113304113305113306113307113308113309113310113311113312113313113314113315113316113317113318113319113320113321113322113323113324** so that a subsequent copy will not be merged into this one.
*/
static void setDoNotMergeFlagOnCopy(Vdbe
*v
){
if
( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){
sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergeable */
}
}
/*
** Generate code to implement special SQL functions that are implemented
** in-line rather than by using the usual callbacks.
*/
static
int
exprCodeInlineFunction(
Parse
*pParse
, /* Parsing context */
ExprList
*pFarg
, /* List of function arguments */
int
iFuncId, /* Function ID. One of the INTFUNC_...
values
*/
int
target /* Store function result in this register */
){
int
nFarg;
Vdbe
*v
= pParse->pVdbe;
assert( v!=0 );
115543115544115545115546115547115548115549115550115551115552115553115554115555115556115557115558115559115560115561115562115563** implement sqlite3ReferencesSrcList().
*/
struct RefSrcList {
sqlite3
*db
; /* Database connection used
for
sqlite3DbRealloc() */
SrcList
*pRef
; /* Looking
for
references to these tables */
i64 nExclude; /* Number of tables to exclude from the search */
int
*aiExclude
; /* Cursor IDs
for
tables to exclude from the search */
};
/*
** Walker SELECT callbacks
for
sqlite3ReferencesSrcList().
**
** When entering a new subquery on the pExpr argument, add all FROM clause
** entries
for
that subquery to the exclude list.
**
** When leaving the subquery, remove those entries from the exclude list.
*/
static
int
selectRefEnter(Walker
*pWalker
, Select
*pSelect
){
struct RefSrcList
*p
= pWalker->u.pRefSrcList;
SrcList
*pSrc
= pSelect->pSrc;
i64 i, j;
121329121330121331121332121333121334121335121336121337121338121339121340121341121342121343121344121345121346121347121348121349
pParse->rc = SQLITE_AUTH;
}
else
if
( rc!=SQLITE_OK && rc!=SQLITE_IGNORE ){
rc = SQLITE_DENY;
sqliteAuthBadReturnCode(pParse);
}
return
rc;
}
/*
** Push an authorization context. After this routine is called, the
** zArg3 argument to authorization callbacks will be zContext
until
** popped. Or
if
pParse==0, this routine is a
no
-op.
*/
SQLITE_PRIVATE void sqlite3AuthContextPush(
Parse
*pParse
,
AuthContext
*pContext
,
const char
*zContext
){
assert( pParse );
pContext->pParse = pParse;
pContext->zAuthContext = pParse->zAuthContext;
138357138358138359138360138361138362138363138364138365138366138367138368138369138370138371138372138373138374138375138376138377#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
{/* zName: */
"defer_foreign_keys"
,
/* ePragTyp: */ PragTyp_FLAG,
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
/* ColNames: */ 0, 0,
/* iArg: */ SQLITE_DeferFKs },
#endif
#endif
#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
{/* zName: */
"empty_result_callbacks"
,
/* ePragTyp: */ PragTyp_FLAG,
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
/* ColNames: */ 0, 0,
/* iArg: */ SQLITE_NullCallback },
#endif
#if !defined(SQLITE_OMIT_UTF16)
{/* zName: */
"encoding"
,
/* ePragTyp: */ PragTyp_ENCODING,
/* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1,
/* ColNames: */ 0, 0,
150545150546150547150548150549150550150551150552150553150554150555150556150557150558150559150560150561150562150563150564150565
** Examples of where these kinds of null SQLITE_READ authorizations
** would occur:
**
** SELECT count(*) FROM t1; -- SQLITE_READ t1.
""
** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2.
""
**
** The fake column name is an empty string. It is possible
for
a table to
** have a column named by the empty string, in which case there is
no
way to
** distinguish between an unreferenced table and an actual reference to the
**
""
column. The original design was
for
the fake column name to be a NULL,
** which would be unambiguous. But legacy authorization callbacks might
** string
for
the fake column name seems safer.
*/
if
( pItem->colUsed==0 && pItem->zName!=0 ){
sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName,
""
, pItem->zDatabase);
}
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
/* Generate code
for
all
sub
-queries in the FROM clause
*/
156346156347156348156349156350156351156352156353156354156355156356156357156358156359156360156361156362156363156364156365156366
return
rc;
}
/*
** This function invokes either the xRollback or xCommit method
** of
each
of the virtual tables in the sqlite3.aVTrans array. The method
** called is identified by the second argument,
"offset"
, which is
** the offset of the method to call in the sqlite3_module structure.
**
** The array is cleared
after
invoking the callbacks.
*/
static void callFinaliser(sqlite3
*db
,
int
offset){
int
i;
if
( db->aVTrans ){
VTable *
*aVTrans
= db->aVTrans;
db->aVTrans = 0;
for
(i=0; i<db->nVTrans; i++){
VTable
*pVTab
= aVTrans[i];
sqlite3_vtab
*p
= pVTab->pVtab;
if
( p ){
170904170905170906170907170908170909170910170911170912170913170914170915170916170917170918170919170920170921170922170923170924170925170926170927170928** that it processes in a temporary table. If it is not zero, this
** variable indicates
when
rows may be removed from the temp table (in
** order to reduce memory requirements - it would always be safe just
** to leave them there). Possible
values
for
eDelete are:
**
** WINDOW_RETURN_ROW:
** An input row can be discarded
after
it is returned to the
caller
.
**
** WINDOW_AGGINVERSE:
** An input row can be discarded
after
the window functions xInverse()
** callbacks have been invoked in it.
**
** WINDOW_AGGSTEP:
** An input row can be discarded
after
the window functions xStep()
** callbacks have been invoked in it.
**
** start,current,end
** Consider a window-frame similar to the following:
**
** (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING)
**
** The windows functions implementation caches the input rows in a temp
** table, sorted by
"a, b"
(it actually populates the cache lazily, and
** aggressively removes rows once they are
no
longer required, but that's
** a mere detail). It keeps three cursors
open
on the temp table. One
181166181167181168181169181170181171181172181173181174181175181176181177181178181179181180181181181182181183181184181185181186
sqlite3SchemaClear(db->aDb[1].pSchema);
}
sqlite3VtabUnlockList(db);
/* Free up the array of auxiliary databases */
sqlite3CollapseDatabaseArray(db);
assert( db->nDb<=2 );
assert( db->aDb==db->aDbStatic );
/* Tell the code in notify.c that the connection
no
longer holds any
*/
sqlite3ConnectionClosed(db);
for
(i=sqliteHashFirst(
&db
->aFunc); i; i=sqliteHashNext(i)){
FuncDef
*pNext
,
*p
;
p = sqliteHashData(i);
do
{
functionDestroy(db, p);
pNext = p->pNext;
sqlite3DbFree(db, p);
185002185003185004185005185006185007185008185009185010185011185012185013185014185015185016185017185018185019185020185021185022185023**
** If there is
no
blocking connection, the callback is invoked immediately,
**
before
this routine returns.
**
** If pOther is already blocked on db, then report SQLITE_LOCKED, to indicate
** a deadlock.
**
** Otherwise, make arrangements to invoke xNotify
when
pOther drops
** its locks.
**
** Each call to this routine overrides any prior callbacks registered
** on the same
"db"
. If xNotify==0 then any prior callbacks are immediately
** cancelled.
*/
SQLITE_API
int
sqlite3_unlock_notify(
sqlite3
*db
,
void (
*xNotify
)(void **,
int
),
void
*pArg
){
int
rc = SQLITE_OK;
#ifdef SQLITE_ENABLE_API_ARMOR
185136185137185138185139185140185141185142185143185144185145185146185147185148185149185150185151185152185153185154185155185156185157185158185159185160185161185162185163185164185165185166
aDyn = aArg = pNew;
}
else
{
/* This occurs
when
the array of context pointers that need to
** be passed to the unlock-notify callback is larger than the
** aStatic[] array allocated on the stack and the attempt to
** allocate a larger array from the heap
has
failed.
**
** This is a difficult situation to handle. Returning an error
** code to the
caller
is insufficient, as even
if
an error code
** is returned the transaction on connection db will still be
** closed and the unlock-notify callbacks on blocked connections
** will go unissued. This might cause the application to
wait
** indefinitely
for
an unlock-notify callback that will never
** arrive.
**
** Instead, invoke the unlock-notify callback
with
the context
** array already accumulated. We can then clear the array and
** begin accumulating any further context pointers without
** requiring any dynamic allocation. This is
sub
-optimal because
** it means that instead of one callback
with
a large array of
** context pointers the application will receive two or more
** callbacks
with
smaller arrays of context pointers, which will
** reduce the applications ability to prioritize multiple
** connections. But it is the best that can be done under the
** circumstances.
*/
xUnlockNotify(aArg, nArg);
nArg = 0;
}
}
sqlite3EndBenignMalloc();
199393199394199395199396199397199398199399199400199401199402199403199404199405199406199407199408199409199410199411199412199413/* If all the seg-readers are at EOF, we're finished.
return
SQLITE_OK. */
assert( rc==SQLITE_OK );
if
( apSegment[0]->aNode==0 ) break;
pCsr->nTerm = apSegment[0]->nTerm;
pCsr->zTerm = apSegment[0]->zTerm;
/* If this is a prefix-search, and
if
the term that apSegment[0] points
** to does not share a suffix
with
pFilter->zTerm/nTerm, then all
** required callbacks have been made. In this case
exit
early.
**
** Similarly,
if
this is a search
for
an exact match, and the first term
** of segment apSegment[0] is not a match,
exit
early.
*/
if
( pFilter->zTerm && !isScan ){
if
( pCsr->nTerm<pFilter->nTerm
|| (!isPrefix && pCsr->nTerm>pFilter->nTerm)
|| memcmp(pCsr->zTerm, pFilter->zTerm, pFilter->nTerm)
){
break;
236371236372236373236374236375236376236377236378236379236380236381236382236383236384236385236386236387236388236389236390236391** arguments passed to it are, in order:
**
** void
*pCtx
// Copy of 4th argument to sqlite3Fts5Tokenize()
** const char
*pToken
// Pointer to buffer containing token
**
int
nToken // Size of token in bytes
**
int
iStart // Byte offset of start of token within input text
**
int
iEnd // Byte offset of end of token within input text
**
int
iPos // Position of token in input (first token is 0)
**
** If the callback returns a non-zero value the tokenization is abandoned
** and
no
further callbacks are issued.
**
** This function returns SQLITE_OK
if
successful or an SQLite error code
**
if
an error occurs. If the tokenization was abandoned early because
** the callback returned SQLITE_DONE, this is not an error and this function
** still returns SQLITE_OK. Or,
if
the tokenization was abandoned early
** because the callback returned another non-zero value, it is assumed
** to be an SQLite error code and returned to the
caller
.
*/
static
int
sqlite3Fts5Tokenize(
Fts5Config
*pConfig
, /* FTS5 Configuration object */
3311331233133314331533163317331833193320332133223323332433253326332733283329333033313332** These routines are deprecated. Use the [sqlite3_trace_v2()] interface
** instead of the routines described here.
**
** These routines register callback functions that can be used
for
** tracing and profiling the execution of SQL statements.
**
** ^The callback function registered by sqlite3_trace() is invoked at
** various
times
when
an SQL statement is being run by [sqlite3_step()].
** ^The sqlite3_trace() callback is invoked
with
a UTF-8 rendering of the
** SQL statement text as the statement first begins executing.
** ^(Additional sqlite3_trace() callbacks might occur
** as
each
triggered subprogram is entered. The callbacks
for
triggers
** contain a UTF-8 SQL comment that identifies the trigger.)^
**
** The [SQLITE_TRACE_SIZE_LIMIT] compile-
time
option can be used to limit
** the
length
of [bound parameter] expansion in the output of sqlite3_trace().
**
** ^The callback function registered by sqlite3_profile() is invoked
** as
each
SQL statement finishes. ^The profile callback contains
** the original statement text and an estimate of wall-clock
time
** of how long that statement took to run. ^The profile callback
**
time
is in units of nanoseconds, however the current implementation
5423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447** function can gain access to this pointer using [sqlite3_user_data()].)^
**
** ^The sixth, seventh and eighth parameters passed to the three
**
"sqlite3_create_function*"
functions, xFunc, xStep and xFinal, are
** pointers to C-language functions that implement the SQL function or
** aggregate. ^A
scalar
SQL function requires an implementation of the xFunc
** callback only; NULL pointers must be passed as the xStep and xFinal
** parameters. ^An aggregate SQL function requires an implementation of xStep
** and xFinal and NULL pointer must be passed
for
xFunc. ^To
delete
an existing
** SQL function or aggregate, pass NULL pointers
for
all three function
** callbacks.
**
** ^The sixth, seventh, eighth and ninth parameters (xStep, xFinal, xValue
** and xInverse) passed to sqlite3_create_window_function are pointers to
** C-language callbacks that implement the new function. xStep and xFinal
** must both be non-NULL. xValue and xInverse may either both be NULL, in
** which case a regular aggregate function is created, or must both be
** non-NULL, in which case the new function may be used as either an aggregate
** or aggregate window function. More details regarding the implementation
** of aggregate window functions are
** [user-
defined
window functions|available here].
**
** ^(If the final parameter to sqlite3_create_function_v2() or
** sqlite3_create_window_function() is not NULL, then it is destructor
for
** the application data pointer. The destructor is invoked
when
the function
605960606061606260636064606560666067606860696070607160726073607460756076607760786079** C++ compilers.
*/
typedef void (
*sqlite3_destructor_type
)(void*);
#define SQLITE_STATIC ((sqlite3_destructor_type)0)
#define SQLITE_TRANSIENT ((sqlite3_destructor_type)-1)
/*
** CAPI3REF: Setting The Result Of An SQL Function
** METHOD: sqlite3_context
**
** These routines are used by the xFunc or xFinal callbacks that
** implement SQL functions and aggregates. See
** [sqlite3_create_function()] and [sqlite3_create_function16()]
**
for
additional information.
**
** These functions work very much like the [parameter binding] family of
** functions used to
bind
values
to host parameters in prepared statements.
** Refer to the [SQL parameter] documentation
for
additional information.
**
** ^The sqlite3_result_blob() interface sets the result from
** an application-
defined
function to be the BLOB whose content is pointed
675167526753675467556756675767586759676067616762676367646765676667676768676967706771**
for
the same database connection is overridden.
** ^The pArg argument is passed through to the callback.
** ^If the callback on a commit hook function returns non-zero,
** then the commit is converted into a rollback.
**
** ^The sqlite3_commit_hook(D,C,P) and sqlite3_rollback_hook(D,C,P) functions
**
return
the P argument from the previous call of the same function
** on the same [database connection] D, or NULL
for
** the first call
for
each
function on D.
**
** The commit and rollback hook callbacks are not reentrant.
** The callback implementation must not
do
anything that will modify
** the database connection that invoked the callback. Any actions
** to modify the database connection must be deferred
until
after
the
** completion of the [sqlite3_step()] call that triggered the commit
** or rollback hook in the first place.
** Note that running any other SQL statements, including SELECT statements,
** or merely calling [sqlite3_prepare_v2()] and [sqlite3_step()] will modify
** the database connections
for
the meaning of
"modify"
in this paragraph.
**
** ^Registering a NULL function disables the callback.
103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387**
** ^The [sqlite3_preupdate_hook()] interface registers a callback function
** that is invoked prior to
each
[INSERT], [UPDATE], and [DELETE] operation
** on a database table.
** ^At most one preupdate hook may be registered at a
time
on a single
** [database connection];
each
call to [sqlite3_preupdate_hook()] overrides
** the previous setting.
** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()]
**
with
a NULL pointer as the second parameter.
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
** the first parameter to callbacks.
**
** ^The preupdate hook only fires
for
changes to real database tables; the
** preupdate hook is not invoked
for
changes to [virtual tables] or to
**
system
tables like sqlite_sequence or sqlite_stat1.
**
** ^The second parameter to the preupdate callback is a pointer to
** the [database connection] that registered the preupdate hook.
** ^The third parameter to the preupdate callback is one of the constants
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
** kind of update operation that is about to occur.
104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446** behavior.
**
** ^The [sqlite3_preupdate_count(D)] interface returns the number of columns
** in the row that is being inserted, updated, or deleted.
**
** ^The [sqlite3_preupdate_old(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row
before
it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_UPDATE and SQLITE_DELETE
** preupdate callbacks;
if
it is used by an SQLITE_INSERT callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed
when
the preupdate callback returns.
**
** ^The [sqlite3_preupdate_new(D,N,P)] interface writes into P a pointer to
** a [protected sqlite3_value] that contains the value of the Nth column of
** the table row
after
it is updated. The N parameter must be between 0
** and one less than the number of columns or the behavior will be
** undefined. This must only be used within SQLITE_INSERT and SQLITE_UPDATE
** preupdate callbacks;
if
it is used by an SQLITE_DELETE callback then the
** behavior is undefined. The [sqlite3_value] that P points to
** will be destroyed
when
the preupdate callback returns.
**
** ^The [sqlite3_preupdate_depth(D)] interface returns 0
if
the preupdate
** callback was invoked as a result of a direct insert, update, or
delete
** operation; or 1
for
inserts, updates, or deletes invoked by top-level
** triggers; or 2
for
changes resulting from triggers called by top-level
** triggers; and so forth.
**
** When the [sqlite3_blob_write()] API is used to update a blob column,
108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910SQLITE_API
int
sqlite3_rtree_geometry_callback(
sqlite3
*db
,
const char
*zGeom
,
int
(
*xGeom
)(sqlite3_rtree_geometry*,
int
, sqlite3_rtree_dbl*,
int
*),
void
*pContext
);
/*
** A pointer to a structure of the following type is passed as the first
** argument to callbacks registered using rtree_geometry_callback().
*/
struct sqlite3_rtree_geometry {
void
*pContext
; /* Copy of pContext passed to s_r_g_c() */
int
nParam; /* Size of array aParam[] */
sqlite3_rtree_dbl
*aParam
; /* Parameters passed to SQL geom function */
void
*pUser
; /* Callback implementation user data */
void (
*xDelUser
)(void *); /* Called by SQLite to clean up pUser */
};
/*
( run in 0.281 second using v1.01-cache-2.11-cpan-0f795438458 )