#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
/*
** If the following function pointer is not NULL and if
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
** I/O active are written using this function. These messages
** are intended for debugging activity only.
*/
/* not-private */ void (*sqlite3IoTrace)(const char*, ...) = 0;
#endif
/*
** If the following global variable points to a string which is the
** name of a directory, then that directory will be used to store
** temporary files.
**

|

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

#if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
/*
** If the following function pointer is not NULL and if
** SQLITE_ENABLE_IOTRACE is enabled, then messages describing
** I/O active are written using this function. These messages
** are intended for debugging activity only.
*/
SQLITE_API void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...) = 0;
#endif
/*
** If the following global variable points to a string which is the
** name of a directory, then that directory will be used to store
** temporary files.
**

*/
memset(&sNC, 0, sizeof(sNC));
sNC.pParse = pParse;
if( sqlite3ResolveExprNames(&sNC, p->pLimit) ||
sqlite3ResolveExprNames(&sNC, p->pOffset) ){
return WRC_Abort;
}
/* If the SF_Converted flags is set, then this Select object was ** was created by the convertCompoundSelectToSubquery() function. ** In this case the ORDER BY clause (p->pOrderBy) should be resolved ** as if it were part of the sub-query, not the parent. This block ** moves the pOrderBy down to the sub-query. It will be moved back ** after the names have been resolved. */ if( p->selFlags & SF_Converted ){ Select *pSub = p->pSrc->a[0].pSelect; assert( p->pSrc->nSrc==1 && isCompound==0 && p->pOrderBy ); assert( pSub->pPrior && pSub->pOrderBy==0 ); pSub->pOrderBy = p->pOrderBy; p->pOrderBy = 0; }
/* Recursively resolve names in all subqueries
*/
for(i=0; i<p->pSrc->nSrc; i++){
struct SrcList_item *pItem = &p->pSrc->a[i];
if( pItem->pSelect ){
NameContext *pNC; /* Used to iterate name contexts */
................................................................................
if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort;
/* The ORDER BY and GROUP BY clauses may not refer to terms in
** outer queries
*/
sNC.pNext = 0;
sNC.ncFlags |= NC_AllowAgg;
/* If this is a converted compound query, move the ORDER BY clause from ** the sub-query back to the parent query. At this point each term ** within the ORDER BY clause has been transformed to an integer value. ** These integers will be replaced by copies of the corresponding result ** set expressions by the call to resolveOrderGroupBy() below. */ if( p->selFlags & SF_Converted ){ Select *pSub = p->pSrc->a[0].pSelect; p->pOrderBy = pSub->pOrderBy; pSub->pOrderBy = 0; }
/* Process the ORDER BY clause for singleton SELECT statements.
** The ORDER BY clause for compounds SELECT statements is handled
** below, after all of the result-sets for all of the elements of
** the compound have been resolved.
*/
if( !isCompound && resolveOrderGroupBy(&sNC, p, p->pOrderBy, "ORDER") ){

# 2015-03-30## The author disclaims copyright to this source code. In place of# a legal notice, here is a blessing:## May you do good and not evil.# May you find forgiveness for yourself and forgive others.# May you share freely, never taking more than you give.##***********************************************************************## Corruption consisting of a database page that thinks it is a child# of itself.#set testdir [file dirname $argv0]source $testdir/tester.tclset testprefix corruptJif {[permutation]=="mmap"} { finish_test return}# Do not use a codec for tests in this file, as the database file is# manipulated directly using tcl scripts (using the [hexio_write] command).#do_not_use_codecdatabase_may_be_corrupt# Initialize the database.#do_execsql_test 1.1 { PRAGMA page_size=1024; PRAGMA auto_vacuum=0; CREATE TABLE t1(a,b); WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<10) INSERT INTO t1(a,b) SELECT i, zeroblob(700) FROM c;} {}db close# Corrupt the root page of the t1 table such that the left-child pointer# for the very first cell points back to the root. Then try to DROP the# table. The clearDatabasePage() routine should not loop.#do_test 1.2 { hexio_write test.db [expr {2*1024-2}] 02 sqlite3 db test.db catchsql { DROP TABLE t1 }} {1 {database disk image is malformed}}# Similar test using a WITHOUT ROWID table#do_test 2.1 { db close forcedelete test.db sqlite3 db test.db db eval { PRAGMA page_size=1024; PRAGMA auto_vacuum=0; CREATE TABLE t1(a,b,PRIMARY KEY(a,b)) WITHOUT ROWID; WITH RECURSIVE c(i) AS (VALUES(1) UNION ALL SELECT i+1 FROM c WHERE i<100) INSERT INTO t1(a,b) SELECT i, zeroblob(200) FROM c; }} {}# The table is three levels deep. Corrupt the left child of an intermediate# page so that it points back to the root page.#do_test 2.2 { db close hexio_read test.db [expr {9*1024+391}] 8} {00000008814D0401}do_test 2.2b { hexio_write test.db [expr {9*1024+391}] 00000002 sqlite3 db test.db catchsql { PRAGMA secure_delete=ON; DROP TABLE t1; }} {1 {database disk image is malformed}}finish_test