// Code generated by modernc.org/undup from the per-target sqlite_*.go files; DO NOT EDIT.

//go:build (freebsd && 386) || (freebsd && arm) || (linux && 386) || (linux && arm) || (windows && 386)

package sqlite3

import (
	"unsafe"

	"modernc.org/libc"
)

const INTPTR_MAX = 2147483647

const INTPTR_MIN = -2147483648

const PTRDIFF_MAX = 2147483647

const PTRDIFF_MIN = -2147483648

const SIZE_MAX = 4294967295

const SQLITE_PTRSIZE = 4

type TBitvec = struct {
	FiSize    Tu32
	FnSet     Tu32
	FiDivisor Tu32
	Fu        struct {
		FaHash   [0][125]Tu32
		FapSub   [0][125]uintptr
		FaBitmap [500]Tu8
	}
}

type TExprList = struct {
	FnExpr  int32
	FnAlloc int32
}

type TFts5TombstoneArray = struct {
	FnRef       int32
	FnTombstone int32
}

type TIdList = struct {
	FnId int32
}

type TIndexIterator = struct {
	FeType int32
	Fi     int32
	Fu     struct {
		Fax [0]struct {
			FnIdx int32
			FaIdx uintptr
		}
		Flx struct {
			FpIdx uintptr
		}
		F__ccgo_pad2 [4]byte
	}
}

type TParse = struct {
	Fdb               uintptr
	FzErrMsg          uintptr
	FpVdbe            uintptr
	Frc               int32
	FnQueryLoop       TLogEst
	Fnested           Tu8
	FnTempReg         Tu8
	FisMultiWrite     Tu8
	FdisableLookaside Tu8
	FprepFlags        Tu8
	FwithinRJSubrtn   Tu8
	FmSubrtnSig       Tu8
	FeTriggerOp       Tu8
	FeOrconf          Tu8
	F__ccgo28         uint16
	FnRangeReg        int32
	FiRangeReg        int32
	FnErr             int32
	FnTab             int32
	FnMem             int32
	FszOpAlloc        int32
	FiSelfTab         int32
	FnLabel           int32
	FnLabelAlloc      int32
	FaLabel           uintptr
	FpConstExpr       uintptr
	FpIdxEpr          uintptr
	FpIdxPartExpr     uintptr
	FwriteMask        TyDbMask
	FcookieMask       TyDbMask
	FnMaxArg          int32
	FnSelect          int32
	FnProgressSteps   Tu32
	FnTableLock       int32
	FaTableLock       uintptr
	FpAinc            uintptr
	FpToplevel        uintptr
	FpTriggerTab      uintptr
	FpTriggerPrg      uintptr
	FpCleanup         uintptr
	FaTempReg         [8]int32
	FpOuterParse      uintptr
	FsNameToken       TToken
	Foldmask          Tu32
	Fnewmask          Tu32
	Fu1               struct {
		Fd [0]struct {
			FpReturning uintptr
		}
		Fcr struct {
			FaddrCrTab      int32
			FregRowid       int32
			FregRoot        int32
			FconstraintName TToken
		}
	}
	FsLastToken   TToken
	FnVar         TynVar
	FiPkSortOrder Tu8
	Fexplain      Tu8
	FeParseMode   Tu8
	FnVtabLock    int32
	FnHeight      int32
	FaddrExplain  int32
	FpVList       uintptr
	FpReprepare   uintptr
	FzTail        uintptr
	FpNewTable    uintptr
	FpNewIndex    uintptr
	FpNewTrigger  uintptr
	FzAuthContext uintptr
	FsArg         TToken
	FapVtabLock   uintptr
	FpWith        uintptr
	FpRename      uintptr
}

type TWalIterator = struct {
	FiPrior   Tu32
	FnSegment int32
}

// C documentation
//
//	/* The next sections is a series of control #defines.
//	** various aspects of the generated parser.
//	**    YYCODETYPE         is the data type used to store the integer codes
//	**                       that represent terminal and non-terminal symbols.
//	**                       "unsigned char" is used if there are fewer than
//	**                       256 symbols.  Larger types otherwise.
//	**    YYNOCODE           is a number of type YYCODETYPE that is not used for
//	**                       any terminal or nonterminal symbol.
//	**    YYFALLBACK         If defined, this indicates that one or more tokens
//	**                       (also known as: "terminal symbols") have fall-back
//	**                       values which should be used if the original symbol
//	**                       would not parse.  This permits keywords to sometimes
//	**                       be used as identifiers, for example.
//	**    YYACTIONTYPE       is the data type used for "action codes" - numbers
//	**                       that indicate what to do in response to the next
//	**                       token.
//	**    sqlite3ParserTOKENTYPE     is the data type used for minor type for terminal
//	**                       symbols.  Background: A "minor type" is a semantic
//	**                       value associated with a terminal or non-terminal
//	**                       symbols.  For example, for an "ID" terminal symbol,
//	**                       the minor type might be the name of the identifier.
//	**                       Each non-terminal can have a different minor type.
//	**                       Terminal symbols all have the same minor type, though.
//	**                       This macros defines the minor type for terminal
//	**                       symbols.
//	**    YYMINORTYPE        is the data type used for all minor types.
//	**                       This is typically a union of many types, one of
//	**                       which is sqlite3ParserTOKENTYPE.  The entry in the union
//	**                       for terminal symbols is called "yy0".
//	**    YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
//	**                       zero the stack is dynamically sized using realloc()
//	**    sqlite3ParserARG_SDECL     A static variable declaration for the %extra_argument
//	**    sqlite3ParserARG_PDECL     A parameter declaration for the %extra_argument
//	**    sqlite3ParserARG_PARAM     Code to pass %extra_argument as a subroutine parameter
//	**    sqlite3ParserARG_STORE     Code to store %extra_argument into yypParser
//	**    sqlite3ParserARG_FETCH     Code to extract %extra_argument from yypParser
//	**    sqlite3ParserCTX_*         As sqlite3ParserARG_ except for %extra_context
//	**    YYREALLOC          Name of the realloc() function to use
//	**    YYFREE             Name of the free() function to use
//	**    YYDYNSTACK         True if stack space should be extended on heap
//	**    YYERRORSYMBOL      is the code number of the error symbol.  If not
//	**                       defined, then do no error processing.
//	**    YYNSTATE           the combined number of states.
//	**    YYNRULE            the number of rules in the grammar
//	**    YYNTOKEN           Number of terminal symbols
//	**    YY_MAX_SHIFT       Maximum value for shift actions
//	**    YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
//	**    YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
//	**    YY_ERROR_ACTION    The yy_action[] code for syntax error
//	**    YY_ACCEPT_ACTION   The yy_action[] code for accept
//	**    YY_NO_ACTION       The yy_action[] code for no-op
//	**    YY_MIN_REDUCE      Minimum value for reduce actions
//	**    YY_MAX_REDUCE      Maximum value for reduce actions
//	**    YY_MIN_DSTRCTR     Minimum symbol value that has a destructor
//	**    YY_MAX_DSTRCTR     Maximum symbol value that has a destructor
//	*/
//	/************* Begin control #defines *****************************************/
type TYYMINORTYPE = struct {
	Fyy0   [0]TToken
	Fyy14  [0]uintptr
	Fyy59  [0]uintptr
	Fyy67  [0]uintptr
	Fyy122 [0]uintptr
	Fyy132 [0]uintptr
	Fyy144 [0]int32
	Fyy168 [0]uintptr
	Fyy203 [0]uintptr
	Fyy211 [0]uintptr
	Fyy269 [0]TOnOrUsing
	Fyy286 [0]TTrigEvent
	Fyy383 [0]struct {
		Fvalue int32
		Fmask  int32
	}
	Fyy391        [0]Tu32
	Fyy427        [0]uintptr
	Fyy454        [0]uintptr
	Fyy462        [0]Tu8
	Fyy509        [0]TFrameBound
	Fyy555        [0]uintptr
	Fyyinit       int32
	F__ccgo_pad20 [4]byte
}

// C documentation
//
//	/* The next sections is a series of control #defines.
//	** various aspects of the generated parser.
//	**    fts5YYCODETYPE         is the data type used to store the integer codes
//	**                       that represent terminal and non-terminal symbols.
//	**                       "unsigned char" is used if there are fewer than
//	**                       256 symbols.  Larger types otherwise.
//	**    fts5YYNOCODE           is a number of type fts5YYCODETYPE that is not used for
//	**                       any terminal or nonterminal symbol.
//	**    fts5YYFALLBACK         If defined, this indicates that one or more tokens
//	**                       (also known as: "terminal symbols") have fall-back
//	**                       values which should be used if the original symbol
//	**                       would not parse.  This permits keywords to sometimes
//	**                       be used as identifiers, for example.
//	**    fts5YYACTIONTYPE       is the data type used for "action codes" - numbers
//	**                       that indicate what to do in response to the next
//	**                       token.
//	**    sqlite3Fts5ParserFTS5TOKENTYPE     is the data type used for minor type for terminal
//	**                       symbols.  Background: A "minor type" is a semantic
//	**                       value associated with a terminal or non-terminal
//	**                       symbols.  For example, for an "ID" terminal symbol,
//	**                       the minor type might be the name of the identifier.
//	**                       Each non-terminal can have a different minor type.
//	**                       Terminal symbols all have the same minor type, though.
//	**                       This macros defines the minor type for terminal
//	**                       symbols.
//	**    fts5YYMINORTYPE        is the data type used for all minor types.
//	**                       This is typically a union of many types, one of
//	**                       which is sqlite3Fts5ParserFTS5TOKENTYPE.  The entry in the union
//	**                       for terminal symbols is called "fts5yy0".
//	**    fts5YYSTACKDEPTH       is the maximum depth of the parser's stack.  If
//	**                       zero the stack is dynamically sized using realloc()
//	**    sqlite3Fts5ParserARG_SDECL     A static variable declaration for the %extra_argument
//	**    sqlite3Fts5ParserARG_PDECL     A parameter declaration for the %extra_argument
//	**    sqlite3Fts5ParserARG_PARAM     Code to pass %extra_argument as a subroutine parameter
//	**    sqlite3Fts5ParserARG_STORE     Code to store %extra_argument into fts5yypParser
//	**    sqlite3Fts5ParserARG_FETCH     Code to extract %extra_argument from fts5yypParser
//	**    sqlite3Fts5ParserCTX_*         As sqlite3Fts5ParserARG_ except for %extra_context
//	**    fts5YYREALLOC          Name of the realloc() function to use
//	**    fts5YYFREE             Name of the free() function to use
//	**    fts5YYDYNSTACK         True if stack space should be extended on heap
//	**    fts5YYERRORSYMBOL      is the code number of the error symbol.  If not
//	**                       defined, then do no error processing.
//	**    fts5YYNSTATE           the combined number of states.
//	**    fts5YYNRULE            the number of rules in the grammar
//	**    fts5YYNFTS5TOKEN           Number of terminal symbols
//	**    fts5YY_MAX_SHIFT       Maximum value for shift actions
//	**    fts5YY_MIN_SHIFTREDUCE Minimum value for shift-reduce actions
//	**    fts5YY_MAX_SHIFTREDUCE Maximum value for shift-reduce actions
//	**    fts5YY_ERROR_ACTION    The fts5yy_action[] code for syntax error
//	**    fts5YY_ACCEPT_ACTION   The fts5yy_action[] code for accept
//	**    fts5YY_NO_ACTION       The fts5yy_action[] code for no-op
//	**    fts5YY_MIN_REDUCE      Minimum value for reduce actions
//	**    fts5YY_MAX_REDUCE      Maximum value for reduce actions
//	**    fts5YY_MIN_DSTRCTR     Minimum symbol value that has a destructor
//	**    fts5YY_MAX_DSTRCTR     Maximum symbol value that has a destructor
//	*/
//	/************* Begin control #defines *****************************************/
type Tfts5YYMINORTYPE = struct {
	Ffts5yy0     [0]TFts5Token
	Ffts5yy4     [0]int32
	Ffts5yy11    [0]uintptr
	Ffts5yy24    [0]uintptr
	Ffts5yy46    [0]uintptr
	Ffts5yy53    [0]uintptr
	Ffts5yyinit  int32
	F__ccgo_pad7 [4]byte
}

type Tintptr_t = int32

type Tp4union = struct {
	Fp          [0]uintptr
	Fz          [0]uintptr
	FpI64       [0]uintptr
	FpReal      [0]uintptr
	FpFunc      [0]uintptr
	FpCtx       [0]uintptr
	FpColl      [0]uintptr
	FpMem       [0]uintptr
	FpVtab      [0]uintptr
	FpKeyInfo   [0]uintptr
	Fai         [0]uintptr
	FpProgram   [0]uintptr
	FpTab       [0]uintptr
	FpSubrtnSig [0]uintptr
	FpIdx       [0]uintptr
	Fi          int32
}

type Tptrdiff_t = int32

type Tsize_t = uint32

// C documentation
//
//	/*
//	** Variables in which to record status information.
//	*/
type Tsqlite3StatValueType = uint32

type Tssize_t = int32

type Tuintptr_t = uint32

// C documentation
//
//	/* The uptr type is an unsigned integer large enough to hold a pointer
//	*/
type Tuptr = uint32

const UINTPTR_MAX = 4294967295

// C documentation
//
//	/*
//	** Register a statically linked extension that is automatically
//	** loaded by every new database connection.
//	*/
func Xsqlite3_auto_extension(tls *libc.TLS, __ccgo_fp_xInit uintptr) (r int32) {
	var aNew, mutex uintptr
	var i Tu32
	var nByte Tu64
	var rc int32
	_, _, _, _, _ = aNew, i, mutex, nByte, rc
	rc = SQLITE_OK
	rc = Xsqlite3_initialize(tls)
	if rc != 0 {
		return rc
	} else {
		mutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_MAIN))
		Xsqlite3_mutex_enter(tls, mutex)
		i = uint32(0)
		for {
			if !(i < _sqlite3Autoext.FnExt) {
				break
			}
			if **(**uintptr)(__ccgo_up(_sqlite3Autoext.FaExt + uintptr(i)*4)) == __ccgo_fp_xInit {
				break
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		if i == _sqlite3Autoext.FnExt {
			nByte = uint64((_sqlite3Autoext.FnExt + uint32(1)) * uint32(4))
			aNew = Xsqlite3_realloc64(tls, _sqlite3Autoext.FaExt, nByte)
			if aNew == uintptr(0) {
				rc = int32(SQLITE_NOMEM)
			} else {
				_sqlite3Autoext.FaExt = aNew
				**(**uintptr)(__ccgo_up(_sqlite3Autoext.FaExt + uintptr(_sqlite3Autoext.FnExt)*4)) = __ccgo_fp_xInit
				_sqlite3Autoext.FnExt = _sqlite3Autoext.FnExt + 1
			}
		}
		Xsqlite3_mutex_leave(tls, mutex)
		return rc
	}
	return r
}

// C documentation
//
//	/*
//	** Release all resources associated with an sqlite3_backup* handle.
//	*/
func Xsqlite3_backup_finish(tls *libc.TLS, p uintptr) (r int32) {
	var pSrcDb, pp uintptr
	var rc, v1 int32
	_, _, _, _ = pSrcDb, pp, rc, v1 /* Value to return */
	/* Enter the mutexes */
	if p == uintptr(0) {
		return SQLITE_OK
	}
	pSrcDb = (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrcDb
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(pSrcDb)).Fmutex)
	_sqlite3BtreeEnter(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)).Fmutex)
	}
	/* Detach this backup from the source pager. */
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		(*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup = (*TBtree)(unsafe.Pointer((*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)).FnBackup - 1
	}
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FisAttached != 0 {
		pp = _sqlite3PagerBackupPtr(tls, _sqlite3BtreePager(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc))
		for **(**uintptr)(__ccgo_up(pp)) != p {
			pp = **(**uintptr)(__ccgo_up(pp)) + 44
		}
		**(**uintptr)(__ccgo_up(pp)) = (*Tsqlite3_backup)(unsafe.Pointer(p)).FpNext
	}
	/* If a transaction is still open on the Btree, roll it back. */
	_sqlite3BtreeRollback(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDest, SQLITE_OK, 0)
	/* Set the error code of the destination database handle. */
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).Frc == int32(SQLITE_DONE) {
		v1 = SQLITE_OK
	} else {
		v1 = (*Tsqlite3_backup)(unsafe.Pointer(p)).Frc
	}
	rc = v1
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		_sqlite3Error(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb, rc)
		/* Exit the mutexes and free the backup context structure. */
		_sqlite3LeaveMutexAndCloseZombie(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb)
	}
	_sqlite3BtreeLeave(tls, (*Tsqlite3_backup)(unsafe.Pointer(p)).FpSrc)
	if (*Tsqlite3_backup)(unsafe.Pointer(p)).FpDestDb != 0 {
		/* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
		 ** call to sqlite3_backup_init() and is destroyed by a call to
		 ** sqlite3_backup_finish(). */
		Xsqlite3_free(tls, p)
	}
	_sqlite3LeaveMutexAndCloseZombie(tls, pSrcDb)
	return rc
}

// C documentation
//
//	/*
//	** Return the N-th compile-time option string.  If N is out of range,
//	** return a NULL pointer.
//	*/
func Xsqlite3_compileoption_get(tls *libc.TLS, N int32) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var azCompileOpt uintptr
	var _ /* nOpt at bp+0 */ int32
	_ = azCompileOpt
	azCompileOpt = _sqlite3CompileOptions(tls, bp)
	if N >= 0 && N < **(**int32)(__ccgo_up(bp)) {
		return **(**uintptr)(__ccgo_up(azCompileOpt + uintptr(N)*4))
	}
	return uintptr(0)
}

/************** End of main.c ************************************************/
/************** Begin file notify.c ******************************************/
/*
** 2009 March 3
**
** 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.
**
*************************************************************************
**
** This file contains the implementation of the sqlite3_unlock_notify()
** API method and its associated functionality.
 */
/* #include "sqliteInt.h" */
/* #include "btreeInt.h" */

/* Omit this entire file if SQLITE_ENABLE_UNLOCK_NOTIFY is not defined. */

/*
** Public interfaces:
**
**   sqlite3ConnectionBlocked()
**   sqlite3ConnectionUnlocked()
**   sqlite3ConnectionClosed()
**   sqlite3_unlock_notify()
 */

// C documentation
//
//	/*
//	** Flush any dirty pages in the pager-cache for any attached database
//	** to disk.
//	*/
func Xsqlite3_db_cacheflush(tls *libc.TLS, db uintptr) (r int32) {
	var bSeenBusy, i, rc, v2 int32
	var pBt, pPager uintptr
	_, _, _, _, _, _ = bSeenBusy, i, pBt, pPager, rc, v2
	rc = SQLITE_OK
	bSeenBusy = 0
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3BtreeEnterAll(tls, db)
	i = 0
	for {
		if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 && _sqlite3BtreeTxnState(tls, pBt) == int32(SQLITE_TXN_WRITE) {
			pPager = _sqlite3BtreePager(tls, pBt)
			rc = _sqlite3PagerFlush(tls, pPager)
			if rc == int32(SQLITE_BUSY) {
				bSeenBusy = int32(1)
				rc = SQLITE_OK
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	_sqlite3BtreeLeaveAll(tls, db)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if rc == SQLITE_OK && bSeenBusy != 0 {
		v2 = int32(SQLITE_BUSY)
	} else {
		v2 = rc
	}
	return v2
}

// C documentation
//
//	/*
//	** Return the name of the N-th database schema.  Return NULL if N is out
//	** of range.
//	*/
func Xsqlite3_db_name(tls *libc.TLS, db uintptr, N int32) (r uintptr) {
	if N < 0 || N >= (*Tsqlite3)(unsafe.Pointer(db)).FnDb {
		return uintptr(0)
	} else {
		return (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(N)*16))).FzDbSName
	}
	return r
}

// C documentation
//
//	/*
//	** Free up as much memory as we can from the given database
//	** connection.
//	*/
func Xsqlite3_db_release_memory(tls *libc.TLS, db uintptr) (r int32) {
	var i int32
	var pBt, pPager uintptr
	_, _, _ = i, pBt, pPager
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	_sqlite3BtreeEnterAll(tls, db)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 {
			pPager = _sqlite3BtreePager(tls, pBt)
			_sqlite3PagerShrink(tls, pPager)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	_sqlite3BtreeLeaveAll(tls, db)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** This routine frees the space the sqlite3_get_table() malloced.
//	*/
func Xsqlite3_free_table(tls *libc.TLS, azResult uintptr) {
	var i, n int32
	_, _ = i, n
	if azResult != 0 {
		azResult -= 4
		n = int32(**(**uintptr)(__ccgo_up(azResult)))
		i = int32(1)
		for {
			if !(i < n) {
				break
			}
			if **(**uintptr)(__ccgo_up(azResult + uintptr(i)*4)) != 0 {
				Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(azResult + uintptr(i)*4)))
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_free(tls, azResult)
	}
}

/************** End of table.c ***********************************************/
/************** Begin file trigger.c *****************************************/
/*
**
** 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.
**
*************************************************************************
** This file contains the implementation for TRIGGERs
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** Find existing client data.
//	*/
func Xsqlite3_get_clientdata(tls *libc.TLS, db uintptr, zName uintptr) (r uintptr) {
	var p, pResult uintptr
	_, _ = p, pResult
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	p = (*Tsqlite3)(unsafe.Pointer(db)).FpDbData
	for {
		if !(p != 0) {
			break
		}
		if libc.Xstrcmp(tls, p+12, zName) == 0 {
			pResult = (*TDbClientData)(unsafe.Pointer(p)).FpData
			Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
			return pResult
		}
		goto _1
	_1:
		;
		p = (*TDbClientData)(unsafe.Pointer(p)).FpNext
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return uintptr(0)
}

func Xsqlite3_result_subtype(tls *libc.TLS, pCtx uintptr, eSubtype uint32) {
	var pOut, v1 uintptr
	_, _ = pOut, v1
	pOut = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpOut
	(*TMem)(unsafe.Pointer(pOut)).FeSubtype = uint8(eSubtype & uint32(0xff))
	v1 = pOut + 16
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(MEM_Subtype))
}

// C documentation
//
//	/*
//	** Register a new geometry function for use with the r-tree MATCH operator.
//	*/
func Xsqlite3_rtree_geometry_callback(tls *libc.TLS, db uintptr, zGeom uintptr, __ccgo_fp_xGeom uintptr, pContext uintptr) (r int32) {
	var pGeomCtx uintptr
	_ = pGeomCtx /* Context object for new user-function */
	/* Allocate and populate the context object. */
	pGeomCtx = Xsqlite3_malloc(tls, int32(16))
	if !(pGeomCtx != 0) {
		return int32(SQLITE_NOMEM)
	}
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxGeom = __ccgo_fp_xGeom
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxQueryFunc = uintptr(0)
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxDestructor = uintptr(0)
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FpContext = pContext
	return Xsqlite3_create_function_v2(tls, db, zGeom, -int32(1), int32(SQLITE_ANY), pGeomCtx, __ccgo_fp(_geomCallback), uintptr(0), uintptr(0), __ccgo_fp(_rtreeFreeCallback))
}

// C documentation
//
//	/*
//	** Register a new 2nd-generation geometry function for use with the
//	** r-tree MATCH operator.
//	*/
func Xsqlite3_rtree_query_callback(tls *libc.TLS, db uintptr, zQueryFunc uintptr, __ccgo_fp_xQueryFunc uintptr, pContext uintptr, __ccgo_fp_xDestructor uintptr) (r int32) {
	var pGeomCtx uintptr
	_ = pGeomCtx /* Context object for new user-function */
	/* Allocate and populate the context object. */
	pGeomCtx = Xsqlite3_malloc(tls, int32(16))
	if !(pGeomCtx != 0) {
		if __ccgo_fp_xDestructor != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xDestructor})))(tls, pContext)
		}
		return int32(SQLITE_NOMEM)
	}
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxGeom = uintptr(0)
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxQueryFunc = __ccgo_fp_xQueryFunc
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FxDestructor = __ccgo_fp_xDestructor
	(*TRtreeGeomCallback)(unsafe.Pointer(pGeomCtx)).FpContext = pContext
	return Xsqlite3_create_function_v2(tls, db, zQueryFunc, -int32(1), int32(SQLITE_ANY), pGeomCtx, __ccgo_fp(_geomCallback), uintptr(0), uintptr(0), __ccgo_fp(_rtreeFreeCallback))
}

/************** End of rtree.c ***********************************************/
/************** Begin file icu.c *********************************************/
/*
** 2007 May 6
**
** 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.
**
*************************************************************************
** $Id: icu.c,v 1.7 2007/12/13 21:54:11 drh Exp $
**
** This file implements an integration between the ICU library
** ("International Components for Unicode", an open-source library
** for handling unicode data) and SQLite. The integration uses
** ICU to provide the following to SQLite:
**
**   * An implementation of the SQL regexp() function (and hence REGEXP
**     operator) using the ICU uregex_XX() APIs.
**
**   * Implementations of the SQL scalar upper() and lower() functions
**     for case mapping.
**
**   * Integration of ICU and SQLite collation sequences.
**
**   * An implementation of the LIKE operator that uses ICU to
**     provide case-independent matching.
 */

/************** End of icu.c *************************************************/
/************** Begin file fts3_icu.c ****************************************/
/*
** 2007 June 22
**
** 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.
**
*************************************************************************
** This file implements a tokenizer for fts3 based on the ICU library.
 */
/* #include "fts3Int.h" */

/************** End of fts3_icu.c ********************************************/
/************** Begin file sqlite3rbu.c **************************************/
/*
** 2014 August 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.
**
*************************************************************************
**
**
** OVERVIEW
**
**  The RBU extension requires that the RBU update be packaged as an
**  SQLite database. The tables it expects to find are described in
**  sqlite3rbu.h.  Essentially, for each table xyz in the target database
**  that the user wishes to write to, a corresponding data_xyz table is
**  created in the RBU database and populated with one row for each row to
**  update, insert or delete from the target table.
**
**  The update proceeds in three stages:
**
**  1) The database is updated. The modified database pages are written
**     to a *-oal file. A *-oal file is just like a *-wal file, except
**     that it is named "<database>-oal" instead of "<database>-wal".
**     Because regular SQLite clients do not look for file named
**     "<database>-oal", they go on using the original database in
**     rollback mode while the *-oal file is being generated.
**
**     During this stage RBU does not update the database by writing
**     directly to the target tables. Instead it creates "imposter"
**     tables using the SQLITE_TESTCTRL_IMPOSTER interface that it uses
**     to update each b-tree individually. All updates required by each
**     b-tree are completed before moving on to the next, and all
**     updates are done in sorted key order.
**
**  2) The "<database>-oal" file is moved to the equivalent "<database>-wal"
**     location using a call to rename(2). Before doing this the RBU
**     module takes an EXCLUSIVE lock on the database file, ensuring
**     that there are no other active readers.
**
**     Once the EXCLUSIVE lock is released, any other database readers
**     detect the new *-wal file and read the database in wal mode. At
**     this point they see the new version of the database - including
**     the updates made as part of the RBU update.
**
**  3) The new *-wal file is checkpointed. This proceeds in the same way
**     as a regular database checkpoint, except that a single frame is
**     checkpointed each time sqlite3rbu_step() is called. If the RBU
**     handle is closed before the entire *-wal file is checkpointed,
**     the checkpoint progress is saved in the RBU database and the
**     checkpoint can be resumed by another RBU client at some point in
**     the future.
**
** POTENTIAL PROBLEMS
**
**  The rename() call might not be portable. And RBU is not currently
**  syncing the directory after renaming the file.
**
**  When state is saved, any commit to the *-oal file and the commit to
**  the RBU update database are not atomic. So if the power fails at the
**  wrong moment they might get out of sync. As the main database will be
**  committed before the RBU update database this will likely either just
**  pass unnoticed, or result in SQLITE_CONSTRAINT errors (due to UNIQUE
**  constraint violations).
**
**  If some client does modify the target database mid RBU update, or some
**  other error occurs, the RBU extension will keep throwing errors. It's
**  not really clear how to get out of this state. The system could just
**  by delete the RBU update database and *-oal file and have the device
**  download the update again and start over.
**
**  At present, for an UPDATE, both the new.* and old.* records are
**  collected in the rbu_xyz table. And for both UPDATEs and DELETEs all
**  fields are collected.  This means we're probably writing a lot more
**  data to disk when saving the state of an ongoing update to the RBU
**  update database than is strictly necessary.
**
 */

/* #include <assert.h> */
/* #include <string.h> */
/* #include <stdio.h> */

/* #include "sqlite3.h" */

/************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
/************** Begin file sqlite3rbu.h **************************************/
/*
** 2014 August 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.
**
*************************************************************************
**
** This file contains the public interface for the RBU extension.
 */

/*
** SUMMARY
**
** Writing a transaction containing a large number of operations on
** b-tree indexes that are collectively larger than the available cache
** memory can be very inefficient.
**
** The problem is that in order to update a b-tree, the leaf page (at least)
** containing the entry being inserted or deleted must be modified. If the
** working set of leaves is larger than the available cache memory, then a
** single leaf that is modified more than once as part of the transaction
** may be loaded from or written to the persistent media multiple times.
** Additionally, because the index updates are likely to be applied in
** random order, access to pages within the database is also likely to be in
** random order, which is itself quite inefficient.
**
** One way to improve the situation is to sort the operations on each index
** by index key before applying them to the b-tree. This leads to an IO
** pattern that resembles a single linear scan through the index b-tree,
** and all but guarantees each modified leaf page is loaded and stored
** exactly once. SQLite uses this trick to improve the performance of
** CREATE INDEX commands. This extension allows it to be used to improve
** the performance of large transactions on existing databases.
**
** Additionally, this extension allows the work involved in writing the
** large transaction to be broken down into sub-transactions performed
** sequentially by separate processes. This is useful if the system cannot
** guarantee that a single update process will run for long enough to apply
** the entire update, for example because the update is being applied on a
** mobile device that is frequently rebooted. Even after the writer process
** has committed one or more sub-transactions, other database clients continue
** to read from the original database snapshot. In other words, partially
** applied transactions are not visible to other clients.
**
** "RBU" stands for "Resumable Bulk Update". As in a large database update
** transmitted via a wireless network to a mobile device. A transaction
** applied using this extension is hence referred to as an "RBU update".
**
**
** LIMITATIONS
**
** An "RBU update" transaction is subject to the following limitations:
**
**   * The transaction must consist of INSERT, UPDATE and DELETE operations
**     only.
**
**   * INSERT statements may not use any default values.
**
**   * UPDATE and DELETE statements must identify their target rows by
**     non-NULL PRIMARY KEY values. Rows with NULL values stored in PRIMARY
**     KEY fields may not be updated or deleted. If the table being written
**     has no PRIMARY KEY, affected rows must be identified by rowid.
**
**   * UPDATE statements may not modify PRIMARY KEY columns.
**
**   * No triggers will be fired.
**
**   * No foreign key violations are detected or reported.
**
**   * CHECK constraints are not enforced.
**
**   * No constraint handling mode except for "OR ROLLBACK" is supported.
**
**
** PREPARATION
**
** An "RBU update" is stored as a separate SQLite database. A database
** containing an RBU update is an "RBU database". For each table in the
** target database to be updated, the RBU database should contain a table
** named "data_<target name>" containing the same set of columns as the
** target table, and one more - "rbu_control". The data_% table should
** have no PRIMARY KEY or UNIQUE constraints, but each column should have
** the same type as the corresponding column in the target database.
** The "rbu_control" column should have no type at all. For example, if
** the target database contains:
**
**   CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c UNIQUE);
**
** Then the RBU database should contain:
**
**   CREATE TABLE data_t1(a INTEGER, b TEXT, c, rbu_control);
**
** The order of the columns in the data_% table does not matter.
**
** Instead of a regular table, the RBU database may also contain virtual
** tables or views named using the data_<target> naming scheme.
**
** Instead of the plain data_<target> naming scheme, RBU database tables
** may also be named data<integer>_<target>, where <integer> is any sequence
** of zero or more numeric characters (0-9). This can be significant because
** tables within the RBU database are always processed in order sorted by
** name. By judicious selection of the <integer> portion of the names
** of the RBU tables the user can therefore control the order in which they
** are processed. This can be useful, for example, to ensure that "external
** content" FTS4 tables are updated before their underlying content tables.
**
** If the target database table is a virtual table or a table that has no
** PRIMARY KEY declaration, the data_% table must also contain a column
** named "rbu_rowid". This column is mapped to the table's implicit primary
** key column - "rowid". Virtual tables for which the "rowid" column does
** not function like a primary key value cannot be updated using RBU. For
** example, if the target db contains either of the following:
**
**   CREATE VIRTUAL TABLE x1 USING fts3(a, b);
**   CREATE TABLE x1(a, b)
**
** then the RBU database should contain:
**
**   CREATE TABLE data_x1(a, b, rbu_rowid, rbu_control);
**
** All non-hidden columns (i.e. all columns matched by "SELECT *") of the
** target table must be present in the input table. For virtual tables,
** hidden columns are optional - they are updated by RBU if present in
** the input table, or not otherwise. For example, to write to an fts4
** table with a hidden languageid column such as:
**
**   CREATE VIRTUAL TABLE ft1 USING fts4(a, b, languageid='langid');
**
** Either of the following input table schemas may be used:
**
**   CREATE TABLE data_ft1(a, b, langid, rbu_rowid, rbu_control);
**   CREATE TABLE data_ft1(a, b, rbu_rowid, rbu_control);
**
** For each row to INSERT into the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain integer value 0. The
** other columns should be set to the values that make up the new record
** to insert.
**
** If the target database table has an INTEGER PRIMARY KEY, it is not
** possible to insert a NULL value into the IPK column. Attempting to
** do so results in an SQLITE_MISMATCH error.
**
** For each row to DELETE from the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain integer value 1. The
** real primary key values of the row to delete should be stored in the
** corresponding columns of the data_% table. The values stored in the
** other columns are not used.
**
** For each row to UPDATE from the target database as part of the RBU
** update, the corresponding data_% table should contain a single record
** with the "rbu_control" column set to contain a value of type text.
** The real primary key values identifying the row to update should be
** stored in the corresponding columns of the data_% table row, as should
** the new values of all columns being update. The text value in the
** "rbu_control" column must contain the same number of characters as
** there are columns in the target database table, and must consist entirely
** of 'x' and '.' characters (or in some special cases 'd' - see below). For
** each column that is being updated, the corresponding character is set to
** 'x'. For those that remain as they are, the corresponding character of the
** rbu_control value should be set to '.'. For example, given the tables
** above, the update statement:
**
**   UPDATE t1 SET c = 'usa' WHERE a = 4;
**
** is represented by the data_t1 row created by:
**
**   INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..x');
**
** Instead of an 'x' character, characters of the rbu_control value specified
** for UPDATEs may also be set to 'd'. In this case, instead of updating the
** target table with the value stored in the corresponding data_% column, the
** user-defined SQL function "rbu_delta()" is invoked and the result stored in
** the target table column. rbu_delta() is invoked with two arguments - the
** original value currently stored in the target table column and the
** value specified in the data_xxx table.
**
** For example, this row:
**
**   INSERT INTO data_t1(a, b, c, rbu_control) VALUES(4, NULL, 'usa', '..d');
**
** is similar to an UPDATE statement such as:
**
**   UPDATE t1 SET c = rbu_delta(c, 'usa') WHERE a = 4;
**
** Finally, if an 'f' character appears in place of a 'd' or 's' in an
** ota_control string, the contents of the data_xxx table column is assumed
** to be a "fossil delta" - a patch to be applied to a blob value in the
** format used by the fossil source-code management system. In this case
** the existing value within the target database table must be of type BLOB.
** It is replaced by the result of applying the specified fossil delta to
** itself.
**
** If the target database table is a virtual table or a table with no PRIMARY
** KEY, the rbu_control value should not include a character corresponding
** to the rbu_rowid value. For example, this:
**
**   INSERT INTO data_ft1(a, b, rbu_rowid, rbu_control)
**       VALUES(NULL, 'usa', 12, '.x');
**
** causes a result similar to:
**
**   UPDATE ft1 SET b = 'usa' WHERE rowid = 12;
**
** The data_xxx tables themselves should have no PRIMARY KEY declarations.
** However, RBU is more efficient if reading the rows in from each data_xxx
** table in "rowid" order is roughly the same as reading them sorted by
** the PRIMARY KEY of the corresponding target database table. In other
** words, rows should be sorted using the destination table PRIMARY KEY
** fields before they are inserted into the data_xxx tables.
**
** USAGE
**
** The API declared below allows an application to apply an RBU update
** stored on disk to an existing target database. Essentially, the
** application:
**
**     1) Opens an RBU handle using the sqlite3rbu_open() function.
**
**     2) Registers any required virtual table modules with the database
**        handle returned by sqlite3rbu_db(). Also, if required, register
**        the rbu_delta() implementation.
**
**     3) Calls the sqlite3rbu_step() function one or more times on
**        the new handle. Each call to sqlite3rbu_step() performs a single
**        b-tree operation, so thousands of calls may be required to apply
**        a complete update.
**
**     4) Calls sqlite3rbu_close() to close the RBU update handle. If
**        sqlite3rbu_step() has been called enough times to completely
**        apply the update to the target database, then the RBU database
**        is marked as fully applied. Otherwise, the state of the RBU
**        update application is saved in the RBU database for later
**        resumption.
**
** See comments below for more detail on APIs.
**
** If an update is only partially applied to the target database by the
** time sqlite3rbu_close() is called, various state information is saved
** within the RBU database. This allows subsequent processes to automatically
** resume the RBU update from where it left off.
**
** To remove all RBU extension state information, returning an RBU database
** to its original contents, it is sufficient to drop all tables that begin
** with the prefix "rbu_"
**
** DATABASE LOCKING
**
** An RBU update may not be applied to a database in WAL mode. Attempting
** to do so is an error (SQLITE_ERROR).
**
** While an RBU handle is open, a SHARED lock may be held on the target
** database file. This means it is possible for other clients to read the
** database, but not to write it.
**
** If an RBU update is started and then suspended before it is completed,
** then an external client writes to the database, then attempting to resume
** the suspended RBU update is also an error (SQLITE_BUSY).
 */

/* #include "sqlite3.h"              ** Required for error code definitions ** */

// C documentation
//
//	/*
//	** Set the auxiliary data pointer and delete function, for the iArg'th
//	** argument to the user-function defined by pCtx. Any previous value is
//	** deleted by calling the delete function specified when it was set.
//	**
//	** The left-most argument is 0.
//	**
//	** Undocumented behavior:  If iArg is negative then make the data available
//	** to all functions within the current prepared statement using iArg as an
//	** access code.
//	*/
func Xsqlite3_set_auxdata(tls *libc.TLS, pCtx uintptr, iArg int32, pAux uintptr, __ccgo_fp_xDelete uintptr) {
	var pAuxData, pVdbe uintptr
	_, _ = pAuxData, pVdbe
	pVdbe = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FpVdbe
	if pVdbe == uintptr(0) {
		goto failed
	}
	pAuxData = (*TVdbe)(unsafe.Pointer(pVdbe)).FpAuxData
	for {
		if !(pAuxData != 0) {
			break
		}
		if (*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxArg == iArg && ((*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxOp == (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp || iArg < 0) {
			break
		}
		goto _1
	_1:
		;
		pAuxData = (*TAuxData)(unsafe.Pointer(pAuxData)).FpNextAux
	}
	if pAuxData == uintptr(0) {
		pAuxData = _sqlite3DbMallocZero(tls, (*TVdbe)(unsafe.Pointer(pVdbe)).Fdb, uint64(20))
		if !(pAuxData != 0) {
			goto failed
		}
		(*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxOp = (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FiOp
		(*TAuxData)(unsafe.Pointer(pAuxData)).FiAuxArg = iArg
		(*TAuxData)(unsafe.Pointer(pAuxData)).FpNextAux = (*TVdbe)(unsafe.Pointer(pVdbe)).FpAuxData
		(*TVdbe)(unsafe.Pointer(pVdbe)).FpAuxData = pAuxData
		if (*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError == 0 {
			(*Tsqlite3_context)(unsafe.Pointer(pCtx)).FisError = -int32(1)
		}
	} else {
		if (*TAuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TAuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux})))(tls, (*TAuxData)(unsafe.Pointer(pAuxData)).FpAux)
		}
	}
	(*TAuxData)(unsafe.Pointer(pAuxData)).FpAux = pAux
	(*TAuxData)(unsafe.Pointer(pAuxData)).FxDeleteAux = __ccgo_fp_xDelete
	return
	goto failed
failed:
	;
	if __ccgo_fp_xDelete != 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xDelete})))(tls, pAux)
	}
}

// C documentation
//
//	/*
//	** Undo the effects of sqlite3_initialize().  Must not be called while
//	** there are outstanding database connections or memory allocations or
//	** while any part of SQLite is otherwise in use in any thread.  This
//	** routine is not threadsafe.  But it is safe to invoke this routine
//	** on when SQLite is already shut down.  If SQLite is already shut down
//	** when this routine is invoked, then this routine is a harmless no-op.
//	*/
func Xsqlite3_shutdown(tls *libc.TLS) (r int32) {
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208) != 0 {
		Xsqlite3_os_end(tls)
		Xsqlite3_reset_auto_extension(tls)
		libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_sqlite3Config))+208, 0)
	}
	if _sqlite3Config.FisPCacheInit != 0 {
		_sqlite3PcacheShutdown(tls)
		_sqlite3Config.FisPCacheInit = 0
	}
	if _sqlite3Config.FisMallocInit != 0 {
		_sqlite3MallocEnd(tls)
		_sqlite3Config.FisMallocInit = 0
		/* The heap subsystem has now been shutdown and these values are supposed
		 ** to be NULL or point to memory that was obtained from sqlite3_malloc(),
		 ** which would rely on that heap subsystem; therefore, make sure these
		 ** values cannot refer to heap memory that was just invalidated when the
		 ** heap subsystem was shutdown.  This is only done if the current call to
		 ** this function resulted in the heap subsystem actually being shutdown.
		 */
		Xsqlite3_data_directory = uintptr(0)
		Xsqlite3_temp_directory = uintptr(0)
	}
	if _sqlite3Config.FisMutexInit != 0 {
		_sqlite3MutexEnd(tls)
		_sqlite3Config.FisMutexInit = 0
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Recover as many snapshots as possible from the wal file associated with
//	** schema zDb of database db.
//	*/
func Xsqlite3_snapshot_recover(tls *libc.TLS, db uintptr, zDb uintptr) (r int32) {
	var iDb, rc int32
	var pBt uintptr
	_, _, _ = iDb, pBt, rc
	rc = int32(SQLITE_ERROR)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	iDb = _sqlite3FindDbName(tls, db, zDb)
	if iDb == 0 || iDb > int32(1) {
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
		if SQLITE_TXN_NONE == _sqlite3BtreeTxnState(tls, pBt) {
			rc = _sqlite3BtreeBeginTrans(tls, pBt, 0, uintptr(0))
			if rc == SQLITE_OK {
				rc = _sqlite3PagerSnapshotRecover(tls, _sqlite3BtreePager(tls, pBt))
				_sqlite3BtreeCommit(tls, pBt)
			}
		}
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Return the transaction state for a single databse, or the maximum
//	** transaction state over all attached databases if zSchema is null.
//	*/
func Xsqlite3_txn_state(tls *libc.TLS, db uintptr, zSchema uintptr) (r int32) {
	var iDb, iTxn, nDb, x, v1 int32
	var pBt uintptr
	_, _, _, _, _, _ = iDb, iTxn, nDb, pBt, x, v1
	iTxn = -int32(1)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if zSchema != 0 {
		v1 = _sqlite3FindDbName(tls, db, zSchema)
		iDb = v1
		nDb = v1
		if iDb < 0 {
			nDb = nDb - 1
		}
	} else {
		iDb = 0
		nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb - int32(1)
	}
	for {
		if !(iDb <= nDb) {
			break
		}
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
		if pBt != uintptr(0) {
			v1 = _sqlite3BtreeTxnState(tls, pBt)
		} else {
			v1 = SQLITE_TXN_NONE
		}
		x = v1
		if x > iTxn {
			iTxn = x
		}
		goto _2
	_2:
		;
		iDb = iDb + 1
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return iTxn
}

// C documentation
//
//	/*
//	** Configure an sqlite3_wal_hook() callback to automatically checkpoint
//	** a database after committing a transaction if there are nFrame or
//	** more frames in the log file. Passing zero or a negative value as the
//	** nFrame parameter disables automatic checkpoints entirely.
//	**
//	** The callback registered by this function replaces any existing callback
//	** registered using sqlite3_wal_hook(). Likewise, registering a callback
//	** using sqlite3_wal_hook() disables the automatic checkpoint mechanism
//	** configured by this function.
//	*/
func Xsqlite3_wal_autocheckpoint(tls *libc.TLS, db uintptr, nFrame int32) (r int32) {
	if nFrame > 0 {
		Xsqlite3_wal_hook(tls, db, __ccgo_fp(_sqlite3WalDefaultHook), uintptr(nFrame))
	} else {
		Xsqlite3_wal_hook(tls, db, uintptr(0), uintptr(0))
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Delete a changegroup object.
//	*/
func Xsqlite3changegroup_delete(tls *libc.TLS, pGrp uintptr) {
	var ii int32
	_ = ii
	if pGrp != 0 {
		ii = 0
		for {
			if !(ii < (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FnBufAlloc) {
				break
			}
			Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf + uintptr(ii)*12))).FaBuf)
			goto _1
		_1:
			;
			ii = ii + 1
		}
		Xsqlite3_free(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.Frecord.FaBuf)
		Xsqlite3_free(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf)
		Xsqlite3_free(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FzDb)
		_sessionDeleteTable(tls, uintptr(0), (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList)
		Xsqlite3_free(tls, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Frec.FaBuf)
		Xsqlite3_free(tls, pGrp)
	}
}

// C documentation
//
//	/*
//	** Allocate a new, empty, sqlite3_changegroup.
//	*/
func Xsqlite3changegroup_new(tls *libc.TLS, pp uintptr) (r int32) {
	var p uintptr
	var rc int32
	_, _ = p, rc
	rc = SQLITE_OK /* New object */
	p = Xsqlite3_malloc(tls, int32(64))
	if p == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, p, 0, uint32(64))
	}
	**(**uintptr)(__ccgo_up(pp)) = p
	return rc
}

// C documentation
//
//	/*
//	** Finalize an iterator allocated with sqlite3changeset_start().
//	**
//	** This function may not be called on iterators passed to a conflict handler
//	** callback by changeset_apply().
//	*/
func Xsqlite3changeset_finalize(tls *libc.TLS, p uintptr) (r int32) {
	var i, rc int32
	_, _ = i, rc
	rc = SQLITE_OK
	if p != 0 { /* Used to iterate through p->apValue[] */
		rc = (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Frc
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue != 0 {
			i = 0
			for {
				if !(i < (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FnCol*int32(2)) {
					break
				}
				_sqlite3ValueFree(tls, **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).FapValue + uintptr(i)*4)))
				goto _1
			_1:
				;
				i = i + 1
			}
		}
		Xsqlite3_free(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Ftblhdr.FaBuf)
		Xsqlite3_free(tls, (*Tsqlite3_changeset_iter)(unsafe.Pointer(p)).Fin.Fbuf.FaBuf)
		Xsqlite3_free(tls, p)
	}
	return rc
}

// C documentation
//
//	/*
//	** Invert a changeset object.
//	*/
func Xsqlite3changeset_invert(tls *libc.TLS, nChangeset int32, pChangeset uintptr, pnInverted uintptr, ppInverted uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* sInput at bp+0 */ TSessionInput
	/* Set up the input stream */
	libc.Xmemset(tls, bp, 0, uint32(44))
	(**(**TSessionInput)(__ccgo_up(bp))).FnData = nChangeset
	(**(**TSessionInput)(__ccgo_up(bp))).FaData = pChangeset
	return _sessionChangesetInvert(tls, bp, uintptr(0), uintptr(0), pnInverted, ppInverted)
}

// C documentation
//
//	/*
//	** Streaming version of sqlite3changeset_invert().
//	*/
func Xsqlite3changeset_invert_strm(tls *libc.TLS, __ccgo_fp_xInput uintptr, pIn uintptr, __ccgo_fp_xOutput uintptr, pOut uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var rc int32
	var _ /* sInput at bp+0 */ TSessionInput
	_ = rc
	/* Set up the input stream */
	libc.Xmemset(tls, bp, 0, uint32(44))
	(**(**TSessionInput)(__ccgo_up(bp))).FxInput = __ccgo_fp_xInput
	(**(**TSessionInput)(__ccgo_up(bp))).FpIn = pIn
	rc = _sessionChangesetInvert(tls, bp, __ccgo_fp_xOutput, pOut, uintptr(0), uintptr(0))
	Xsqlite3_free(tls, (**(**TSessionInput)(__ccgo_up(bp))).Fbuf.FaBuf)
	return rc
}

// C documentation
//
//	/*
//	** This function may only be called while the iterator is pointing to an
//	** SQLITE_UPDATE or SQLITE_INSERT change (see sqlite3changeset_op()).
//	** Otherwise, SQLITE_MISUSE is returned.
//	**
//	** It sets *ppValue to point to an sqlite3_value structure containing the
//	** iVal'th value in the new.* record. Or, if that particular value is not
//	** included in the record (because the change is an UPDATE and the field
//	** was not modified), set *ppValue to NULL.
//	**
//	** If value iVal is out-of-range, SQLITE_RANGE is returned and *ppValue is
//	** not modified. Otherwise, SQLITE_OK.
//	*/
func Xsqlite3changeset_new(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) (r int32) {
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_UPDATE) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_INSERT) {
		return int32(SQLITE_MISUSE)
	}
	if iVal < 0 || iVal >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return int32(SQLITE_RANGE)
	}
	**(**uintptr)(__ccgo_up(ppValue)) = **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+iVal)*4))
	return SQLITE_OK
}

/*
** The following two macros are used internally. They are similar to the
** sqlite3changeset_new() and sqlite3changeset_old() functions, except that
** they omit all error checking and return a pointer to the requested value.
 */

// C documentation
//
//	/*
//	** This function may only be called while the iterator is pointing to an
//	** SQLITE_UPDATE or SQLITE_DELETE change (see sqlite3changeset_op()).
//	** Otherwise, SQLITE_MISUSE is returned.
//	**
//	** It sets *ppValue to point to an sqlite3_value structure containing the
//	** iVal'th value in the old.* record. Or, if that particular value is not
//	** included in the record (because the change is an UPDATE and the field
//	** was not modified and is not a PK column), set *ppValue to NULL.
//	**
//	** If value iVal is out-of-range, SQLITE_RANGE is returned and *ppValue is
//	** not modified. Otherwise, SQLITE_OK.
//	*/
func Xsqlite3changeset_old(tls *libc.TLS, pIter uintptr, iVal int32, ppValue uintptr) (r int32) {
	if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_UPDATE) && (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fop != int32(SQLITE_DELETE) {
		return int32(SQLITE_MISUSE)
	}
	if iVal < 0 || iVal >= (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol {
		return int32(SQLITE_RANGE)
	}
	**(**uintptr)(__ccgo_up(ppValue)) = **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(iVal)*4))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Create a new rebaser object.
//	*/
func Xsqlite3rebaser_create(tls *libc.TLS, ppNew uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	rc = SQLITE_OK
	pNew = Xsqlite3_malloc(tls, int32(64))
	if pNew == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, pNew, 0, uint32(64))
	}
	**(**uintptr)(__ccgo_up(ppNew)) = pNew
	return rc
}

// C documentation
//
//	/*
//	** Delete a session object previously allocated using sqlite3session_create().
//	*/
func Xsqlite3session_delete(tls *libc.TLS, pSession uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var db, pp uintptr
	var _ /* pHead at bp+0 */ uintptr
	_, _ = db, pp
	db = (*Tsqlite3_session)(unsafe.Pointer(pSession)).Fdb
	/* Unlink the session from the linked list of sessions attached to the
	 ** database handle. Hold the db mutex while doing so.  */
	Xsqlite3_mutex_enter(tls, Xsqlite3_db_mutex(tls, db))
	**(**uintptr)(__ccgo_up(bp)) = Xsqlite3_preupdate_hook(tls, db, uintptr(0), uintptr(0))
	pp = bp
	for {
		if !(**(**uintptr)(__ccgo_up(pp)) != uintptr(0)) {
			break
		}
		if **(**uintptr)(__ccgo_up(pp)) == pSession {
			**(**uintptr)(__ccgo_up(pp)) = (*Tsqlite3_session)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FpNext
			if **(**uintptr)(__ccgo_up(bp)) != 0 {
				Xsqlite3_preupdate_hook(tls, db, __ccgo_fp(_xPreUpdate), **(**uintptr)(__ccgo_up(bp)))
			}
			break
		}
		goto _1
	_1:
		;
		pp = **(**uintptr)(__ccgo_up(pp)) + 60
	}
	Xsqlite3_mutex_leave(tls, Xsqlite3_db_mutex(tls, db))
	_sqlite3ValueFree(tls, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpZeroBlob)
	/* Delete all attached table objects. And the contents of their
	 ** associated hash-tables. */
	_sessionDeleteTable(tls, pSession, (*Tsqlite3_session)(unsafe.Pointer(pSession)).FpTable)
	/* Free the session object. */
	Xsqlite3_free(tls, pSession)
}

// C documentation
//
//	/*
//	** This function implements the ChooseLeaf algorithm from Gutman[84].
//	** ChooseSubTree in r*tree terminology.
//	*/
func _ChooseLeaf(tls *libc.TLS, pRtree uintptr, pCell uintptr, iHeight int32, ppLeaf uintptr) (r int32) {
	bp := tls.Alloc(112)
	defer tls.Free(112)
	var area, area1, fMinArea, fMinGrowth, growth TRtreeDValue
	var bFound, iCell, ii, nCell, rc int32
	var iBest Tsqlite3_int64
	var _ /* cell at bp+56 */ TRtreeCell
	var _ /* cell at bp+8 */ TRtreeCell
	var _ /* pChild at bp+4 */ uintptr
	var _ /* pNode at bp+0 */ uintptr
	_, _, _, _, _, _, _, _, _, _, _ = area, area1, bFound, fMinArea, fMinGrowth, growth, iBest, iCell, ii, nCell, rc
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	rc = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp)
	ii = 0
	for {
		if !(rc == SQLITE_OK && ii < (*TRtree)(unsafe.Pointer(pRtree)).FiDepth-iHeight) {
			break
		}
		iBest = 0
		bFound = 0
		fMinGrowth = float64(0)
		fMinArea = float64(0)
		nCell = _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FzData+2)
		**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0)
		/* First check to see if there is are any cells in pNode that completely
		 ** contains pCell.  If two or more cells in pNode completely contain pCell
		 ** then pick the smallest.
		 */
		iCell = 0
		for {
			if !(iCell < nCell) {
				break
			}
			_nodeGetCell(tls, pRtree, **(**uintptr)(__ccgo_up(bp)), iCell, bp+8)
			if _cellContains(tls, pRtree, bp+8, pCell) != 0 {
				area = _cellArea(tls, pRtree, bp+8)
				if bFound == 0 || area < fMinArea {
					iBest = (**(**TRtreeCell)(__ccgo_up(bp + 8))).FiRowid
					fMinArea = area
					bFound = int32(1)
				}
			}
			goto _2
		_2:
			;
			iCell = iCell + 1
		}
		if !(bFound != 0) {
			/* No cells of pNode will completely contain pCell.  So pick the
			 ** cell of pNode that grows by the least amount when pCell is added.
			 ** Break ties by selecting the smaller cell.
			 */
			iCell = 0
			for {
				if !(iCell < nCell) {
					break
				}
				_nodeGetCell(tls, pRtree, **(**uintptr)(__ccgo_up(bp)), iCell, bp+56)
				area1 = _cellArea(tls, pRtree, bp+56)
				_cellUnion(tls, pRtree, bp+56, pCell)
				growth = _cellArea(tls, pRtree, bp+56) - area1
				if iCell == 0 || growth < fMinGrowth || growth == fMinGrowth && area1 < fMinArea {
					fMinGrowth = growth
					fMinArea = area1
					iBest = (**(**TRtreeCell)(__ccgo_up(bp + 56))).FiRowid
				}
				goto _3
			_3:
				;
				iCell = iCell + 1
			}
		}
		rc = _nodeAcquire(tls, pRtree, iBest, **(**uintptr)(__ccgo_up(bp)), bp+4)
		_nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp)))
		**(**uintptr)(__ccgo_up(bp)) = **(**uintptr)(__ccgo_up(bp + 4))
		goto _1
	_1:
		;
		ii = ii + 1
	}
	**(**uintptr)(__ccgo_up(ppLeaf)) = **(**uintptr)(__ccgo_up(bp))
	return rc
}

const __INTPTR_MAX__ = 2147483647

const __INTPTR_TYPE__ = 0

const __INTPTR_WIDTH__ = 32

const __PTRDIFF_MAX__ = 2147483647

const __PTRDIFF_TYPE__ = 0

const __PTRDIFF_WIDTH__ = 32

const __SIZEOF_POINTER__ = 4

const __SIZEOF_PTRDIFF_T__ = 4

const __SIZEOF_SIZE_T__ = 4

const __SIZE_MAX__ = 4294967295

const __SIZE_WIDTH__ = 32

const __UINTPTR_MAX__ = 4294967295

// C documentation
//
//	/*
//	** Add a new element to the pAggInfo->aCol[] array.  Return the index of
//	** the new element.  Return a negative number if malloc fails.
//	*/
func _addAggInfoColumn(tls *libc.TLS, db uintptr, pInfo uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* i at bp+0 */ int32
	(*TAggInfo)(unsafe.Pointer(pInfo)).FaCol = _sqlite3ArrayAllocate(tls, db, (*TAggInfo)(unsafe.Pointer(pInfo)).FaCol, int32(20), pInfo+28, bp)
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Add a new element to the pAggInfo->aFunc[] array.  Return the index of
//	** the new element.  Return a negative number if malloc fails.
//	*/
func _addAggInfoFunc(tls *libc.TLS, db uintptr, pInfo uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* i at bp+0 */ int32
	(*TAggInfo)(unsafe.Pointer(pInfo)).FaFunc = _sqlite3ArrayAllocate(tls, db, (*TAggInfo)(unsafe.Pointer(pInfo)).FaFunc, int32(24), pInfo+40, bp)
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Set the bit number pgno in the PagerSavepoint.pInSavepoint
//	** bitvecs of all open savepoints. Return SQLITE_OK if successful
//	** or SQLITE_NOMEM if a malloc failure occurs.
//	*/
func _addToSavepointBitvecs(tls *libc.TLS, pPager uintptr, pgno TPgno) (r int32) {
	var ii, rc int32
	var p uintptr
	_, _, _ = ii, p, rc /* Loop counter */
	rc = SQLITE_OK      /* Result code */
	ii = 0
	for {
		if !(ii < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
			break
		}
		p = (*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*48
		if pgno <= (*TPagerSavepoint)(unsafe.Pointer(p)).FnOrig {
			rc = rc | _sqlite3BitvecSet(tls, (*TPagerSavepoint)(unsafe.Pointer(p)).FpInSavepoint, pgno)
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	return rc
}

// C documentation
//
//	/*
//	** Convert every pAggInfo->aFunc[].pExpr such that any node within
//	** those expressions that has pAppInfo set is changed into a TK_AGG_COLUMN
//	** opcode.
//	*/
func _aggregateConvertIndexedExprRefToColumn(tls *libc.TLS, pAggInfo uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var _ /* w at bp+0 */ TWalker
	_ = i
	libc.Xmemset(tls, bp, 0, uint32(28))
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_aggregateIdxEprRefToColCallback)
	i = 0
	for {
		if !(i < (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc) {
			break
		}
		_sqlite3WalkExpr(tls, bp, (**(**TAggInfo_func)(__ccgo_up((*TAggInfo)(unsafe.Pointer(pAggInfo)).FaFunc + uintptr(i)*24))).FpFExpr)
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** Find the table named by the first entry in source list pSrc. If successful,
//	** return a pointer to the Table structure and set output variable (*pzDb)
//	** to point to the name of the database containin the table (i.e. "main",
//	** "temp" or the name of an attached database).
//	**
//	** If the table cannot be located, return NULL. The value of the two output
//	** parameters is undefined in this case.
//	*/
func _alterFindTable(tls *libc.TLS, pParse uintptr, pSrc uintptr, piDb uintptr, pzDb uintptr, bAuth int32) (r uintptr) {
	var db, pTab uintptr
	var iDb int32
	_, _, _ = db, iDb, pTab
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pTab = uintptr(0)
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pSrc+8)
	if pTab != 0 {
		iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pTab)).FpSchema)
		**(**uintptr)(__ccgo_up(pzDb)) = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
		**(**int32)(__ccgo_up(piDb)) = iDb
		if SQLITE_OK != _isRealTable(tls, pParse, pTab, int32(2)) || SQLITE_OK != _isAlterableTable(tls, pParse, pTab) {
			pTab = uintptr(0)
		}
	}
	if pTab != 0 && bAuth != 0 {
		if _sqlite3AuthCheck(tls, pParse, int32(SQLITE_ALTER_TABLE), **(**uintptr)(__ccgo_up(pzDb)), (*TTable)(unsafe.Pointer(pTab)).FzName, uintptr(0)) != 0 {
			pTab = uintptr(0)
		}
	}
	_sqlite3SrcListDelete(tls, db, pSrc)
	return pTab
}

// C documentation
//
//	/*
//	** Generate code that will do an analysis of an entire database
//	*/
func _analyzeDatabase(tls *libc.TLS, pParse uintptr, iDb int32) {
	var db, k, pSchema, pTab uintptr
	var iMem, iStatCur, iTab int32
	_, _, _, _, _, _, _ = db, iMem, iStatCur, iTab, k, pSchema, pTab
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	_sqlite3BeginWriteOperation(tls, pParse, 0, iDb)
	iStatCur = (*TParse)(unsafe.Pointer(pParse)).FnTab
	**(**int32)(__ccgo_up(pParse + 44)) += int32(3)
	_openStatTable(tls, pParse, iDb, iStatCur, uintptr(0), uintptr(0))
	iMem = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	iTab = (*TParse)(unsafe.Pointer(pParse)).FnTab
	k = (*THash)(unsafe.Pointer(pSchema + 8)).Ffirst
	for {
		if !(k != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(k)).Fdata
		_analyzeOneTable(tls, pParse, pTab, uintptr(0), iStatCur, iMem, iTab)
		iMem = _sqlite3FirstAvailableRegister(tls, pParse, iMem)
		goto _1
	_1:
		;
		k = (*THashElem)(unsafe.Pointer(k)).Fnext
	}
	_loadAnalysis(tls, pParse, iDb)
}

// C documentation
//
//	/*
//	** Append text z[] to the end of p[].  Return a pointer to the first
//	** character after then zero terminator on the new text in p[].
//	*/
func _appendText(tls *libc.TLS, p uintptr, z uintptr) (r uintptr) {
	var n Tsize_t
	_ = n
	n = libc.Xstrlen(tls, z)
	libc.Xmemcpy(tls, p, z, n+uint32(1))
	return p + uintptr(n) + uintptr(1)
}

// C documentation
//
//	/*
//	** Try to convert a value into a numeric representation if we can
//	** do so without loss of information.  In other words, if the string
//	** looks like a number, convert it into a number.  If it does not
//	** look like a number, leave it alone.
//	**
//	** If the bTryForInt flag is true, then extra effort is made to give
//	** an integer representation.  Strings that look like floating point
//	** values but which have no fractional component (example: '48.00')
//	** will have a MEM_Int representation when bTryForInt is true.
//	**
//	** If bTryForInt is false, then if the input string contains a decimal
//	** point or exponential notation, the result is only MEM_Real, even
//	** if there is an exact integer representation of the quantity.
//	*/
func _applyNumericAffinity(tls *libc.TLS, pRec uintptr, bTryForInt int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var v1 uintptr
	var _ /* rValue at bp+0 */ float64
	_, _ = rc, v1
	rc = _sqlite3MemRealValueRC(tls, pRec, bp)
	if rc <= 0 {
		return
	}
	if rc&int32(2) == 0 && _alsoAnInt(tls, pRec, **(**float64)(__ccgo_up(bp)), pRec) != 0 {
		v1 = pRec + 16
		*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(MEM_Int))
	} else {
		*(*float64)(unsafe.Pointer(pRec)) = **(**float64)(__ccgo_up(bp))
		v1 = pRec + 16
		*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(MEM_Real))
		if bTryForInt != 0 {
			_sqlite3VdbeIntegerAffinity(tls, pRec)
		}
	}
	/* TEXT->NUMERIC is many->one.  Hence, it is important to invalidate the
	 ** string representation after computing a numeric equivalent, because the
	 ** string representation might not be the canonical representation for the
	 ** numeric value.  Ticket [343634942dd54ab57b7024] 2018-01-31. */
	v1 = pRec + 16
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(MEM_Str))
}

// C documentation
//
//	/*
//	** Allocate a block of registers so that there is one register for each
//	** pAggInfo->aCol[] and pAggInfo->aFunc[] entry in pAggInfo.  The first
//	** register in this block is stored in pAggInfo->iFirstReg.
//	**
//	** This routine may only be called once for each AggInfo object.  Prior
//	** to calling this routine:
//	**
//	**     *  The aCol[] and aFunc[] arrays may be modified
//	**     *  The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used
//	**
//	** After calling this routine:
//	**
//	**     *  The aCol[] and aFunc[] arrays are fixed
//	**     *  The AggInfoColumnReg() and AggInfoFuncReg() macros may be used
//	**
//	*/
func _assignAggregateRegisters(tls *libc.TLS, pParse uintptr, pAggInfo uintptr) {
	(*TAggInfo)(unsafe.Pointer(pAggInfo)).FiFirstReg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	**(**int32)(__ccgo_up(pParse + 48)) += (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnColumn + (*TAggInfo)(unsafe.Pointer(pAggInfo)).FnFunc
}

// C documentation
//
//	/*
//	** Enter the mutex on every Btree associated with a database
//	** connection.  This is needed (for example) prior to parsing
//	** a statement since we will be comparing table and column names
//	** against all schemas and we do not want those schemas being
//	** reset out from under us.
//	**
//	** There is a corresponding leave-all procedures.
//	**
//	** Enter the mutexes in ascending order by BtShared pointer address
//	** to avoid the possibility of deadlock when two threads with
//	** two or more btrees in common both try to lock all their btrees
//	** at the same instant.
//	*/
func _btreeEnterAll(tls *libc.TLS, db uintptr) {
	var i int32
	var p uintptr
	var skipOk Tu8
	_, _, _ = i, p, skipOk
	skipOk = uint8(1)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		p = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if p != 0 && (*TBtree)(unsafe.Pointer(p)).Fsharable != 0 {
			_sqlite3BtreeEnter(tls, p)
			skipOk = uint8(0)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache = skipOk
}

func _btreeLeaveAll(tls *libc.TLS, db uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		p = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if p != 0 {
			_sqlite3BtreeLeave(tls, p)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** 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.
//	*/
func _callFinaliser(tls *libc.TLS, db uintptr, offset int32) {
	var aVTrans, p, pVTab, x uintptr
	var i int32
	_, _, _, _, _ = aVTrans, i, p, pVTab, x
	if (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans != 0 {
		aVTrans = (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans
		(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = uintptr(0)
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) {
				break
			}
			pVTab = **(**uintptr)(__ccgo_up(aVTrans + uintptr(i)*4))
			p = (*TVTable)(unsafe.Pointer(pVTab)).FpVtab
			if p != 0 {
				x = **(**uintptr)(__ccgo_up((*Tsqlite3_vtab)(unsafe.Pointer(p)).FpModule + uintptr(offset)))
				if x != 0 {
					(*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, p)
				}
			}
			(*TVTable)(unsafe.Pointer(pVTab)).FiSavepoint = 0
			_sqlite3VtabUnlock(tls, pVTab)
			goto _1
		_1:
			;
			i = i + 1
		}
		_sqlite3DbFree(tls, db, aVTrans)
		(*Tsqlite3)(unsafe.Pointer(db)).FnVTrans = 0
	}
}

// C documentation
//
//	/* The RFC-7539 ChaCha20 block function
//	*/
func _chacha_block(tls *libc.TLS, out uintptr, in uintptr) {
	bp := tls.Alloc(64)
	defer tls.Free(64)
	var i int32
	var _ /* x at bp+0 */ [16]Tu32
	_ = i
	libc.Xmemcpy(tls, bp, in, uint32(64))
	i = 0
	for {
		if !(i < int32(10)) {
			break
		}
		**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
		**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
		**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
		**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
		**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
		**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
		**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
		**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
		**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
		**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
		**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
		**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
		**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
		**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
		**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
		**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
		**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
		**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
		**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]
		**(**Tu32)(__ccgo_up(bp + 15*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[0]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 10*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(15)]
		**(**Tu32)(__ccgo_up(bp + 5*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(10)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(5)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
		**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
		**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp + 1*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]
		**(**Tu32)(__ccgo_up(bp + 12*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(1)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 11*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(12)]
		**(**Tu32)(__ccgo_up(bp + 6*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(11)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(6)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
		**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
		**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp + 2*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]
		**(**Tu32)(__ccgo_up(bp + 13*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(2)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 8*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(13)]
		**(**Tu32)(__ccgo_up(bp + 7*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(8)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(7)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
		**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<<libc.Int32FromInt32(16) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(16))
		**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
		**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<<libc.Int32FromInt32(12) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(12))
		**(**Tu32)(__ccgo_up(bp + 3*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]
		**(**Tu32)(__ccgo_up(bp + 14*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(3)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]<<libc.Int32FromInt32(8) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(8))
		**(**Tu32)(__ccgo_up(bp + 9*4)) += (**(**[16]Tu32)(__ccgo_up(bp)))[int32(14)]
		**(**Tu32)(__ccgo_up(bp + 4*4)) ^= (**(**[16]Tu32)(__ccgo_up(bp)))[int32(9)]
		(**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)] = (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]<<libc.Int32FromInt32(7) | (**(**[16]Tu32)(__ccgo_up(bp)))[int32(4)]>>(libc.Int32FromInt32(32)-libc.Int32FromInt32(7))
		goto _1
	_1:
		;
		i = i + 1
	}
	i = 0
	for {
		if !(i < int32(16)) {
			break
		}
		**(**Tu32)(__ccgo_up(out + uintptr(i)*4)) = (**(**[16]Tu32)(__ccgo_up(bp)))[i] + **(**Tu32)(__ccgo_up(in + uintptr(i)*4))
		goto _2
	_2:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** This function does processing common to the _change_int64(), _change_text()
//	** and other similar APIs.
//	*/
func _checkChangeParams(tls *libc.TLS, pGrp uintptr, bNew int32, iCol int32, nReq Tsqlite3_int64, ppBuf uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pBuf uintptr
	var _ /* rc at bp+0 */ int32
	_ = pBuf
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab == uintptr(0) {
		**(**int32)(__ccgo_up(bp)) = int32(SQLITE_MISUSE)
	} else {
		if iCol < 0 || iCol >= (*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol {
			**(**int32)(__ccgo_up(bp)) = int32(SQLITE_RANGE)
		} else {
			if bNew != 0 && (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_DELETE) || !(bNew != 0) && (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_INSERT) {
				**(**int32)(__ccgo_up(bp)) = int32(SQLITE_ERROR)
			} else {
				pBuf = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FaBuf + uintptr(iCol)*12
				if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FeOp == int32(SQLITE_UPDATE) && bNew != 0 {
					pBuf = pBuf + uintptr((*TSessionTable)(unsafe.Pointer((*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).Fcd.FpTab)).FnCol)*12
				}
				(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = 0
				_sessionBufferGrow(tls, pBuf, nReq, bp)
				(*TSessionBuffer)(unsafe.Pointer(pBuf)).FnBuf = int32(nReq)
				**(**uintptr)(__ccgo_up(ppBuf)) = pBuf
			}
		}
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** pEList is the SET clause of an UPDATE statement.  Each entry
//	** in pEList is of the format <id>=<expr>.  If any of the entries
//	** in pEList have an <id> which matches an identifier in pIdList,
//	** then return TRUE.  If pIdList==NULL, then it is considered a
//	** wildcard that matches anything.  Likewise if pEList==NULL then
//	** it matches anything so always return true.  Return false only
//	** if there is no match.
//	*/
func _checkColumnOverlap(tls *libc.TLS, pIdList uintptr, pEList uintptr) (r int32) {
	var e int32
	_ = e
	if pIdList == uintptr(0) || pEList == uintptr(0) {
		return int32(1)
	}
	e = 0
	for {
		if !(e < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		if _sqlite3IdListIndex(tls, pIdList, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(e)*20))).FzEName) >= 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		e = e + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** Release all the table locks (locks obtained via calls to
//	** the setSharedCacheTableLock() procedure) held by Btree object p.
//	**
//	** This function assumes that Btree p has an open read or write
//	** transaction. If it does not, then the BTS_PENDING flag
//	** may be incorrectly cleared.
//	*/
func _clearAllSharedCacheTableLocks(tls *libc.TLS, p uintptr) {
	var pBt, pLock, ppIter, v1 uintptr
	_, _, _, _ = pBt, pLock, ppIter, v1
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	ppIter = pBt + 76
	for **(**uintptr)(__ccgo_up(ppIter)) != 0 {
		pLock = **(**uintptr)(__ccgo_up(ppIter))
		if (*TBtLock)(unsafe.Pointer(pLock)).FpBtree == p {
			**(**uintptr)(__ccgo_up(ppIter)) = (*TBtLock)(unsafe.Pointer(pLock)).FpNext
			if (*TBtLock)(unsafe.Pointer(pLock)).FiTable != uint32(1) {
				Xsqlite3_free(tls, pLock)
			}
		} else {
			ppIter = pLock + 12
		}
	}
	if (*TBtShared)(unsafe.Pointer(pBt)).FpWriter == p {
		(*TBtShared)(unsafe.Pointer(pBt)).FpWriter = uintptr(0)
		v1 = pBt + 24
		*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(BTS_EXCLUSIVE) | libc.Int32FromInt32(BTS_PENDING)))
	} else {
		if (*TBtShared)(unsafe.Pointer(pBt)).FnTransaction == int32(2) {
			/* This function is called when Btree p is concluding its
			 ** transaction. If there currently exists a writer, and p is not
			 ** that writer, then the number of locks held by connections other
			 ** than the writer must be about to drop to zero. In this case
			 ** set the BTS_PENDING flag to 0.
			 **
			 ** If there is not currently a writer, then BTS_PENDING must
			 ** be zero already. So this next line is harmless in that case.
			 */
			v1 = pBt + 24
			*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(BTS_PENDING))
		}
	}
}

// C documentation
//
//	/*
//	** Close all cursors in the current frame.
//	*/
func _closeCursorsInFrame(tls *libc.TLS, p uintptr) {
	var i int32
	var pC uintptr
	_, _ = i, pC
	i = 0
	for {
		if !(i < (*TVdbe)(unsafe.Pointer(p)).FnCursor) {
			break
		}
		pC = **(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(i)*4))
		if pC != 0 {
			_sqlite3VdbeFreeCursorNN(tls, p, pC)
			**(**uintptr)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FapCsr + uintptr(i)*4)) = uintptr(0)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** Add code that will check to make sure the array of registers starting at
//	** iMem form a distinct entry. This is used by both "SELECT DISTINCT ..." and
//	** distinct aggregates ("SELECT count(DISTINCT <expr>) ..."). Three strategies
//	** are available. Which is used depends on the value of parameter eTnctType,
//	** as follows:
//	**
//	**   WHERE_DISTINCT_UNORDERED/WHERE_DISTINCT_NOOP:
//	**     Build an ephemeral table that contains all entries seen before and
//	**     skip entries which have been seen before.
//	**
//	**     Parameter iTab is the cursor number of an ephemeral table that must
//	**     be opened before the VM code generated by this routine is executed.
//	**     The ephemeral cursor table is queried for a record identical to the
//	**     record formed by the current array of registers. If one is found,
//	**     jump to VM address addrRepeat. Otherwise, insert a new record into
//	**     the ephemeral cursor and proceed.
//	**
//	**     The returned value in this case is a copy of parameter iTab.
//	**
//	**   WHERE_DISTINCT_ORDERED:
//	**     In this case rows are being delivered sorted order. The ephemeral
//	**     table is not required. Instead, the current set of values
//	**     is compared against previous row. If they match, the new row
//	**     is not distinct and control jumps to VM address addrRepeat. Otherwise,
//	**     the VM program proceeds with processing the new row.
//	**
//	**     The returned value in this case is the register number of the first
//	**     in an array of registers used to store the previous result row so that
//	**     it can be compared to the next. The caller must ensure that this
//	**     register is initialized to NULL.  (The fixDistinctOpenEph() routine
//	**     will take care of this initialization.)
//	**
//	**   WHERE_DISTINCT_UNIQUE:
//	**     In this case it has already been determined that the rows are distinct.
//	**     No special action is required. The return value is zero.
//	**
//	** Parameter pEList is the list of expressions used to generated the
//	** contents of each row. It is used by this routine to determine (a)
//	** how many elements there are in the array of registers and (b) the
//	** collation sequences that should be used for the comparisons if
//	** eTnctType is WHERE_DISTINCT_ORDERED.
//	*/
func _codeDistinct(tls *libc.TLS, pParse uintptr, eTnctType int32, iTab int32, addrRepeat int32, pEList uintptr, regElem int32) (r int32) {
	var i, iJump, iRet, nResultCol, r1, regPrev, v1 int32
	var pColl, v uintptr
	_, _, _, _, _, _, _, _, _ = i, iJump, iRet, nResultCol, pColl, r1, regPrev, v, v1
	iRet = 0
	nResultCol = (*TExprList)(unsafe.Pointer(pEList)).FnExpr
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	switch eTnctType {
	case int32(WHERE_DISTINCT_ORDERED): /* Previous row content */
		/* Allocate space for the previous row */
		v1 = (*TParse)(unsafe.Pointer(pParse)).FnMem + libc.Int32FromInt32(1)
		regPrev = v1
		iRet = v1
		**(**int32)(__ccgo_up(pParse + 48)) += nResultCol
		iJump = _sqlite3VdbeCurrentAddr(tls, v) + nResultCol
		i = 0
		for {
			if !(i < nResultCol) {
				break
			}
			pColl = _sqlite3ExprCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr)
			if i < nResultCol-int32(1) {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Ne), regElem+i, iJump, regPrev+i)
			} else {
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Eq), regElem+i, addrRepeat, regPrev+i)
			}
			_sqlite3VdbeChangeP4(tls, v, -int32(1), pColl, -int32(2))
			_sqlite3VdbeChangeP5(tls, v, uint16(SQLITE_NULLEQ))
			goto _2
		_2:
			;
			i = i + 1
		}
		_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), regElem, regPrev, nResultCol-int32(1))
	case int32(WHERE_DISTINCT_UNIQUE):
		/* nothing to do */
	default:
		r1 = _sqlite3GetTempReg(tls, pParse)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_Found), iTab, addrRepeat, regElem, nResultCol)
		_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regElem, nResultCol, r1)
		_sqlite3VdbeAddOp4Int(tls, v, int32(OP_IdxInsert), iTab, r1, regElem, nResultCol)
		_sqlite3VdbeChangeP5(tls, v, uint16(OPFLAG_USESEEKRESULT))
		_sqlite3ReleaseTempReg(tls, pParse, r1)
		iRet = iTab
		break
	}
	return iRet
}

// C documentation
//
//	/*
//	** If the expression passed as the second argument is a vector, generate
//	** code to write the first nReg elements of the vector into an array
//	** of registers starting with iReg.
//	**
//	** If the expression is not a vector, then nReg must be passed 1. In
//	** this case, generate code to evaluate the expression and leave the
//	** result in register iReg.
//	*/
func _codeExprOrVector(tls *libc.TLS, pParse uintptr, p uintptr, iReg int32, nReg int32) {
	var i, iSelect int32
	var pList, v uintptr
	_, _, _, _ = i, iSelect, pList, v
	if p != 0 && _sqlite3ExprIsVector(tls, p) != 0 {
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
			v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
			iSelect = _sqlite3CodeSubselect(tls, pParse, p)
			_sqlite3VdbeAddOp3(tls, v, int32(OP_Copy), iSelect, iReg, nReg-int32(1))
		} else {
			pList = *(*uintptr)(unsafe.Pointer(p + 20))
			i = 0
			for {
				if !(i < nReg) {
					break
				}
				_sqlite3ExprCode(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr, iReg+i)
				goto _1
			_1:
				;
				i = i + 1
			}
		}
	} else {
		_sqlite3ExprCode(tls, pParse, p, iReg)
	}
}

// C documentation
//
//	/*
//	** Return the size of the Nth element of the cell array
//	*/
func _computeCellSize(tls *libc.TLS, p uintptr, N int32) (r Tu16) {
	**(**Tu16)(__ccgo_up((*TCellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2)) = (*(*func(*libc.TLS, uintptr, uintptr) Tu16)(unsafe.Pointer(&struct{ uintptr }{(*TMemPage)(unsafe.Pointer((*TCellArray)(unsafe.Pointer(p)).FpRef)).FxCellSize})))(tls, (*TCellArray)(unsafe.Pointer(p)).FpRef, **(**uintptr)(__ccgo_up((*TCellArray)(unsafe.Pointer(p)).FapCell + uintptr(N)*4)))
	return **(**Tu16)(__ccgo_up((*TCellArray)(unsafe.Pointer(p)).FszCell + uintptr(N)*2))
}

// C documentation
//
//	/*
//	** The CONCAT_WS(separator, ...) function.
//	**
//	** Generate a string that is the concatenation of 2nd through the Nth
//	** argument.  Use the first argument (which must be non-NULL) as the
//	** separator.
//	*/
func _concatwsFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var nSep int32
	var zSep uintptr
	_, _ = nSep, zSep
	nSep = Xsqlite3_value_bytes(tls, **(**uintptr)(__ccgo_up(argv)))
	zSep = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	if zSep == uintptr(0) {
		return
	}
	_concatFuncCore(tls, context, argc-int32(1), argv+uintptr(1)*4, nSep, zSep)
}

// C documentation
//
//	/*
//	** Return TRUE if database connection db has unfinalized prepared
//	** statements or unfinished sqlite3_backup objects.
//	*/
func _connectionIsBusy(tls *libc.TLS, db uintptr) (r int32) {
	var j int32
	var pBt uintptr
	_, _ = j, pBt
	if (*Tsqlite3)(unsafe.Pointer(db)).FpVdbe != 0 {
		return int32(1)
	}
	j = 0
	for {
		if !(j < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*16))).FpBt
		if pBt != 0 && _sqlite3BtreeIsInBackup(tls, pBt) != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		j = j + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** Worker function used by utf-8 APIs that create new functions:
//	**
//	**    sqlite3_create_function()
//	**    sqlite3_create_function_v2()
//	**    sqlite3_create_window_function()
//	*/
func _createFunctionApi(tls *libc.TLS, db uintptr, zFunc uintptr, nArg int32, enc int32, p uintptr, __ccgo_fp_xSFunc uintptr, __ccgo_fp_xStep uintptr, __ccgo_fp_xFinal uintptr, __ccgo_fp_xValue uintptr, __ccgo_fp_xInverse uintptr, __ccgo_fp_xDestroy uintptr) (r int32) {
	var pArg uintptr
	var rc int32
	_, _ = pArg, rc
	rc = int32(SQLITE_ERROR)
	pArg = uintptr(0)
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	if __ccgo_fp_xDestroy != 0 {
		pArg = _sqlite3Malloc(tls, uint64(12))
		if !(pArg != 0) {
			_sqlite3OomFault(tls, db)
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xDestroy})))(tls, p)
			goto out
		}
		(*TFuncDestructor)(unsafe.Pointer(pArg)).FnRef = 0
		(*TFuncDestructor)(unsafe.Pointer(pArg)).FxDestroy = __ccgo_fp_xDestroy
		(*TFuncDestructor)(unsafe.Pointer(pArg)).FpUserData = p
	}
	rc = _sqlite3CreateFunc(tls, db, zFunc, nArg, enc, p, __ccgo_fp_xSFunc, __ccgo_fp_xStep, __ccgo_fp_xFinal, __ccgo_fp_xValue, __ccgo_fp_xInverse, pArg)
	if pArg != 0 && (*TFuncDestructor)(unsafe.Pointer(pArg)).FnRef == 0 {
		(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xDestroy})))(tls, p)
		Xsqlite3_free(tls, pArg)
	}
	goto out
out:
	;
	rc = _sqlite3ApiExit(tls, db, rc)
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer(db)).Fmutex)
	return rc
}

// C documentation
//
//	/*
//	** Put the DateTime object into its error state.
//	*/
func _datetimeError(tls *libc.TLS, p uintptr) {
	libc.Xmemset(tls, p, 0, uint32(48))
	libc.SetBitFieldPtr8Uint32(p+44, libc.Uint32FromInt32(1), 1, 0x2)
}

// C documentation
//
//	/*
//	** Open write transactions. Since we do not know in advance which database
//	** files will be written by the sqlite_dbpage virtual table, start a write
//	** transaction on them all.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code otherwise.
//	*/
func _dbpageBeginTrans(tls *libc.TLS, pTab uintptr) (r int32) {
	var db, pBt uintptr
	var i, rc int32
	_, _, _, _ = db, i, pBt, rc
	db = (*TDbpageTable)(unsafe.Pointer(pTab)).Fdb
	rc = SQLITE_OK
	i = 0
	for {
		if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 {
			rc = _sqlite3BtreeBeginTrans(tls, pBt, int32(1), uintptr(0))
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return rc
}

// C documentation
//
//	/*
//	** Open a new dbpagevfs cursor.
//	*/
func _dbpageOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = Xsqlite3_malloc64(tls, uint64(28))
	if pCsr == uintptr(0) {
		return int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, pCsr, 0, uint32(28))
		(*TDbpageCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
		(*TDbpageCursor)(unsafe.Pointer(pCsr)).Fpgno = uint32(0)
	}
	**(**uintptr)(__ccgo_up(ppCursor)) = pCsr
	return SQLITE_OK
}

// C documentation
//
//	/* Invoke sqlite3PagerTruncate() as necessary, just prior to COMMIT
//	*/
func _dbpageSync(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pBt, pPager, pTab uintptr
	_, _, _ = pBt, pPager, pTab
	pTab = pVtab
	if (*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc > uint32(0) {
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TDbpageTable)(unsafe.Pointer(pTab)).Fdb)).FaDb + uintptr((*TDbpageTable)(unsafe.Pointer(pTab)).FiDbTrunc)*16))).FpBt
		pPager = _sqlite3BtreePager(tls, pBt)
		_sqlite3BtreeEnter(tls, pBt)
		if (*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc < _sqlite3BtreeLastPage(tls, pBt) {
			_sqlite3PagerTruncateImage(tls, pPager, (*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc)
		}
		_sqlite3BtreeLeave(tls, pBt)
	}
	(*TDbpageTable)(unsafe.Pointer(pTab)).FpgnoTrunc = uint32(0)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Disable lookaside memory allocation for objects that might be
//	** shared across database connections.
//	*/
func _disableLookaside(tls *libc.TLS, pParse uintptr) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	(*TParse)(unsafe.Pointer(pParse)).FdisableLookaside = (*TParse)(unsafe.Pointer(pParse)).FdisableLookaside + 1
	libc.Xmemset(tls, pParse+184, 0, uint32(20))
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FbDisable + 1
	(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.Fsz = uint16(0)
}

// C documentation
//
//	/*
//	** This function is called after a transaction has been committed. It
//	** invokes callbacks registered with sqlite3_wal_hook() as required.
//	*/
func _doWalCallbacks(tls *libc.TLS, db uintptr) (r int32) {
	var i, nEntry, rc int32
	var pBt uintptr
	_, _, _, _ = i, nEntry, pBt, rc
	rc = SQLITE_OK
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 {
			_sqlite3BtreeEnter(tls, pBt)
			nEntry = _sqlite3PagerWalCallback(tls, _sqlite3BtreePager(tls, pBt))
			_sqlite3BtreeLeave(tls, pBt)
			if nEntry > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FxWalCallback != 0 && rc == SQLITE_OK {
				rc = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3)(unsafe.Pointer(db)).FxWalCallback})))(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpWalArg, db, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FzDbSName, nEntry)
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return rc
}

// C documentation
//
//	/*
//	** This function changes all write-locks held by Btree p into read-locks.
//	*/
func _downgradeAllSharedCacheTableLocks(tls *libc.TLS, p uintptr) {
	var pBt, pLock, v1 uintptr
	_, _, _ = pBt, pLock, v1
	pBt = (*TBtree)(unsafe.Pointer(p)).FpBt
	if (*TBtShared)(unsafe.Pointer(pBt)).FpWriter == p {
		(*TBtShared)(unsafe.Pointer(pBt)).FpWriter = uintptr(0)
		v1 = pBt + 24
		*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(BTS_EXCLUSIVE) | libc.Int32FromInt32(BTS_PENDING)))
		pLock = (*TBtShared)(unsafe.Pointer(pBt)).FpLock
		for {
			if !(pLock != 0) {
				break
			}
			(*TBtLock)(unsafe.Pointer(pLock)).FeLock = uint8(READ_LOCK)
			goto _2
		_2:
			;
			pLock = (*TBtLock)(unsafe.Pointer(pLock)).FpNext
		}
	}
}

/* Forward reference */

/*
***** This routine is used inside of assert() only ****
**
** Verify that the cursor holds the mutex on its BtShared
 */

/*
** Invalidate the overflow cache of the cursor passed as the first argument.
** on the shared btree structure pBt.
 */

// C documentation
//
//	/*
//	** Return the length of the longest string literal in the given
//	** expression.
//	**
//	** eCode indicates how to count characters:
//	**
//	**    eCode==0     Count as a GLOB pattern
//	**    eCode==1     Count as a LIKE pattern
//	*/
func _estLikePatternLength(tls *libc.TLS, p uintptr, eCode Tu16) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	*(*int32)(unsafe.Pointer(bp + 24)) = 0
	(**(**TWalker)(__ccgo_up(bp))).FeCode = eCode
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_exprNodePatternLengthEst)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkFail)
	_sqlite3WalkExpr(tls, bp, p)
	return *(*int32)(unsafe.Pointer(bp + 24))
}

// C documentation
//
//	/*
//	** Estimate the total row width for a table.
//	*/
func _estimateTableWidth(tls *libc.TLS, pTab uintptr) {
	var i int32
	var pTabCol uintptr
	var wTable uint32
	_, _, _ = i, pTabCol, wTable
	wTable = uint32(0)
	i = int32((*TTable)(unsafe.Pointer(pTab)).FnCol)
	pTabCol = (*TTable)(unsafe.Pointer(pTab)).FaCol
	for {
		if !(i > 0) {
			break
		}
		wTable = wTable + uint32((*TColumn)(unsafe.Pointer(pTabCol)).FszEst)
		goto _1
	_1:
		;
		i = i - 1
		pTabCol += 12
	}
	if int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) < 0 {
		wTable = wTable + 1
	}
	(*TTable)(unsafe.Pointer(pTab)).FszTabRow = _sqlite3LogEst(tls, uint64(wTable*uint32(4)))
}

// C documentation
//
//	/*
//	** Delete an entire expression list.
//	*/
func _exprListDeleteNN(tls *libc.TLS, db uintptr, pList uintptr) {
	var i, v1 int32
	var pItem uintptr
	_, _, _ = i, pItem, v1
	i = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	pItem = pList + 8
	for {
		_sqlite3ExprDelete(tls, db, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
		if (*TExprList_item)(unsafe.Pointer(pItem)).FzEName != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TExprList_item)(unsafe.Pointer(pItem)).FzEName)
		}
		pItem += 20
		goto _2
	_2:
		;
		i = i - 1
		v1 = i
		if !(v1 > 0) {
			break
		}
	}
	_sqlite3DbNNFreeNN(tls, db, pList)
}

// C documentation
//
//	/*
//	** Return true if all expressions in the expression-list passed as the
//	** only argument are constant.
//	*/
func _exprListIsConstant(tls *libc.TLS, pParse uintptr, pRow uintptr) (r int32) {
	var ii int32
	_ = ii
	ii = 0
	for {
		if !(ii < (*TExprList)(unsafe.Pointer(pRow)).FnExpr) {
			break
		}
		if 0 == _sqlite3ExprIsConstant(tls, pParse, (*(*TExprList_item)(unsafe.Pointer(pRow + 8 + uintptr(ii)*20))).FpExpr) {
			return 0
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
//	*/
func _exprNodeIsConstantOrGroupBy(tls *libc.TLS, pWalker uintptr, pExpr uintptr) (r int32) {
	var i int32
	var p, pColl, pGroupBy uintptr
	_, _, _, _ = i, p, pColl, pGroupBy
	pGroupBy = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	/* Check if pExpr is identical to any GROUP BY term. If so, consider
	 ** it constant.  */
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pGroupBy)).FnExpr) {
			break
		}
		p = (*(*TExprList_item)(unsafe.Pointer(pGroupBy + 8 + uintptr(i)*20))).FpExpr
		if _sqlite3ExprCompare(tls, uintptr(0), pExpr, p, -int32(1)) < int32(2) {
			pColl = _sqlite3ExprNNCollSeq(tls, (*TWalker)(unsafe.Pointer(pWalker)).FpParse, p)
			if _sqlite3IsBinary(tls, pColl) != 0 {
				return int32(WRC_Prune)
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	/* Check if pExpr is a sub-select. If so, consider it variable. */
	if (*TExpr)(unsafe.Pointer(pExpr)).Fflags&uint32(EP_xIsSelect) != uint32(0) {
		(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(0)
		return int32(WRC_Abort)
	}
	return _exprNodeIsConstant(tls, pWalker, pExpr)
}

// C documentation
//
//	/*
//	** Expression pExpr is guaranteed to be a TK_COLUMN or equivalent. This
//	** function checks the Parse.pIdxPartExpr list to see if this column
//	** can be replaced with a constant value. If so, it generates code to
//	** put the constant value in a register (ideally, but not necessarily,
//	** register iTarget) and returns the register number.
//	**
//	** Or, if the TK_COLUMN cannot be replaced by a constant, zero is
//	** returned.
//	*/
func _exprPartidxExprLookup(tls *libc.TLS, pParse uintptr, pExpr uintptr, iTarget int32) (r int32) {
	var addr, ret int32
	var p, v uintptr
	_, _, _, _ = addr, p, ret, v
	p = (*TParse)(unsafe.Pointer(pParse)).FpIdxPartExpr
	for {
		if !(p != 0) {
			break
		}
		if int32((*TExpr)(unsafe.Pointer(pExpr)).FiColumn) == (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCol && (*TExpr)(unsafe.Pointer(pExpr)).FiTable == (*TIndexedExpr)(unsafe.Pointer(p)).FiDataCur {
			v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
			addr = 0
			if (*TIndexedExpr)(unsafe.Pointer(p)).FbMaybeNullRow != 0 {
				addr = _sqlite3VdbeAddOp1(tls, v, int32(OP_IfNullRow), (*TIndexedExpr)(unsafe.Pointer(p)).FiIdxCur)
			}
			ret = _sqlite3ExprCodeTarget(tls, pParse, (*TIndexedExpr)(unsafe.Pointer(p)).FpExpr, iTarget)
			_sqlite3VdbeAddOp4(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, int32(OP_Affinity), ret, int32(1), 0, p+17, int32(1))
			if addr != 0 {
				_sqlite3VdbeJumpHere(tls, v, addr)
				_sqlite3VdbeChangeP3(tls, v, addr, ret)
			}
			return ret
		}
		goto _1
	_1:
		;
		p = (*TIndexedExpr)(unsafe.Pointer(p)).FpIENext
	}
	return 0
}

// C documentation
//
//	/*
//	** Recursively walk the expressions of a SELECT statement and generate
//	** a bitmask indicating which tables are used in that expression
//	** tree.
//	*/
func _exprSelectUsage(tls *libc.TLS, pMaskSet uintptr, pS uintptr) (r TBitmask) {
	var i int32
	var mask TBitmask
	var pSrc uintptr
	_, _, _ = i, mask, pSrc
	mask = uint64(0)
	for pS != 0 {
		pSrc = (*TSelect)(unsafe.Pointer(pS)).FpSrc
		mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpEList)
		mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpGroupBy)
		mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpOrderBy)
		mask = mask | _sqlite3WhereExprUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpWhere)
		mask = mask | _sqlite3WhereExprUsage(tls, pMaskSet, (*TSelect)(unsafe.Pointer(pS)).FpHaving)
		if pSrc != uintptr(0) {
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
					break
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 12 + 4))&0x4>>2) != 0 {
					mask = mask | _exprSelectUsage(tls, pMaskSet, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 44)))).FpSelect)
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 12 + 4))&0x800>>11) == 0 {
					mask = mask | _sqlite3WhereExprUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 40)))
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 12 + 4))&0x8>>3) != 0 {
					mask = mask | _sqlite3WhereExprListUsage(tls, pMaskSet, *(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 32)))
				}
				goto _1
			_1:
				;
				i = i + 1
			}
		}
		pS = (*TSelect)(unsafe.Pointer(pS)).FpPrior
	}
	return mask
}

// C documentation
//
//	/*
//	** Return an Expr object that refers to column iCol of table pTab which
//	** has cursor iCur.
//	*/
func _exprTableColumn(tls *libc.TLS, db uintptr, pTab uintptr, iCursor int32, iCol Ti16) (r uintptr) {
	var pExpr uintptr
	_ = pExpr
	pExpr = _sqlite3Expr(tls, db, int32(TK_COLUMN), uintptr(0))
	if pExpr != 0 {
		(*TExpr)(unsafe.Pointer(pExpr)).Fy.FpTab = pTab
		(*TExpr)(unsafe.Pointer(pExpr)).FiTable = iCursor
		(*TExpr)(unsafe.Pointer(pExpr)).FiColumn = iCol
	}
	return pExpr
}

// C documentation
//
//	/*
//	** The implementation of SQL function sqlite_fail(MSG). This takes a single
//	** argument, and returns it as an error message with the error code set to
//	** SQLITE_CONSTRAINT.
//	*/
func _failConstraintFunc(tls *libc.TLS, ctx uintptr, NotUsed int32, argv uintptr) {
	var err int32
	var zText uintptr
	_, _ = err, zText
	zText = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	err = Xsqlite3_value_int(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
	_ = NotUsed
	Xsqlite3_result_error(tls, ctx, zText, -int32(1))
	Xsqlite3_result_error_code(tls, ctx, err)
}

// C documentation
//
//	/*
//	** Implementation of internal SQL function:
//	**
//	**     sqlite_find_constraint(SQL, CONSTRAINT-NAME)
//	**
//	** This function returns true if the SQL passed as the first argument is a
//	** CREATE TABLE that contains a constraint with the name CONSTRAINT-NAME,
//	** or false otherwise.
//	*/
func _findConstraintFunc(tls *libc.TLS, ctx uintptr, NotUsed int32, argv uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iOff, nTok int32
	var zCons, zSql uintptr
	var _ /* cmp at bp+4 */ int32
	var _ /* t at bp+0 */ int32
	_, _, _, _ = iOff, nTok, zCons, zSql
	zSql = uintptr(0)
	zCons = uintptr(0)
	iOff = 0
	**(**int32)(__ccgo_up(bp)) = 0
	_ = NotUsed
	zSql = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv)))
	zCons = Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
	if zSql == uintptr(0) || zCons == uintptr(0) {
		return
	}
	for **(**int32)(__ccgo_up(bp)) != int32(TK_LP) && **(**int32)(__ccgo_up(bp)) != int32(TK_ILLEGAL) {
		iOff = int32(int64(iOff) + _sqlite3GetToken(tls, zSql+uintptr(iOff), bp))
	}
	for int32(1) != 0 {
		iOff = iOff + _getConstraintToken(tls, zSql+uintptr(iOff), bp)
		if **(**int32)(__ccgo_up(bp)) == int32(TK_CONSTRAINT) {
			nTok = 0
			**(**int32)(__ccgo_up(bp + 4)) = 0
			iOff = iOff + _getWhitespace(tls, zSql+uintptr(iOff))
			nTok = _getConstraintToken(tls, zSql+uintptr(iOff), bp)
			if _quotedCompare(tls, ctx, **(**int32)(__ccgo_up(bp)), zSql+uintptr(iOff), nTok, zCons, bp+4) != 0 {
				return
			}
			if **(**int32)(__ccgo_up(bp + 4)) == 0 {
				Xsqlite3_result_int(tls, ctx, int32(1))
				return
			}
		} else {
			if **(**int32)(__ccgo_up(bp)) == int32(TK_ILLEGAL) {
				break
			}
		}
	}
	Xsqlite3_result_int(tls, ctx, 0)
}

// C documentation
//
//	/* This function (for internal use only) locates an element in an
//	** hash table that matches the given key.  If no element is found,
//	** a pointer to a static null element with HashElem.data==0 is returned.
//	** If pH is not NULL, then the hash for this key is written to *pH.
//	*/
func _findElementWithHash(tls *libc.TLS, pH uintptr, pKey uintptr, pHash uintptr) (r uintptr) {
	var count, h uint32
	var elem, pEntry uintptr
	_, _, _, _ = count, elem, h, pEntry /* The computed hash */
	h = _strHash(tls, pKey)
	if (*THash)(unsafe.Pointer(pH)).Fht != 0 {
		pEntry = (*THash)(unsafe.Pointer(pH)).Fht + uintptr(h%(*THash)(unsafe.Pointer(pH)).Fhtsize)*8
		elem = (*T_ht)(unsafe.Pointer(pEntry)).Fchain
		count = (*T_ht)(unsafe.Pointer(pEntry)).Fcount
	} else {
		elem = (*THash)(unsafe.Pointer(pH)).Ffirst
		count = (*THash)(unsafe.Pointer(pH)).Fcount
	}
	if pHash != 0 {
		**(**uint32)(__ccgo_up(pHash)) = h
	}
	for count != 0 {
		if h == (*THashElem)(unsafe.Pointer(elem)).Fh && _sqlite3StrICmp(tls, (*THashElem)(unsafe.Pointer(elem)).FpKey, pKey) == 0 {
			return elem
		}
		elem = (*THashElem)(unsafe.Pointer(elem)).Fnext
		count = count - 1
	}
	return uintptr(unsafe.Pointer(&_nullElement))
}

// C documentation
//
//	/*
//	** The second argument points to an FKey object representing a foreign key
//	** for which pTab is the child table. An UPDATE statement against pTab
//	** is currently being processed. For each column of the table that is
//	** actually updated, the corresponding element in the aChange[] array
//	** is zero or greater (if a column is unmodified the corresponding element
//	** is set to -1). If the rowid column is modified by the UPDATE statement
//	** the bChngRowid argument is non-zero.
//	**
//	** This function returns true if any of the columns that are part of the
//	** child key for FK constraint *p are modified.
//	*/
func _fkChildIsModified(tls *libc.TLS, pTab uintptr, p uintptr, aChange uintptr, bChngRowid int32) (r int32) {
	var i, iChildKey int32
	_, _ = i, iChildKey
	i = 0
	for {
		if !(i < (*TFKey)(unsafe.Pointer(p)).FnCol) {
			break
		}
		iChildKey = (*(*TsColMap)(unsafe.Pointer(p + 36 + uintptr(i)*8))).FiFrom
		if **(**int32)(__ccgo_up(aChange + uintptr(iChildKey)*4)) >= 0 {
			return int32(1)
		}
		if iChildKey == int32((*TTable)(unsafe.Pointer(pTab)).FiPKey) && bChngRowid != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** Free the pBt->pTmpSpace allocation
//	*/
func _freeTempSpace(tls *libc.TLS, pBt uintptr) {
	if (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace != 0 {
		**(**uintptr)(__ccgo_up(pBt + 84)) -= uintptr(4)
		_sqlite3PageFree(tls, (*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace)
		(*TBtShared)(unsafe.Pointer(pBt)).FpTmpSpace = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Implementation of the xSetAuxdata() method.
//	*/
func _fts5ApiSetAuxdata(tls *libc.TLS, pCtx uintptr, pPtr uintptr, __ccgo_fp_xDelete uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pCsr, pData uintptr
	var _ /* rc at bp+0 */ int32
	_, _ = pCsr, pData
	pCsr = pCtx
	/* Search through the cursors list of Fts5Auxdata objects for one that
	 ** corresponds to the currently executing auxiliary function.  */
	pData = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
	for {
		if !(pData != 0) {
			break
		}
		if (*TFts5Auxdata)(unsafe.Pointer(pData)).FpAux == (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux {
			break
		}
		goto _1
	_1:
		;
		pData = (*TFts5Auxdata)(unsafe.Pointer(pData)).FpNext
	}
	if pData != 0 {
		if (*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete != 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete})))(tls, (*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr)
		}
	} else {
		**(**int32)(__ccgo_up(bp)) = SQLITE_OK
		pData = _sqlite3Fts5MallocZero(tls, bp, int64(16))
		if pData == uintptr(0) {
			if __ccgo_fp_xDelete != 0 {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xDelete})))(tls, pPtr)
			}
			return **(**int32)(__ccgo_up(bp))
		}
		(*TFts5Auxdata)(unsafe.Pointer(pData)).FpAux = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAux
		(*TFts5Auxdata)(unsafe.Pointer(pData)).FpNext = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata
		(*TFts5Cursor)(unsafe.Pointer(pCsr)).FpAuxdata = pData
	}
	(*TFts5Auxdata)(unsafe.Pointer(pData)).FxDelete = __ccgo_fp_xDelete
	(*TFts5Auxdata)(unsafe.Pointer(pData)).FpPtr = pPtr
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Initialize the iterator object indicated by the final parameter to
//	** iterate through coalesced phrase instances in column iCol.
//	*/
func _fts5CInstIterInit(tls *libc.TLS, pApi uintptr, pFts uintptr, iCol int32, pIter uintptr) (r int32) {
	var rc int32
	_ = rc
	libc.Xmemset(tls, pIter, 0, uint32(28))
	(*TCInstIter)(unsafe.Pointer(pIter)).FpApi = pApi
	(*TCInstIter)(unsafe.Pointer(pIter)).FpFts = pFts
	(*TCInstIter)(unsafe.Pointer(pIter)).FiCol = iCol
	rc = (*(*func(*libc.TLS, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5ExtensionApi)(unsafe.Pointer(pApi)).FxInstCount})))(tls, pFts, pIter+16)
	if rc == SQLITE_OK {
		rc = _fts5CInstIterNext(tls, pIter)
	}
	return rc
}

// C documentation
//
//	/*
//	** This is the xColumn method, called by SQLite to request a value from
//	** the row that the supplied cursor currently points to.
//	*/
func _fts5ColumnMethod(tls *libc.TLS, pCursor uintptr, pCtx uintptr, iCol int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pConfig, pCsr, pTab, pVal uintptr
	var rc, v1 int32
	var v2 bool
	var _ /* n at bp+4 */ int32
	var _ /* z at bp+0 */ uintptr
	_, _, _, _, _, _, _ = pConfig, pCsr, pTab, pVal, rc, v1, v2
	pTab = (*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab
	pConfig = (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig
	pCsr = pCursor
	rc = SQLITE_OK
	if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SPECIAL) {
		if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
			Xsqlite3_result_int64(tls, pCtx, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiSpecial)
		}
	} else {
		if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol {
			/* User is requesting the value of the special column with the same name
			 ** as the table. Return the cursor integer id number. This value is only
			 ** useful in that it may be passed as the first argument to an FTS5
			 ** auxiliary function.  */
			Xsqlite3_result_int64(tls, pCtx, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FiCsrId)
		} else {
			if iCol == (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol+int32(1) {
				/* The value of the "rank" column. */
				if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SOURCE) {
					_fts5PoslistBlob(tls, pCtx, pCsr)
				} else {
					if (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_MATCH) || (*TFts5Cursor)(unsafe.Pointer(pCsr)).FePlan == int32(FTS5_PLAN_SORTED_MATCH) {
						if v2 = (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRank != 0; !v2 {
							v1 = _fts5FindRankFunction(tls, pCsr)
							rc = v1
						}
						if v2 || SQLITE_OK == v1 {
							_fts5ApiInvoke(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpRank, pCsr, pCtx, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FnRankArg, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FapRankArg)
						}
					}
				}
			} else {
				if !(Xsqlite3_vtab_nochange(tls, pCtx) != 0) && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent != int32(FTS5_CONTENT_NONE) {
					(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = pTab + 8
					rc = _fts5SeekCursor(tls, pCsr, int32(1))
					if rc == SQLITE_OK {
						pVal = Xsqlite3_column_value(tls, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol+int32(1))
						if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_EXTERNAL) && _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
							**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
							**(**int32)(__ccgo_up(bp + 4)) = 0
							rc = _fts5TextFromStmt(tls, pConfig, (*TFts5Cursor)(unsafe.Pointer(pCsr)).FpStmt, iCol, bp, bp+4)
							if rc == SQLITE_OK {
								Xsqlite3_result_text(tls, pCtx, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), uintptr(-libc.Int32FromInt32(1)))
							}
							_sqlite3Fts5ClearLocale(tls, pConfig)
						} else {
							Xsqlite3_result_value(tls, pCtx, pVal)
						}
					}
					(*TFts5Config)(unsafe.Pointer(pConfig)).FpzErrmsg = uintptr(0)
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** All individual term iterators in pNear are guaranteed to be valid when
//	** this function is called. This function checks if all term iterators
//	** point to the same rowid, and if not, advances them until they do.
//	** If an EOF is reached before this happens, *pbEof is set to true before
//	** returning.
//	**
//	** SQLITE_OK is returned if an error occurs, or an SQLite error code
//	** otherwise. It is not considered an error code if an iterator reaches
//	** EOF.
//	*/
func _fts5ExprNodeTest_STRING(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bDesc, bMatch, i, j int32
	var iRowid Ti64
	var pIter, pLeft, pNear, pPhrase, pTerm uintptr
	var _ /* iLast at bp+8 */ Ti64
	var _ /* rc at bp+0 */ int32
	_, _, _, _, _, _, _, _, _, _ = bDesc, bMatch, i, iRowid, j, pIter, pLeft, pNear, pPhrase, pTerm
	pNear = (*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear
	pLeft = *(*uintptr)(unsafe.Pointer(pNear + 12))
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK /* True if all terms are at the same rowid */
	bDesc = (*TFts5Expr)(unsafe.Pointer(pExpr)).FbDesc
	/* Check that this node should not be FTS5_TERM */
	/* Initialize iLast, the "lastest" rowid any iterator points to. If the
	 ** iterator skips through rowids in the default ascending order, this means
	 ** the maximum rowid. Or, if the iterator is "ORDER BY rowid DESC", then it
	 ** means the minimum rowid.  */
	if (*(*TFts5ExprTerm)(unsafe.Pointer(pLeft + 20))).FpSynonym != 0 {
		**(**Ti64)(__ccgo_up(bp + 8)) = _fts5ExprSynonymRowid(tls, pLeft+20, bDesc, uintptr(0))
	} else {
		**(**Ti64)(__ccgo_up(bp + 8)) = (*TFts5IndexIter)(unsafe.Pointer((*(*TFts5ExprTerm)(unsafe.Pointer(pLeft + 20))).FpIter)).FiRowid
	}
	for cond := true; cond; cond = bMatch == 0 {
		bMatch = int32(1)
		i = 0
		for {
			if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			pPhrase = *(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4))
			j = 0
			for {
				if !(j < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
					break
				}
				pTerm = pPhrase + 20 + uintptr(j)*24
				if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
					iRowid = _fts5ExprSynonymRowid(tls, pTerm, bDesc, uintptr(0))
					if iRowid == **(**Ti64)(__ccgo_up(bp + 8)) {
						goto _2
					}
					bMatch = 0
					if _fts5ExprSynonymAdvanceto(tls, pTerm, bDesc, bp+8, bp) != 0 {
						(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = 0
						(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof = int32(1)
						return **(**int32)(__ccgo_up(bp))
					}
				} else {
					pIter = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr(j)*24))).FpIter
					if (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid == **(**Ti64)(__ccgo_up(bp + 8)) {
						goto _2
					}
					bMatch = 0
					if _fts5ExprAdvanceto(tls, pIter, bDesc, bp+8, bp, pNode+4) != 0 {
						return **(**int32)(__ccgo_up(bp))
					}
				}
				goto _2
			_2:
				;
				j = j + 1
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = **(**Ti64)(__ccgo_up(bp + 8))
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = libc.BoolInt32(0 == _fts5ExprNearTest(tls, bp, pExpr, pNode) && **(**int32)(__ccgo_up(bp)) == SQLITE_OK)
	return **(**int32)(__ccgo_up(bp))
}

func _fts5ExprNodeTest_TERM(tls *libc.TLS, pExpr uintptr, pNode uintptr) (r int32) {
	var pIter, pPhrase uintptr
	_, _ = pIter, pPhrase
	/* As this "NEAR" object is actually a single phrase that consists
	 ** of a single term only, grab pointers into the poslist managed by the
	 ** fts5_index.c iterator object. This is much faster than synthesizing
	 ** a new poslist the way we have to for more complicated phrase or NEAR
	 ** expressions.  */
	pPhrase = *(*uintptr)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear + 12))
	pIter = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FpIter
	(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FnData
	if (*TFts5Config)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FeDetail == FTS5_DETAIL_FULL {
		(*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fp = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FpData
	}
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid = (*TFts5IndexIter)(unsafe.Pointer(pIter)).FiRowid
	(*TFts5ExprNode)(unsafe.Pointer(pNode)).FbNomatch = libc.BoolInt32((*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn == 0)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Free the phrase object passed as the only argument.
//	*/
func _fts5ExprPhraseFree(tls *libc.TLS, pPhrase uintptr) {
	var i int32
	var pNext, pSyn, pTerm uintptr
	_, _, _, _ = i, pNext, pSyn, pTerm
	if pPhrase != 0 {
		i = 0
		for {
			if !(i < (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm) {
				break
			}
			pTerm = pPhrase + 20 + uintptr(i)*24
			Xsqlite3_free(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm)
			_sqlite3Fts5IterClose(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter)
			pSyn = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym
			for {
				if !(pSyn != 0) {
					break
				}
				pNext = (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpSynonym
				_sqlite3Fts5IterClose(tls, (*TFts5ExprTerm)(unsafe.Pointer(pSyn)).FpIter)
				_sqlite3Fts5BufferFree(tls, pSyn+1*24)
				Xsqlite3_free(tls, pSyn)
				goto _2
			_2:
				;
				pSyn = pNext
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		if (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.FnSpace > 0 {
			_sqlite3Fts5BufferFree(tls, pPhrase+4)
		}
		Xsqlite3_free(tls, pPhrase)
	}
}

// C documentation
//
//	/*
//	** Find a tokenizer. This is the implementation of the
//	** fts5_api.xFindTokenizer() method.
//	*/
func _fts5FindTokenizer(tls *libc.TLS, pApi uintptr, zName uintptr, ppUserData uintptr, pTokenizer uintptr) (r int32) {
	var pMod uintptr
	var rc int32
	_, _ = pMod, rc
	rc = SQLITE_OK
	pMod = _fts5LocateTokenizer(tls, pApi, zName)
	if pMod != 0 {
		if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native == 0 {
			**(**uintptr)(__ccgo_up(ppUserData)) = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData
		} else {
			**(**uintptr)(__ccgo_up(ppUserData)) = pMod
		}
		**(**Tfts5_tokenizer)(__ccgo_up(pTokenizer)) = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1
	} else {
		libc.Xmemset(tls, pTokenizer, 0, uint32(12))
		**(**uintptr)(__ccgo_up(ppUserData)) = uintptr(0)
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

// C documentation
//
//	/*
//	** Find a tokenizer. This is the implementation of the
//	** fts5_api.xFindTokenizer_v2() method.
//	*/
func _fts5FindTokenizer_v2(tls *libc.TLS, pApi uintptr, zName uintptr, ppUserData uintptr, ppTokenizer uintptr) (r int32) {
	var pMod uintptr
	var rc int32
	_, _ = pMod, rc
	rc = SQLITE_OK
	pMod = _fts5LocateTokenizer(tls, pApi, zName)
	if pMod != 0 {
		if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native != 0 {
			**(**uintptr)(__ccgo_up(ppUserData)) = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData
		} else {
			**(**uintptr)(__ccgo_up(ppUserData)) = pMod
		}
		**(**uintptr)(__ccgo_up(ppTokenizer)) = pMod + 24
	} else {
		**(**uintptr)(__ccgo_up(ppTokenizer)) = uintptr(0)
		**(**uintptr)(__ccgo_up(ppUserData)) = uintptr(0)
		rc = int32(SQLITE_ERROR)
	}
	return rc
}

// C documentation
//
//	/*
//	** Tokenizer callback used by implementation of highlight() function.
//	*/
func _fts5HighlightCb(tls *libc.TLS, pContext uintptr, tflags int32, pToken uintptr, nToken int32, iStartOff int32, iEndOff int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iPos, v1 int32
	var p, v2 uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _, _ = iPos, p, v1, v2
	p = pContext
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	_ = pToken
	_ = nToken
	if tflags&int32(FTS5_TOKEN_COLOCATED) != 0 {
		return SQLITE_OK
	}
	v2 = p + 52
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	iPos = v1
	if (*THighlightContext)(unsafe.Pointer(p)).FiRangeEnd >= 0 {
		if iPos < (*THighlightContext)(unsafe.Pointer(p)).FiRangeStart || iPos > (*THighlightContext)(unsafe.Pointer(p)).FiRangeEnd {
			return SQLITE_OK
		}
		if (*THighlightContext)(unsafe.Pointer(p)).FiRangeStart != 0 && iPos == (*THighlightContext)(unsafe.Pointer(p)).FiRangeStart {
			(*THighlightContext)(unsafe.Pointer(p)).FiOff = iStartOff
		}
	}
	/* If the parenthesis is open, and this token is not part of the current
	 ** phrase, and the starting byte offset of this token is past the point
	 ** that has currently been copied into the output buffer, close the
	 ** parenthesis. */
	if (*THighlightContext)(unsafe.Pointer(p)).FbOpen != 0 && (iPos <= (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart || (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart < 0) && iStartOff > (*THighlightContext)(unsafe.Pointer(p)).FiOff {
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzClose, -int32(1))
		(*THighlightContext)(unsafe.Pointer(p)).FbOpen = 0
	}
	/* If this is the start of a new phrase, and the highlight is not open:
	 **
	 **   * copy text from the input up to the start of the phrase, and
	 **   * open the highlight.
	 */
	if iPos == (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart && (*THighlightContext)(unsafe.Pointer(p)).FbOpen == 0 {
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iStartOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzOpen, -int32(1))
		(*THighlightContext)(unsafe.Pointer(p)).FiOff = iStartOff
		(*THighlightContext)(unsafe.Pointer(p)).FbOpen = int32(1)
	}
	if iPos == (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiEnd {
		if (*THighlightContext)(unsafe.Pointer(p)).FbOpen == 0 {
			_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzOpen, -int32(1))
			(*THighlightContext)(unsafe.Pointer(p)).FbOpen = int32(1)
		}
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
		(*THighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = _fts5CInstIterNext(tls, p+24)
		}
	}
	if iPos == (*THighlightContext)(unsafe.Pointer(p)).FiRangeEnd {
		if (*THighlightContext)(unsafe.Pointer(p)).FbOpen != 0 {
			if (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart >= 0 && iPos >= (*THighlightContext)(unsafe.Pointer(p)).Fiter.FiStart {
				_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
				(*THighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
			}
			_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzClose, -int32(1))
			(*THighlightContext)(unsafe.Pointer(p)).FbOpen = 0
		}
		_fts5HighlightAppend(tls, bp, p, (*THighlightContext)(unsafe.Pointer(p)).FzIn+uintptr((*THighlightContext)(unsafe.Pointer(p)).FiOff), iEndOff-(*THighlightContext)(unsafe.Pointer(p)).FiOff)
		(*THighlightContext)(unsafe.Pointer(p)).FiOff = iEndOff
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Array ap[] contains n elements. Release each of these elements using
//	** fts5DataRelease(). Then free the array itself using sqlite3_free().
//	*/
func _fts5IndexFreeArray(tls *libc.TLS, ap uintptr, n int32) {
	var ii int32
	_ = ii
	if ap != 0 {
		ii = 0
		for {
			if !(ii < n) {
				break
			}
			_fts5DataRelease(tls, **(**uintptr)(__ccgo_up(ap + uintptr(ii)*4)))
			goto _1
		_1:
			;
			ii = ii + 1
		}
		Xsqlite3_free(tls, ap)
	}
}

// C documentation
//
//	/*
//	** This function is the implementation of both the xConnect and xCreate
//	** methods of the FTS3 virtual table.
//	**
//	** The argv[] array contains the following:
//	**
//	**   argv[0]   -> module name  ("fts5")
//	**   argv[1]   -> database name
//	**   argv[2]   -> table name
//	**   argv[...] -> "column name" and other module argument fields.
//	*/
func _fts5InitVtab(tls *libc.TLS, bCreate int32, db uintptr, pAux uintptr, argc int32, argv uintptr, ppVTab uintptr, pzErr uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var azConfig, pGlobal, pTab uintptr
	var _ /* pConfig at bp+4 */ uintptr
	var _ /* rc at bp+0 */ int32
	_, _, _ = azConfig, pGlobal, pTab
	pGlobal = pAux
	azConfig = argv
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK        /* Return code */
	**(**uintptr)(__ccgo_up(bp + 4)) = uintptr(0) /* Results of parsing argc/argv */
	pTab = uintptr(0)                             /* New virtual table object */
	/* Allocate the new vtab object and parse the configuration */
	pTab = _sqlite3Fts5MallocZero(tls, bp, int64(36))
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5ConfigParse(tls, pGlobal, db, argc, azConfig, bp+4, pzErr)
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		(*TFts5Config)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 4)))).FpzErrmsg = pzErr
		(*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig = **(**uintptr)(__ccgo_up(bp + 4))
		(*TFts5FullTable)(unsafe.Pointer(pTab)).FpGlobal = pGlobal
		if bCreate != 0 || _sqlite3Fts5TokenizerPreload(tls, **(**uintptr)(__ccgo_up(bp + 4))+76) != 0 {
			**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5LoadTokenizer(tls, **(**uintptr)(__ccgo_up(bp + 4)))
		}
	}
	/* Open the index sub-system */
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5IndexOpen(tls, **(**uintptr)(__ccgo_up(bp + 4)), bCreate, pTab+16, pzErr)
	}
	/* Open the storage sub-system */
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5StorageOpen(tls, **(**uintptr)(__ccgo_up(bp + 4)), (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpIndex, bCreate, pTab+20, pzErr)
	}
	/* Call sqlite3_declare_vtab() */
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5ConfigDeclareVtab(tls, **(**uintptr)(__ccgo_up(bp + 4)))
	}
	/* Load the initial configuration */
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = _sqlite3Fts5ConfigLoad(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig, (*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FiCookie-int32(1))
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && (*TFts5Config)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 4)))).FeContent == FTS5_CONTENT_NORMAL {
		**(**int32)(__ccgo_up(bp)) = Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_CONSTRAINT_SUPPORT), libc.VaList(bp+16, libc.Int32FromInt32(1)))
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp)) = Xsqlite3_vtab_config(tls, db, int32(SQLITE_VTAB_INNOCUOUS), 0)
	}
	if **(**uintptr)(__ccgo_up(bp + 4)) != 0 {
		(*TFts5Config)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 4)))).FpzErrmsg = uintptr(0)
	}
	if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
		_fts5FreeVtab(tls, pTab)
		pTab = uintptr(0)
	} else {
		if bCreate != 0 {
		}
	}
	**(**uintptr)(__ccgo_up(ppVTab)) = pTab
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Tokenize using the porter tokenizer.
//	*/
func _fts5PorterTokenize(tls *libc.TLS, pTokenizer uintptr, pCtx uintptr, flags int32, pText uintptr, nText int32, pLoc uintptr, nLoc int32, __ccgo_fp_xToken uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var p uintptr
	var _ /* sCtx at bp+0 */ TPorterContext
	_ = p
	p = pTokenizer
	(**(**TPorterContext)(__ccgo_up(bp))).FxToken = __ccgo_fp_xToken
	(**(**TPorterContext)(__ccgo_up(bp))).FpCtx = pCtx
	(**(**TPorterContext)(__ccgo_up(bp))).FaBuf = p + 20
	return (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TPorterTokenizer)(unsafe.Pointer(p)).Ftokenizer_v2.FxTokenize})))(tls, (*TPorterTokenizer)(unsafe.Pointer(p)).FpTokenizer, bp, flags, pText, nText, pLoc, nLoc, __ccgo_fp(_fts5PorterCb))
}

// C documentation
//
//	/*
//	** Return true if zName is the extension on one of the shadow tables used
//	** by this module.
//	*/
func _fts5ShadowName(tls *libc.TLS, zName uintptr) (r int32) {
	var i uint32
	_ = i
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(20)/libc.Uint32FromInt64(4)) {
			break
		}
		if Xsqlite3_stricmp(tls, zName, _azName2[i]) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return 0
}

func _fts5SpecialDelete(tls *libc.TLS, pTab uintptr, apVal uintptr) (r int32) {
	var eType1, rc int32
	var iDel Tsqlite3_int64
	_, _, _ = eType1, iDel, rc
	rc = SQLITE_OK
	eType1 = Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(apVal + 1*4)))
	if eType1 == int32(SQLITE_INTEGER) {
		iDel = Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up(apVal + 1*4)))
		rc = _sqlite3Fts5StorageDelete(tls, (*TFts5FullTable)(unsafe.Pointer(pTab)).FpStorage, iDel, apVal+2*4, 0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Store the current contents of the p->nTotalRow and p->aTotalSize[]
//	** variables in the "averages" record on disk.
//	**
//	** Return SQLITE_OK if successful, or an SQLite error code if an error
//	** occurs.
//	*/
func _fts5StorageSaveTotals(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i, nCol int32
	var _ /* buf at bp+0 */ TFts5Buffer
	var _ /* rc at bp+12 */ int32
	_, _ = i, nCol
	nCol = (*TFts5Config)(unsafe.Pointer((*TFts5Storage)(unsafe.Pointer(p)).FpConfig)).FnCol
	**(**int32)(__ccgo_up(bp + 12)) = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint32(12))
	_sqlite3Fts5BufferAppendVarint(tls, bp+12, bp, (*TFts5Storage)(unsafe.Pointer(p)).FnTotalRow)
	i = 0
	for {
		if !(i < nCol) {
			break
		}
		_sqlite3Fts5BufferAppendVarint(tls, bp+12, bp, **(**Ti64)(__ccgo_up((*TFts5Storage)(unsafe.Pointer(p)).FaTotalSize + uintptr(i)*8)))
		goto _1
	_1:
		;
		i = i + 1
	}
	if **(**int32)(__ccgo_up(bp + 12)) == SQLITE_OK {
		**(**int32)(__ccgo_up(bp + 12)) = _sqlite3Fts5IndexSetAverages(tls, (*TFts5Storage)(unsafe.Pointer(p)).FpIndex, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp, (**(**TFts5Buffer)(__ccgo_up(bp))).Fn)
	}
	Xsqlite3_free(tls, (**(**TFts5Buffer)(__ccgo_up(bp))).Fp)
	return **(**int32)(__ccgo_up(bp + 12))
}

// C documentation
//
//	/*
//	** Implementation of xSync() method.
//	*/
func _fts5SyncMethod(tls *libc.TLS, pVtab uintptr) (r int32) {
	var pTab uintptr
	var rc int32
	_, _ = pTab, rc
	pTab = pVtab
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = pTab + 8
	rc = _sqlite3Fts5FlushToDisk(tls, pTab)
	(*TFts5Config)(unsafe.Pointer((*TFts5FullTable)(unsafe.Pointer(pTab)).Fp.FpConfig)).FpzErrmsg = uintptr(0)
	return rc
}

// C documentation
//
//	/*
//	** Argument pStmt is an SQL statement of the type used by Fts5Cursor. This
//	** function extracts the text value of column iCol of the current row.
//	** Additionally, if there is an associated locale, it invokes
//	** sqlite3Fts5SetLocale() to configure the tokenizer. In all cases the caller
//	** should invoke sqlite3Fts5ClearLocale() to clear the locale at some point
//	** after this function returns.
//	**
//	** If successful, (*ppText) is set to point to a buffer containing the text
//	** value as utf-8 and SQLITE_OK returned. (*pnText) is set to the size of that
//	** buffer in bytes. It is not guaranteed to be nul-terminated. If an error
//	** occurs, an SQLite error code is returned. The final values of the two
//	** output parameters are undefined in this case.
//	*/
func _fts5TextFromStmt(tls *libc.TLS, pConfig uintptr, pStmt uintptr, iCol int32, ppText uintptr, pnText uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pVal uintptr
	var rc int32
	var _ /* nLoc at bp+4 */ int32
	var _ /* pLoc at bp+0 */ uintptr
	_, _ = pVal, rc
	pVal = Xsqlite3_column_value(tls, pStmt, iCol+int32(1))
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**int32)(__ccgo_up(bp + 4)) = 0
	rc = SQLITE_OK
	if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == int32(FTS5_CONTENT_EXTERNAL) && _sqlite3Fts5IsLocaleValue(tls, pConfig, pVal) != 0 {
		rc = _sqlite3Fts5DecodeLocaleValue(tls, pVal, ppText, pnText, bp, bp+4)
	} else {
		**(**uintptr)(__ccgo_up(ppText)) = Xsqlite3_value_text(tls, pVal)
		**(**int32)(__ccgo_up(pnText)) = Xsqlite3_value_bytes(tls, pVal)
		if (*TFts5Config)(unsafe.Pointer(pConfig)).FbLocale != 0 && (*TFts5Config)(unsafe.Pointer(pConfig)).FeContent == FTS5_CONTENT_NORMAL {
			**(**uintptr)(__ccgo_up(bp)) = Xsqlite3_column_text(tls, pStmt, iCol+int32(1)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)
			**(**int32)(__ccgo_up(bp + 4)) = Xsqlite3_column_bytes(tls, pStmt, iCol+int32(1)+(*TFts5Config)(unsafe.Pointer(pConfig)).FnCol)
		}
	}
	_sqlite3Fts5SetLocale(tls, pConfig, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)))
	return rc
}

// C documentation
//
//	/*
//	** Delete an Fts5TokenDataIter structure and its contents.
//	*/
func _fts5TokendataIterDelete(tls *libc.TLS, pSet uintptr) {
	var ii int32
	_ = ii
	if pSet != 0 {
		ii = 0
		for {
			if !(int64(ii) < (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FnIter) {
				break
			}
			_fts5MultiIterFree(tls, *(*uintptr)(unsafe.Pointer(pSet + 56 + uintptr(ii)*4)))
			goto _1
		_1:
			;
			ii = ii + 1
		}
		_sqlite3Fts5BufferFree(tls, pSet+20)
		Xsqlite3_free(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FaPoslistReader)
		Xsqlite3_free(tls, (*TFts5TokenDataIter)(unsafe.Pointer(pSet)).FaMap)
		Xsqlite3_free(tls, pSet)
	}
}

// C documentation
//
//	/*
//	** The two input arrays - a1[] and a2[] - are in sorted order. This function
//	** merges the two arrays together and writes the result to output array
//	** aOut[]. aOut[] is guaranteed to be large enough to hold the result.
//	**
//	** Duplicate entries are copied into the output. So the size of the output
//	** array is always (n1+n2) entries.
//	*/
func _fts5TokendataMerge(tls *libc.TLS, a1 uintptr, n1 int32, a2 uintptr, n2 int32, aOut uintptr) {
	var i1, i2 int32
	var pOut uintptr
	_, _, _ = i1, i2, pOut
	i1 = 0
	i2 = 0
	for i1 < n1 || i2 < n2 {
		pOut = aOut + uintptr(i1+i2)*24
		if i2 >= n2 || i1 < n1 && ((**(**TFts5TokenDataMap)(__ccgo_up(a1 + uintptr(i1)*24))).FiRowid < (**(**TFts5TokenDataMap)(__ccgo_up(a2 + uintptr(i2)*24))).FiRowid || (**(**TFts5TokenDataMap)(__ccgo_up(a1 + uintptr(i1)*24))).FiRowid == (**(**TFts5TokenDataMap)(__ccgo_up(a2 + uintptr(i2)*24))).FiRowid && (**(**TFts5TokenDataMap)(__ccgo_up(a1 + uintptr(i1)*24))).FiPos <= (**(**TFts5TokenDataMap)(__ccgo_up(a2 + uintptr(i2)*24))).FiPos) {
			libc.Xmemcpy(tls, pOut, a1+uintptr(i1)*24, uint32(24))
			i1 = i1 + 1
		} else {
			libc.Xmemcpy(tls, pOut, a2+uintptr(i2)*24, uint32(24))
			i2 = i2 + 1
		}
	}
}

// C documentation
//
//	/*
//	** Decrement the ref-count of the object passed as the only argument. If it
//	** reaches 0, free it and its contents.
//	*/
func _fts5TombstoneArrayDelete(tls *libc.TLS, p uintptr) {
	var ii int32
	_ = ii
	if p != 0 {
		(*TFts5TombstoneArray)(unsafe.Pointer(p)).FnRef = (*TFts5TombstoneArray)(unsafe.Pointer(p)).FnRef - 1
		if (*TFts5TombstoneArray)(unsafe.Pointer(p)).FnRef <= 0 {
			ii = 0
			for {
				if !(ii < (*TFts5TombstoneArray)(unsafe.Pointer(p)).FnTombstone) {
					break
				}
				_fts5DataRelease(tls, *(*uintptr)(unsafe.Pointer(p + 8 + uintptr(ii)*4)))
				goto _1
			_1:
				;
				ii = ii + 1
			}
			Xsqlite3_free(tls, p)
		}
	}
}

// C documentation
//
//	/*
//	** Close the cursor.  For additional information see the documentation
//	** on the xClose method of the virtual table interface.
//	*/
func _fts5VocabCloseMethod(tls *libc.TLS, pCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = pCursor
	_fts5VocabResetCursor(tls, pCsr)
	_sqlite3Fts5BufferFree(tls, pCsr+56)
	Xsqlite3_finalize(tls, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpStmt)
	Xsqlite3_free(tls, pCsr)
	return SQLITE_OK
}

func _fts5VocabColumnMethod(tls *libc.TLS, pCursor uintptr, pCtx uintptr, iCol int32) (r int32) {
	var eDetail, eType, ii, ii1 int32
	var iVal Ti64
	var pCsr, z, z1 uintptr
	_, _, _, _, _, _, _, _ = eDetail, eType, iVal, ii, ii1, pCsr, z, z1
	pCsr = pCursor
	eDetail = (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FeDetail
	eType = (*TFts5VocabTable)(unsafe.Pointer((*Tsqlite3_vtab_cursor)(unsafe.Pointer(pCursor)).FpVtab)).FeType
	iVal = 0
	if iCol == 0 {
		Xsqlite3_result_text(tls, pCtx, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fp, (*TFts5VocabCursor)(unsafe.Pointer(pCsr)).Fterm.Fn, uintptr(-libc.Int32FromInt32(1)))
	} else {
		if eType == FTS5_VOCAB_COL {
			if iCol == int32(1) {
				if eDetail != int32(FTS5_DETAIL_NONE) {
					z = **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FazCol + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*4))
					Xsqlite3_result_text(tls, pCtx, z, -int32(1), libc.UintptrFromInt32(0))
				}
			} else {
				if iCol == int32(2) {
					iVal = **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8))
				} else {
					iVal = **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt + uintptr((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiCol)*8))
				}
			}
		} else {
			if eType == int32(FTS5_VOCAB_ROW) {
				if iCol == int32(1) {
					iVal = **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaDoc))
				} else {
					iVal = **(**Ti64)(__ccgo_up((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FaCnt))
				}
			} else {
				switch iCol {
				case int32(1):
					Xsqlite3_result_int64(tls, pCtx, (*TFts5IndexIter)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpIter)).FiRowid)
				case int32(2):
					ii = -int32(1)
					if eDetail == FTS5_DETAIL_FULL {
						ii = int32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos >> libc.Int32FromInt32(32) & libc.Int64FromInt32(0x7FFFFFFF))
					} else {
						if eDetail == int32(FTS5_DETAIL_COLUMNS) {
							ii = int32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos)
						}
					}
					if ii >= 0 && ii < (*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FnCol {
						z1 = **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer((*TFts5Table)(unsafe.Pointer((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FpFts5)).FpConfig)).FazCol + uintptr(ii)*4))
						Xsqlite3_result_text(tls, pCtx, z1, -int32(1), libc.UintptrFromInt32(0))
					}
				default:
					if eDetail == FTS5_DETAIL_FULL {
						ii1 = int32((*TFts5VocabCursor)(unsafe.Pointer(pCsr)).FiInstPos & libc.Int64FromInt32(0x7FFFFFFF))
						Xsqlite3_result_int(tls, pCtx, ii1)
					}
					break
				}
			}
		}
	}
	if iVal > 0 {
		Xsqlite3_result_int64(tls, pCtx, iVal)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Create a wrapper tokenizer. The context argument pCtx points to the
//	** Fts5TokenizerModule object.
//	*/
func _fts5VtoVCreate(tls *libc.TLS, pCtx uintptr, azArg uintptr, nArg int32, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pMod, pNew uintptr
	var _ /* rc at bp+0 */ int32
	_, _ = pMod, pNew
	pMod = pCtx
	pNew = uintptr(0)
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	pNew = _sqlite3Fts5MallocZero(tls, bp, int64(36))
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		(*TFts5VtoVTokenizer)(unsafe.Pointer(pNew)).Fx1 = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1
		(*TFts5VtoVTokenizer)(unsafe.Pointer(pNew)).Fx2 = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx2
		(*TFts5VtoVTokenizer)(unsafe.Pointer(pNew)).FbV2Native = (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native
		if (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FbV2Native != 0 {
			**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx2.FxCreate})))(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData, azArg, nArg, pNew+32)
		} else {
			**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TFts5TokenizerModule)(unsafe.Pointer(pMod)).Fx1.FxCreate})))(tls, (*TFts5TokenizerModule)(unsafe.Pointer(pMod)).FpUserData, azArg, nArg, pNew+32)
		}
		if **(**int32)(__ccgo_up(bp)) != SQLITE_OK {
			Xsqlite3_free(tls, pNew)
			pNew = uintptr(0)
		}
	}
	**(**uintptr)(__ccgo_up(ppOut)) = pNew
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Pop the parser's stack once.
//	**
//	** If there is a destructor routine associated with the token which
//	** is popped from the stack, then call it.
//	*/
func _fts5yy_pop_parser_stack(tls *libc.TLS, pParser uintptr) {
	var fts5yytos, v1, v2 uintptr
	_, _, _ = fts5yytos, v1, v2
	v2 = pParser
	v1 = *(*uintptr)(unsafe.Pointer(v2))
	*(*uintptr)(unsafe.Pointer(v2)) -= 12
	fts5yytos = v1
	_fts5yy_destructor(tls, pParser, (*Tfts5yyStackEntry)(unsafe.Pointer(fts5yytos)).Fmajor, fts5yytos+4)
}

// C documentation
//
//	/*
//	** Invoke the destructor function associated with FuncDef p, if any. Except,
//	** if this is not the last copy of the function, do not invoke it. Multiple
//	** copies of a single function are created when create_function() is called
//	** with SQLITE_ANY as the encoding.
//	*/
func _functionDestroy(tls *libc.TLS, db uintptr, p uintptr) {
	var pDestructor uintptr
	_ = pDestructor
	pDestructor = *(*uintptr)(unsafe.Pointer(p + 36))
	if pDestructor != 0 {
		(*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef = (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef - 1
		if (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FnRef == 0 {
			(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDestructor)(unsafe.Pointer(pDestructor)).FxDestroy})))(tls, (*TFuncDestructor)(unsafe.Pointer(pDestructor)).FpUserData)
			_sqlite3DbFree(tls, db, pDestructor)
		}
	}
}

func _gatherSelectWindows(tls *libc.TLS, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_gatherSelectWindowsCallback)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_gatherSelectWindowsSelectCallback)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = uintptr(0)
	(**(**TWalker)(__ccgo_up(bp))).FpParse = uintptr(0)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = p
	_sqlite3WalkSelect(tls, bp, p)
}

func _gatherSelectWindowsSelectCallback(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var v1 int32
	_ = v1
	if p == *(*uintptr)(unsafe.Pointer(pWalker + 24)) {
		v1 = WRC_Continue
	} else {
		v1 = int32(WRC_Prune)
	}
	return v1
}

// C documentation
//
//	/*
//	** Generate code that will tell the VDBE the declaration types of columns
//	** in the result set.
//	*/
func _generateColumnTypes(tls *libc.TLS, pParse uintptr, pTabList uintptr, pEList uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var p, v, zType uintptr
	var _ /* sNC at bp+0 */ TNameContext
	var _ /* zOrigCol at bp+44 */ uintptr
	var _ /* zOrigDb at bp+36 */ uintptr
	var _ /* zOrigTab at bp+40 */ uintptr
	_, _, _, _ = i, p, v, zType
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = pTabList
	(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
	(**(**TNameContext)(__ccgo_up(bp))).FpNext = uintptr(0)
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		p = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr
		**(**uintptr)(__ccgo_up(bp + 36)) = uintptr(0)
		**(**uintptr)(__ccgo_up(bp + 40)) = uintptr(0)
		**(**uintptr)(__ccgo_up(bp + 44)) = uintptr(0)
		zType = _columnTypeImpl(tls, bp, p, bp+36, bp+40, bp+44)
		/* The vdbe must make its own copy of the column-type and other
		 ** column specific strings, in case the schema is reset before this
		 ** virtual machine is deleted.
		 */
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_DATABASE), **(**uintptr)(__ccgo_up(bp + 36)), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_TABLE), **(**uintptr)(__ccgo_up(bp + 40)), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_COLUMN), **(**uintptr)(__ccgo_up(bp + 44)), uintptr(-libc.Int32FromInt32(1)))
		_sqlite3VdbeSetColName(tls, v, i, int32(COLNAME_DECLTYPE), zType, uintptr(-libc.Int32FromInt32(1)))
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** Implementation of the geopoly_group_bbox(X) aggregate SQL function.
//	*/
func _geopolyBBoxStep(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var pBBox uintptr
	var _ /* a at bp+0 */ [4]TRtreeCoord
	var _ /* rc at bp+16 */ int32
	_ = pBBox
	**(**int32)(__ccgo_up(bp + 16)) = SQLITE_OK
	_ = argc
	_geopolyBBox(tls, context, **(**uintptr)(__ccgo_up(argv)), bp, bp+16)
	if **(**int32)(__ccgo_up(bp + 16)) == SQLITE_OK {
		pBBox = Xsqlite3_aggregate_context(tls, context, int32(20))
		if pBBox == uintptr(0) {
			return
		}
		if libc.AtomicLoadPInt32(pBBox) == 0 {
			libc.AtomicStorePInt32(pBBox, int32(1))
			libc.Xmemcpy(tls, pBBox+4, bp, libc.Uint32FromInt64(4)*libc.Uint32FromInt32(4))
		} else {
			if *(*TRtreeValue)(unsafe.Pointer(bp)) < *(*TRtreeValue)(unsafe.Pointer(pBBox + 4)) {
				**(**TRtreeCoord)(__ccgo_up(pBBox + 4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[0]
			}
			if *(*TRtreeValue)(unsafe.Pointer(bp + 1*4)) > *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 1*4)) {
				**(**TRtreeCoord)(__ccgo_up(pBBox + 4 + 1*4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[int32(1)]
			}
			if *(*TRtreeValue)(unsafe.Pointer(bp + 2*4)) < *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 2*4)) {
				**(**TRtreeCoord)(__ccgo_up(pBBox + 4 + 2*4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[int32(2)]
			}
			if *(*TRtreeValue)(unsafe.Pointer(bp + 3*4)) > *(*TRtreeValue)(unsafe.Pointer(pBBox + 4 + 3*4)) {
				**(**TRtreeCoord)(__ccgo_up(pBBox + 4 + 3*4)) = (**(**[4]TRtreeCoord)(__ccgo_up(bp)))[int32(3)]
			}
		}
	}
}

// C documentation
//
//	/*
//	** SQL function:    geopoly_contains_point(P,X,Y)
//	**
//	** Return +2 if point X,Y is within polygon P.
//	** Return +1 if point X,Y is on the polygon boundary.
//	** Return 0 if point X,Y is outside the polygon
//	*/
func _geopolyContainsPointFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var cnt, ii, v int32
	var p1 uintptr
	var x0, y0 float64
	_, _, _, _, _, _ = cnt, ii, p1, v, x0, y0
	p1 = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
	x0 = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
	y0 = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 2*4)))
	v = 0
	cnt = 0
	_ = argc
	if p1 == uintptr(0) {
		return
	}
	ii = 0
	for {
		if !(ii < (*TGeoPoly)(unsafe.Pointer(p1)).FnVertex-int32(1)) {
			break
		}
		v = _pointBeneathLine(tls, x0, y0, float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr(ii*int32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr(ii*int32(2)+int32(1))*4))), float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr((ii+int32(1))*int32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr((ii+int32(1))*int32(2)+int32(1))*4))))
		if v == int32(2) {
			break
		}
		cnt = cnt + v
		goto _1
	_1:
		;
		ii = ii + 1
	}
	if v != int32(2) {
		v = _pointBeneathLine(tls, x0, y0, float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr(ii*int32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr(ii*int32(2)+int32(1))*4))), float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2))*4))), float64(**(**TGeoCoord)(__ccgo_up(p1 + 8 + uintptr(libc.Int32FromInt32(0)*libc.Int32FromInt32(2)+libc.Int32FromInt32(1))*4))))
	}
	if v == int32(2) {
		Xsqlite3_result_int(tls, context, int32(1))
	} else {
		if (v+cnt)&int32(1) == 0 {
			Xsqlite3_result_int(tls, context, 0)
		} else {
			Xsqlite3_result_int(tls, context, int32(2))
		}
	}
	Xsqlite3_free(tls, p1)
}

// C documentation
//
//	/*
//	** SQL function:    geopoly_overlap(P1,P2)
//	**
//	** Determine whether or not P1 and P2 overlap. Return value:
//	**
//	**   0     The two polygons are disjoint
//	**   1     They overlap
//	**   2     P1 is completely contained within P2
//	**   3     P2 is completely contained within P1
//	**   4     P1 and P2 are the same polygon
//	**   NULL  Either P1 or P2 or both are not valid polygons
//	*/
func _geopolyOverlapFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p1, p2 uintptr
	var x int32
	_, _, _ = p1, p2, x
	p1 = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
	p2 = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv + 1*4)), uintptr(0))
	_ = argc
	if p1 != 0 && p2 != 0 {
		x = _geopolyOverlap(tls, p1, p2)
		if x < 0 {
			Xsqlite3_result_error_nomem(tls, context)
		} else {
			Xsqlite3_result_int(tls, context, x)
		}
	}
	Xsqlite3_free(tls, p1)
	Xsqlite3_free(tls, p2)
}

// C documentation
//
//	/*
//	** SQL function:    geopoly_within(P1,P2)
//	**
//	** Return +2 if P1 and P2 are the same polygon
//	** Return +1 if P2 is contained within P1
//	** Return 0 if any part of P2 is on the outside of P1
//	**
//	*/
func _geopolyWithinFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var p1, p2 uintptr
	var x, v1, v2 int32
	_, _, _, _, _ = p1, p2, x, v1, v2
	p1 = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
	p2 = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv + 1*4)), uintptr(0))
	_ = argc
	if p1 != 0 && p2 != 0 {
		x = _geopolyOverlap(tls, p1, p2)
		if x < 0 {
			Xsqlite3_result_error_nomem(tls, context)
		} else {
			if x == int32(2) {
				v1 = int32(1)
			} else {
				if x == int32(4) {
					v2 = int32(2)
				} else {
					v2 = 0
				}
				v1 = v2
			}
			Xsqlite3_result_int(tls, context, v1)
		}
	}
	Xsqlite3_free(tls, p1)
	Xsqlite3_free(tls, p2)
}

// C documentation
//
//	/*
//	** SQL Function:      geopoly_xform(poly, A, B, C, D, E, F)
//	**
//	** Transform and/or translate a polygon as follows:
//	**
//	**      x1 = A*x0 + B*y0 + E
//	**      y1 = C*x0 + D*y0 + F
//	**
//	** For a translation:
//	**
//	**      geopoly_xform(poly, 1, 0, 0, 1, x-offset, y-offset)
//	**
//	** Rotate by R around the point (0,0):
//	**
//	**      geopoly_xform(poly, cos(R), sin(R), -sin(R), cos(R), 0, 0)
//	*/
func _geopolyXformFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var A, B, C, D, E, F float64
	var ii int32
	var p uintptr
	var x0, x1, y0, y1 TGeoCoord
	_, _, _, _, _, _, _, _, _, _, _, _ = A, B, C, D, E, F, ii, p, x0, x1, y0, y1
	p = _geopolyFuncParam(tls, context, **(**uintptr)(__ccgo_up(argv)), uintptr(0))
	A = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
	B = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 2*4)))
	C = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 3*4)))
	D = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 4*4)))
	E = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 5*4)))
	F = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 6*4)))
	_ = argc
	if p != 0 {
		ii = 0
		for {
			if !(ii < (*TGeoPoly)(unsafe.Pointer(p)).FnVertex) {
				break
			}
			x0 = **(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2))*4))
			y0 = **(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2)+int32(1))*4))
			x1 = float32(float64(A*float64(x0)) + float64(B*float64(y0)) + E)
			y1 = float32(float64(C*float64(x0)) + float64(D*float64(y0)) + F)
			**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2))*4)) = x1
			**(**TGeoCoord)(__ccgo_up(p + 8 + uintptr(ii*int32(2)+int32(1))*4)) = y1
			goto _1
		_1:
			;
			ii = ii + 1
		}
		Xsqlite3_result_blob(tls, context, p+4, int32(4)+int32(8)*(*TGeoPoly)(unsafe.Pointer(p)).FnVertex, uintptr(-libc.Int32FromInt32(1)))
		Xsqlite3_free(tls, p)
	}
}

func _getDoubleArg(tls *libc.TLS, p uintptr) (r float64) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if (*TPrintfArguments)(unsafe.Pointer(p)).FnArg <= (*TPrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return float64(0)
	}
	v2 = p + 4
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	return Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up((*TPrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(v1)*4)))
}

// C documentation
//
//	/*
//	** Extra argument values from a PrintfArguments object
//	*/
func _getIntArg(tls *libc.TLS, p uintptr) (r Tsqlite3_int64) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if (*TPrintfArguments)(unsafe.Pointer(p)).FnArg <= (*TPrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return 0
	}
	v2 = p + 4
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	return Xsqlite3_value_int64(tls, **(**uintptr)(__ccgo_up((*TPrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(v1)*4)))
}

func _getTextArg(tls *libc.TLS, p uintptr) (r uintptr) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if (*TPrintfArguments)(unsafe.Pointer(p)).FnArg <= (*TPrintfArguments)(unsafe.Pointer(p)).FnUsed {
		return uintptr(0)
	}
	v2 = p + 4
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	return Xsqlite3_value_text(tls, **(**uintptr)(__ccgo_up((*TPrintfArguments)(unsafe.Pointer(p)).FapArg + uintptr(v1)*4)))
}

// C documentation
//
//	/*
//	** Transfer eligible terms from the HAVING clause of a query, which is
//	** processed after grouping, to the WHERE clause, which is processed before
//	** grouping. For example, the query:
//	**
//	**   SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
//	**
//	** can be rewritten as:
//	**
//	**   SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
//	**
//	** A term of the HAVING expression is eligible for transfer if it consists
//	** entirely of constants and expressions that are also GROUP BY terms that
//	** use the "BINARY" collation sequence.
//	*/
func _havingToWhere(tls *libc.TLS, pParse uintptr, p uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* sWalker at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_havingToWhereExprCb)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = p
	_sqlite3WalkExpr(tls, bp, (*TSelect)(unsafe.Pointer(p)).FpHaving)
}

func _heightOfExprList(tls *libc.TLS, p uintptr, pnHeight uintptr) {
	var i int32
	_ = i
	if p != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(p)).FnExpr) {
				break
			}
			_heightOfExpr(tls, (*(*TExprList_item)(unsafe.Pointer(p + 8 + uintptr(i)*20))).FpExpr, pnHeight)
			goto _1
		_1:
			;
			i = i + 1
		}
	}
}

// C documentation
//
//	/*
//	** Check the N SrcItem objects to the right of pBase.  (N might be zero!)
//	** If any of those SrcItem objects have a USING clause containing zName
//	** then return true.
//	**
//	** If N is zero, or none of the N SrcItem objects to the right of pBase
//	** contains a USING clause, or if none of the USING clauses contain zName,
//	** then return false.
//	*/
func _inAnyUsingClause(tls *libc.TLS, zName uintptr, pBase uintptr, N int32) (r int32) {
	for N > 0 {
		N = N - 1
		pBase += 48
		if int32(*(*uint32)(unsafe.Pointer(pBase + 12 + 4))&0x800>>11) == 0 {
			continue
		}
		if *(*uintptr)(unsafe.Pointer(pBase + 40)) == uintptr(0) {
			continue
		}
		if _sqlite3IdListIndex(tls, *(*uintptr)(unsafe.Pointer(pBase + 40)), zName) >= 0 {
			return int32(1)
		}
	}
	return 0
}

func _incrAggFunctionDepth(tls *libc.TLS, pExpr uintptr, N int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	if N > 0 {
		libc.Xmemset(tls, bp, 0, uint32(28))
		(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_incrAggDepth)
		*(*int32)(unsafe.Pointer(bp + 24)) = N
		_sqlite3WalkExpr(tls, bp, pExpr)
	}
}

// C documentation
//
//	/*
//	** Check to see if column iCol of index pIdx references any of the
//	** columns defined by aXRef and chngRowid.  Return true if it does
//	** and false if not.  This is an optimization.  False-positives are a
//	** performance degradation, but false-negatives can result in a corrupt
//	** index and incorrect answers.
//	**
//	** aXRef[j] will be non-negative if column j of the original table is
//	** being updated.  chngRowid will be true if the rowid of the table is
//	** being updated.
//	*/
func _indexColumnIsBeingUpdated(tls *libc.TLS, pIdx uintptr, iCol int32, aXRef uintptr, chngRowid int32) (r int32) {
	var iIdxCol Ti16
	_ = iIdxCol
	iIdxCol = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2))
	/* Cannot index rowid */
	if int32(iIdxCol) >= 0 {
		return libc.BoolInt32(**(**int32)(__ccgo_up(aXRef + uintptr(iIdxCol)*4)) >= 0)
	}
	return _sqlite3ExprReferencesUpdatedColumn(tls, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(iCol)*20))).FpExpr, aXRef, chngRowid)
}

// C documentation
//
//	/*
//	** Return TRUE if the iCol-th column of index pIdx is NOT NULL
//	*/
func _indexColumnNotNull(tls *libc.TLS, pIdx uintptr, iCol int32) (r int32) {
	var j int32
	_ = j
	j = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iCol)*2)))
	if j >= 0 {
		return int32(uint32(*(*uint8)(unsafe.Pointer((*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FpTable)).FaCol + uintptr(j)*12 + 4)) & 0xf >> 0))
	} else {
		if j == -int32(1) {
			return int32(1)
		} else {
			return 0 /* Assume an indexed expression can always yield a NULL */
		}
	}
	return r
}

// C documentation
//
//	/* Return the next index from the list.  Return NULL when out of indexes */
func _indexIteratorNext(tls *libc.TLS, pIter uintptr, pIx uintptr) (r uintptr) {
	var i, v1 int32
	var v2 uintptr
	_, _, _ = i, v1, v2
	if (*TIndexIterator)(unsafe.Pointer(pIter)).FeType != 0 {
		v2 = pIter + 4
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		v1 = *(*int32)(unsafe.Pointer(v2))
		i = v1
		if i >= (*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FnIdx {
			**(**int32)(__ccgo_up(pIx)) = i
			return uintptr(0)
		}
		**(**int32)(__ccgo_up(pIx)) = (**(**TIndexListTerm)(__ccgo_up((*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FaIdx + uintptr(i)*8))).Fix
		return (**(**TIndexListTerm)(__ccgo_up((*(*struct {
			FnIdx int32
			FaIdx uintptr
		})(unsafe.Pointer(pIter + 8))).FaIdx + uintptr(i)*8))).Fp
	} else {
		**(**int32)(__ccgo_up(pIx)) = **(**int32)(__ccgo_up(pIx)) + 1
		(*TIndexIterator)(unsafe.Pointer(pIter)).Fu.Flx.FpIdx = (*TIndex)(unsafe.Pointer((*TIndexIterator)(unsafe.Pointer(pIter)).Fu.Flx.FpIdx)).FpNext
		return (*TIndexIterator)(unsafe.Pointer(pIter)).Fu.Flx.FpIdx
	}
	return r
}

// C documentation
//
//	/*
//	** Initialize an array of N Mem element.
//	**
//	** This is a high-runner, so only those fields that really do need to
//	** be initialized are set.  The Mem structure is organized so that
//	** the fields that get initialized are nearby and hopefully on the same
//	** cache line.
//	**
//	**    Mem.flags = flags
//	**    Mem.db = db
//	**    Mem.szMalloc = 0
//	**
//	** All other fields of Mem can safely remain uninitialized for now.  They
//	** will be initialized before use.
//	*/
func _initMemArray(tls *libc.TLS, p uintptr, N int32, db uintptr, flags Tu16) {
	var v1 int32
	_ = v1
	if N > 0 {
		for {
			(*TMem)(unsafe.Pointer(p)).Fflags = flags
			(*TMem)(unsafe.Pointer(p)).Fdb = db
			(*TMem)(unsafe.Pointer(p)).FszMalloc = 0
			p += 40
			goto _2
		_2:
			;
			N = N - 1
			v1 = N
			if !(v1 > 0) {
				break
			}
		}
	}
}

// C documentation
//
//	/*
//	** Return true if any of the first nKey entries of index pIdx exactly
//	** match the iCol-th entry of pPk.  pPk is always a WITHOUT ROWID
//	** PRIMARY KEY index.  pIdx is an index on the same table.  pIdx may
//	** or may not be the same index as pPk.
//	**
//	** The first nKey entries of pIdx are guaranteed to be ordinary columns,
//	** not a rowid or expression.
//	**
//	** This routine differs from hasColumn() in that both the column and the
//	** collating sequence must match for this routine, but for hasColumn() only
//	** the column name must match.
//	*/
func _isDupColumn(tls *libc.TLS, pIdx uintptr, nKey int32, pPk uintptr, iCol int32) (r int32) {
	var i, j int32
	_, _ = i, j
	j = int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FaiColumn + uintptr(iCol)*2)))
	i = 0
	for {
		if !(i < nKey) {
			break
		}
		if int32(**(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(i)*2))) == j && _sqlite3StrICmp(tls, **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FazColl + uintptr(i)*4)), **(**uintptr)(__ccgo_up((*TIndex)(unsafe.Pointer(pPk)).FazColl + uintptr(iCol)*4))) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** TRUE if p is a lookaside memory allocation from db
//	*/
func _isLookaside(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	return libc.BoolInt32(uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) && uint32(p) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpTrueEnd))
}

// C documentation
//
//	/*
//	** Check to see if the pThis entry of pTabList is a self-join of another view.
//	** Search FROM-clause entries in the range of iFirst..iEnd, including iFirst
//	** but stopping before iEnd.
//	**
//	** If pThis is a self-join, then return the SrcItem for the first other
//	** instance of that view found.  If pThis is not a self-join then return 0.
//	*/
func _isSelfJoinView(tls *libc.TLS, pTabList uintptr, pThis uintptr, iFirst int32, iEnd int32) (r uintptr) {
	var pItem, pS1, pSel uintptr
	var v1 int32
	_, _, _, _ = pItem, pS1, pSel, v1
	pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pThis + 44)))).FpSelect
	if (*TSelect)(unsafe.Pointer(pSel)).FselFlags&uint32(SF_PushDown) != 0 {
		return uintptr(0)
	}
	for iFirst < iEnd {
		v1 = iFirst
		iFirst = iFirst + 1
		pItem = pTabList + 8 + uintptr(v1)*48
		if !(int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0) {
			continue
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x40>>6) != 0 {
			continue
		}
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzName == uintptr(0) {
			continue
		}
		if (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FpSchema != (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pThis)).FpSTab)).FpSchema {
			continue
		}
		if Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(pItem)).FzName, (*TSrcItem)(unsafe.Pointer(pThis)).FzName) != 0 {
			continue
		}
		pS1 = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect
		if (*TTable)(unsafe.Pointer((*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)).FpSchema == uintptr(0) && (*TSelect)(unsafe.Pointer(pSel)).FselId != (*TSelect)(unsafe.Pointer(pS1)).FselId {
			/* The query flattener left two different CTE tables with identical
			 ** names in the same FROM clause. */
			continue
		}
		if (*TSelect)(unsafe.Pointer(pS1)).FselFlags&uint32(SF_PushDown) != 0 {
			/* The view was modified by some other optimization such as
			 ** pushDownWhereTerms() */
			continue
		}
		return pItem
	}
	return uintptr(0)
}

func _jsonAppendRaw(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
	if N == uint32(0) {
		return
	}
	if uint64(N)+(*TJsonString)(unsafe.Pointer(p)).FnUsed >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
		_jsonStringExpandAndAppend(tls, p, zIn, N)
	} else {
		libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, N)
		**(**Tu64)(__ccgo_up(p + 16)) += uint64(N)
	}
}

func _jsonAppendRawNZ(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
	if uint64(N)+(*TJsonString)(unsafe.Pointer(p)).FnUsed >= (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
		_jsonStringExpandAndAppend(tls, p, zIn, N)
	} else {
		libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, N)
		**(**Tu64)(__ccgo_up(p + 16)) += uint64(N)
	}
}

// C documentation
//
//	/* Append a single character.
//	*/
func _jsonBlobAppendOneByte(tls *libc.TLS, pParse uintptr, c Tu8) {
	var v1 Tu32
	var v2 uintptr
	_, _ = v1, v2
	if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob >= (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc {
		_jsonBlobExpandAndAppendOneByte(tls, pParse, c)
	} else {
		v2 = pParse + 4
		v1 = *(*Tu32)(unsafe.Pointer(v2))
		*(*Tu32)(unsafe.Pointer(v2)) = *(*Tu32)(unsafe.Pointer(v2)) + 1
		**(**Tu8)(__ccgo_up((*TJsonParse)(unsafe.Pointer(pParse)).FaBlob + uintptr(v1))) = c
	}
}

// C documentation
//
//	/*
//	** If pParse->aBlob is not previously editable (because it is taken
//	** from sqlite3_value_blob(), as indicated by the fact that
//	** pParse->nBlobAlloc==0 and pParse->nBlob>0) then make it editable
//	** by making a copy into space obtained from malloc.
//	**
//	** Return true on success.  Return false on OOM.
//	*/
func _jsonBlobMakeEditable(tls *libc.TLS, pParse uintptr, nExtra Tu32) (r int32) {
	var aOld uintptr
	var nSize Tu32
	_, _ = aOld, nSize
	if (*TJsonParse)(unsafe.Pointer(pParse)).Foom != 0 {
		return 0
	}
	if (*TJsonParse)(unsafe.Pointer(pParse)).FnBlobAlloc > uint32(0) {
		return int32(1)
	}
	aOld = (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob
	nSize = (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob + nExtra
	(*TJsonParse)(unsafe.Pointer(pParse)).FaBlob = uintptr(0)
	if _jsonBlobExpand(tls, pParse, nSize) != 0 {
		return 0
	}
	libc.Xmemcpy(tls, (*TJsonParse)(unsafe.Pointer(pParse)).FaBlob, aOld, (*TJsonParse)(unsafe.Pointer(pParse)).FnBlob)
	return int32(1)
}

// C documentation
//
//	/*
//	** Free a JsonCache object.
//	*/
func _jsonCacheDelete(tls *libc.TLS, p uintptr) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TJsonCache)(unsafe.Pointer(p)).FnUsed) {
			break
		}
		_jsonParseFree(tls, **(**uintptr)(__ccgo_up(p + 8 + uintptr(i)*4)))
		goto _1
	_1:
		;
		i = i + 1
	}
	_sqlite3DbFree(tls, (*TJsonCache)(unsafe.Pointer(p)).Fdb, p)
}

// C documentation
//
//	/* Reset a JsonEachCursor back to its original state.  Free any memory
//	** held. */
func _jsonEachCursorReset(tls *libc.TLS, p uintptr) {
	_jsonParseReset(tls, p+168)
	_jsonStringReset(tls, p+40)
	_sqlite3DbFree(tls, (*TJsonEachCursor)(unsafe.Pointer(p)).Fdb, (*TJsonEachCursor)(unsafe.Pointer(p)).FaParent)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FiRowid = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).Fi = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FaParent = uintptr(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FnParent = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FnParentAlloc = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FiEnd = uint32(0)
	(*TJsonEachCursor)(unsafe.Pointer(p)).FeType = uint8(0)
}

// C documentation
//
//	/* constructor for a JsonEachCursor object for json_each()/json_tree(). */
func _jsonEachOpen(tls *libc.TLS, p uintptr, ppCursor uintptr) (r int32) {
	var pCur, pVtab uintptr
	_, _ = pCur, pVtab
	pVtab = p
	_ = p
	pCur = _sqlite3DbMallocZero(tls, (*TJsonEachConnection)(unsafe.Pointer(pVtab)).Fdb, uint64(224))
	if pCur == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	(*TJsonEachCursor)(unsafe.Pointer(pCur)).Fdb = (*TJsonEachConnection)(unsafe.Pointer(pVtab)).Fdb
	(*TJsonEachCursor)(unsafe.Pointer(pCur)).FeMode = (*TJsonEachConnection)(unsafe.Pointer(pVtab)).FeMode
	(*TJsonEachCursor)(unsafe.Pointer(pCur)).FbRecursive = (*TJsonEachConnection)(unsafe.Pointer(pVtab)).FbRecursive
	_jsonStringZero(tls, pCur+40)
	**(**uintptr)(__ccgo_up(ppCursor)) = pCur
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Compare two object labels.  Return 1 if they are equal and
//	** 0 if they differ.  Return -1 if an OOM occurs.
//	*/
func _jsonLabelCompare(tls *libc.TLS, zLeft uintptr, nLeft Tu32, rawLeft int32, zRight uintptr, nRight Tu32, rawRight int32) (r int32) {
	if rawLeft != 0 && rawRight != 0 {
		/* Simpliest case:  Neither label contains escapes.  A simple
		 ** memcmp() is sufficient. */
		if nLeft != nRight {
			return 0
		}
		return libc.BoolInt32(libc.Xmemcmp(tls, zLeft, zRight, nLeft) == 0)
	} else {
		return _jsonLabelCompareEscaped(tls, zLeft, nLeft, rawLeft, zRight, nRight, rawRight)
	}
	return r
}

// C documentation
//
//	/*
//	** Implementation of the json_quote(VALUE) function.  Return a JSON value
//	** corresponding to the SQL value input.  Mostly this means putting
//	** double-quotes around strings and returning the unquoted string "null"
//	** when given a NULL input.
//	*/
func _jsonQuoteFunc(tls *libc.TLS, ctx uintptr, argc int32, argv uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var _ /* jx at bp+0 */ TJsonString
	_ = argc
	_jsonStringInit(tls, bp, ctx)
	_jsonAppendSqlValue(tls, bp, **(**uintptr)(__ccgo_up(argv)))
	_jsonReturnString(tls, bp, uintptr(0), uintptr(0))
	Xsqlite3_result_subtype(tls, ctx, uint32(JSON_SUBTYPE))
}

// C documentation
//
//	/*
//	** Convert a JSON BLOB into text and make that text the return value
//	** of an SQL function.
//	*/
func _jsonReturnTextJsonFromBlob(tls *libc.TLS, ctx uintptr, aBlob uintptr, nBlob Tu32) {
	bp := tls.Alloc(192)
	defer tls.Free(192)
	var _ /* s at bp+56 */ TJsonString
	var _ /* x at bp+0 */ TJsonParse
	if aBlob == uintptr(0) {
		return
	}
	libc.Xmemset(tls, bp, 0, uint32(56))
	(**(**TJsonParse)(__ccgo_up(bp))).FaBlob = aBlob
	(**(**TJsonParse)(__ccgo_up(bp))).FnBlob = nBlob
	_jsonStringInit(tls, bp+56, ctx)
	_jsonTranslateBlobToText(tls, bp, uint32(0), bp+56)
	_jsonReturnString(tls, bp+56, uintptr(0), uintptr(0))
}

// C documentation
//
//	/* Append N bytes from zIn onto the end of the JsonString string.
//	*/
func _jsonStringExpandAndAppend(tls *libc.TLS, p uintptr, zIn uintptr, N Tu32) {
	if _jsonStringGrow(tls, p, N) != 0 {
		return
	}
	libc.Xmemcpy(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf+uintptr((*TJsonString)(unsafe.Pointer(p)).FnUsed), zIn, N)
	**(**Tu64)(__ccgo_up(p + 16)) += uint64(N)
}

// C documentation
//
//	/* Enlarge pJson->zBuf so that it can hold at least N more bytes.
//	** Return zero on success.  Return non-zero on an OOM error
//	*/
func _jsonStringGrow(tls *libc.TLS, p uintptr, N Tu32) (r int32) {
	var nTotal Tu64
	var zNew, v2 uintptr
	var v1 uint64
	_, _, _, _ = nTotal, zNew, v1, v2
	if uint64(N) < (*TJsonString)(unsafe.Pointer(p)).FnAlloc {
		v1 = (*TJsonString)(unsafe.Pointer(p)).FnAlloc * uint64(2)
	} else {
		v1 = (*TJsonString)(unsafe.Pointer(p)).FnAlloc + uint64(N) + uint64(10)
	}
	nTotal = v1
	if (*TJsonString)(unsafe.Pointer(p)).FbStatic != 0 {
		if (*TJsonString)(unsafe.Pointer(p)).FeErr != 0 {
			return int32(1)
		}
		zNew = _sqlite3RCStrNew(tls, nTotal)
		if zNew == uintptr(0) {
			_jsonStringOom(tls, p)
			return int32(SQLITE_NOMEM)
		}
		libc.Xmemcpy(tls, zNew, (*TJsonString)(unsafe.Pointer(p)).FzBuf, uint32((*TJsonString)(unsafe.Pointer(p)).FnUsed))
		(*TJsonString)(unsafe.Pointer(p)).FzBuf = zNew
		(*TJsonString)(unsafe.Pointer(p)).FbStatic = uint8(0)
	} else {
		(*TJsonString)(unsafe.Pointer(p)).FzBuf = _sqlite3RCStrResize(tls, (*TJsonString)(unsafe.Pointer(p)).FzBuf, nTotal)
		if (*TJsonString)(unsafe.Pointer(p)).FzBuf == uintptr(0) {
			v2 = p + 25
			*(*Tu8)(unsafe.Pointer(v2)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v2))) | libc.Int32FromInt32(JSTRING_OOM))
			_jsonStringZero(tls, p)
			return int32(SQLITE_NOMEM)
		}
	}
	(*TJsonString)(unsafe.Pointer(p)).FnAlloc = nTotal
	return SQLITE_OK
}

// C documentation
//
//	/* Report an out-of-memory (OOM) condition
//	*/
func _jsonStringOom(tls *libc.TLS, p uintptr) {
	var v1 uintptr
	_ = v1
	v1 = p + 25
	*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(JSTRING_OOM))
	if (*TJsonString)(unsafe.Pointer(p)).FpCtx != 0 {
		Xsqlite3_result_error_nomem(tls, (*TJsonString)(unsafe.Pointer(p)).FpCtx)
	}
	_jsonStringReset(tls, p)
}

// C documentation
//
//	/* Turn uninitialized bulk memory into a valid JsonString object
//	** holding a zero-length string.
//	*/
func _jsonStringZero(tls *libc.TLS, p uintptr) {
	(*TJsonString)(unsafe.Pointer(p)).FzBuf = p + 26
	(*TJsonString)(unsafe.Pointer(p)).FnAlloc = uint64(100)
	(*TJsonString)(unsafe.Pointer(p)).FnUsed = uint64(0)
	(*TJsonString)(unsafe.Pointer(p)).FbStatic = uint8(1)
}

func _last_valueFinalizeFunc(tls *libc.TLS, pCtx uintptr) {
	var p uintptr
	_ = p
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 && (*TLastValueCtx)(unsafe.Pointer(p)).FpVal != 0 {
		Xsqlite3_result_value(tls, pCtx, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
		Xsqlite3_value_free(tls, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
		(*TLastValueCtx)(unsafe.Pointer(p)).FpVal = uintptr(0)
	}
}

func _last_valueInvFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	_ = apArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 {
		(*TLastValueCtx)(unsafe.Pointer(p)).FnVal = (*TLastValueCtx)(unsafe.Pointer(p)).FnVal - 1
		if (*TLastValueCtx)(unsafe.Pointer(p)).FnVal == 0 {
			Xsqlite3_value_free(tls, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
			(*TLastValueCtx)(unsafe.Pointer(p)).FpVal = uintptr(0)
		}
	}
}

// C documentation
//
//	/*
//	** Implementation of last_value().
//	*/
func _last_valueStepFunc(tls *libc.TLS, pCtx uintptr, nArg int32, apArg uintptr) {
	var p uintptr
	_ = p
	_ = nArg
	p = Xsqlite3_aggregate_context(tls, pCtx, int32(8))
	if p != 0 {
		Xsqlite3_value_free(tls, (*TLastValueCtx)(unsafe.Pointer(p)).FpVal)
		(*TLastValueCtx)(unsafe.Pointer(p)).FpVal = Xsqlite3_value_dup(tls, **(**uintptr)(__ccgo_up(apArg)))
		if (*TLastValueCtx)(unsafe.Pointer(p)).FpVal == uintptr(0) {
			Xsqlite3_result_error_nomem(tls, pCtx)
		} else {
			(*TLastValueCtx)(unsafe.Pointer(p)).FnVal = (*TLastValueCtx)(unsafe.Pointer(p)).FnVal + 1
		}
	}
}

// C documentation
//
//	/*
//	** Implementation of SQL functions:
//	**
//	**   ln(X)       - natural logarithm
//	**   log(X)      - log X base 10
//	**   log10(X)    - log X base 10
//	**   log(B,X)    - log X base B
//	*/
func _logFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var ans, b, x float64
	_, _, _ = ans, b, x
	switch Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(argv))) {
	case int32(SQLITE_INTEGER):
		fallthrough
	case int32(SQLITE_FLOAT):
		x = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv)))
		if x <= float64(0) {
			return
		}
	default:
		return
	}
	if argc == int32(2) {
		switch Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(argv))) {
		case int32(SQLITE_INTEGER):
			fallthrough
		case int32(SQLITE_FLOAT):
			b = libc.Xlog(tls, x)
			if b <= float64(0) {
				return
			}
			x = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
			if x <= float64(0) {
				return
			}
		default:
			return
		}
		ans = libc.Xlog(tls, x) / b
	} else {
		switch int32(Xsqlite3_user_data(tls, context)) {
		case int32(1):
			ans = libc.Xlog10(tls, x)
		case int32(2):
			ans = libc.X__builtin_log2(tls, x)
		default:
			ans = libc.Xlog(tls, x)
			break
		}
	}
	Xsqlite3_result_double(tls, context, ans)
}

// C documentation
//
//	/*
//	** Code the OP_MakeRecord instruction that generates the entry to be
//	** added into the sorter.
//	**
//	** Return the register in which the result is stored.
//	*/
func _makeSorterRecord(tls *libc.TLS, pParse uintptr, pSort uintptr, pSelect uintptr, regBase int32, nBase int32) (r int32) {
	var nOBSat, regOut, v1 int32
	var v, v2 uintptr
	_, _, _, _, _ = nOBSat, regOut, v, v1, v2
	nOBSat = (*TSortCtx)(unsafe.Pointer(pSort)).FnOBSat
	v = (*TParse)(unsafe.Pointer(pParse)).FpVdbe
	v2 = pParse + 48
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	v1 = *(*int32)(unsafe.Pointer(v2))
	regOut = v1
	if (*TSortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad != 0 {
		_innerLoopLoadRow(tls, pParse, pSelect, (*TSortCtx)(unsafe.Pointer(pSort)).FpDeferredRowLoad)
	}
	_sqlite3VdbeAddOp3(tls, v, int32(OP_MakeRecord), regBase+nOBSat, nBase-nOBSat, regOut)
	return regOut
}

// C documentation
//
//	/*
//	** Mark term iChild as being a child of term iParent
//	*/
func _markTermAsChild(tls *libc.TLS, pWC uintptr, iChild int32, iParent int32) {
	(**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iChild)*48))).FiParent = iParent
	(**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iChild)*48))).FtruthProb = (**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iParent)*48))).FtruthProb
	(**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iParent)*48))).FnChild = (**(**TWhereTerm)(__ccgo_up((*TWhereClause)(unsafe.Pointer(pWC)).Fa + uintptr(iParent)*48))).FnChild + 1
}

// C documentation
//
//	/*
//	** Implementation of 2-argument SQL math functions:
//	**
//	**   power(X,Y)  - Compute X to the Y-th power
//	*/
func _math2Func(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var ans, v0, v1 float64
	var type0, type1 int32
	var x uintptr
	_, _, _, _, _, _ = ans, type0, type1, v0, v1, x
	type0 = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(argv)))
	if type0 != int32(SQLITE_INTEGER) && type0 != int32(SQLITE_FLOAT) {
		return
	}
	type1 = Xsqlite3_value_numeric_type(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
	if type1 != int32(SQLITE_INTEGER) && type1 != int32(SQLITE_FLOAT) {
		return
	}
	v0 = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv)))
	v1 = Xsqlite3_value_double(tls, **(**uintptr)(__ccgo_up(argv + 1*4)))
	x = Xsqlite3_user_data(tls, context)
	ans = (*(*func(*libc.TLS, float64, float64) float64)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, v0, v1)
	Xsqlite3_result_double(tls, context, ans)
}

// C documentation
//
//	/*
//	** Close an memdb-file.
//	** Free the underlying MemStore object when its refcount drops to zero
//	** or less.
//	*/
func _memdbClose(tls *libc.TLS, pFile uintptr) (r int32) {
	var i, v2 int32
	var p, pVfsMutex, v3 uintptr
	_, _, _, _, _ = i, p, pVfsMutex, v2, v3
	p = (*TMemFile)(unsafe.Pointer(pFile)).FpStore
	if (*TMemStore)(unsafe.Pointer(p)).FzFName != 0 {
		pVfsMutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_VFS1))
		Xsqlite3_mutex_enter(tls, pVfsMutex)
		i = 0
		for {
			if !(i < _memdb_g.FnMemStore) {
				break
			}
			if **(**uintptr)(__ccgo_up(_memdb_g.FapMemStore + uintptr(i)*4)) == p {
				_memdbEnter(tls, p)
				if (*TMemStore)(unsafe.Pointer(p)).FnRef == int32(1) {
					v3 = uintptr(unsafe.Pointer(&_memdb_g))
					*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) - 1
					v2 = *(*int32)(unsafe.Pointer(v3))
					**(**uintptr)(__ccgo_up(_memdb_g.FapMemStore + uintptr(i)*4)) = **(**uintptr)(__ccgo_up(_memdb_g.FapMemStore + uintptr(v2)*4))
					if _memdb_g.FnMemStore == 0 {
						Xsqlite3_free(tls, _memdb_g.FapMemStore)
						_memdb_g.FapMemStore = uintptr(0)
					}
				}
				break
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_mutex_leave(tls, pVfsMutex)
	} else {
		_memdbEnter(tls, p)
	}
	(*TMemStore)(unsafe.Pointer(p)).FnRef = (*TMemStore)(unsafe.Pointer(p)).FnRef - 1
	if (*TMemStore)(unsafe.Pointer(p)).FnRef <= 0 {
		if (*TMemStore)(unsafe.Pointer(p)).FmFlags&uint32(SQLITE_DESERIALIZE_FREEONCLOSE) != 0 {
			Xsqlite3_free(tls, (*TMemStore)(unsafe.Pointer(p)).FaData)
		}
		_memdbLeave(tls, p)
		Xsqlite3_mutex_free(tls, (*TMemStore)(unsafe.Pointer(p)).FpMutex)
		Xsqlite3_free(tls, p)
	} else {
		_memdbLeave(tls, p)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Implementation of the non-aggregate min() and max() functions
//	*/
func _minmaxFunc(tls *libc.TLS, context uintptr, argc int32, argv uintptr) {
	var i, iBest, mask, v1 int32
	var pColl uintptr
	_, _, _, _, _ = i, iBest, mask, pColl, v1
	if Xsqlite3_user_data(tls, context) == uintptr(0) {
		v1 = 0
	} else {
		v1 = -int32(1)
	}
	mask = v1
	pColl = _sqlite3GetFuncCollSeq(tls, context)
	iBest = 0
	if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv))) == int32(SQLITE_NULL) {
		return
	}
	i = int32(1)
	for {
		if !(i < argc) {
			break
		}
		if Xsqlite3_value_type(tls, **(**uintptr)(__ccgo_up(argv + uintptr(i)*4))) == int32(SQLITE_NULL) {
			return
		}
		if _sqlite3MemCompare(tls, **(**uintptr)(__ccgo_up(argv + uintptr(iBest)*4)), **(**uintptr)(__ccgo_up(argv + uintptr(i)*4)), pColl)^mask >= 0 {
			iBest = i
		}
		goto _2
	_2:
		;
		i = i + 1
	}
	Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(argv + uintptr(iBest)*4)))
}

// C documentation
//
//	/*
//	** Routines to implement min() and max() aggregate functions.
//	*/
func _minmaxStep(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var cmp, max int32
	var pArg, pBest, pColl uintptr
	_, _, _, _, _ = cmp, max, pArg, pBest, pColl
	pArg = **(**uintptr)(__ccgo_up(argv))
	_ = NotUsed
	pBest = Xsqlite3_aggregate_context(tls, context, int32(40))
	if !(pBest != 0) {
		return
	}
	if Xsqlite3_value_type(tls, pArg) == int32(SQLITE_NULL) {
		if (*TMem)(unsafe.Pointer(pBest)).Fflags != 0 {
			_sqlite3SkipAccumulatorLoad(tls, context)
		}
	} else {
		if (*TMem)(unsafe.Pointer(pBest)).Fflags != 0 {
			pColl = _sqlite3GetFuncCollSeq(tls, context)
			/* This step function is used for both the min() and max() aggregates,
			 ** the only difference between the two being that the sense of the
			 ** comparison is inverted. For the max() aggregate, the
			 ** sqlite3_user_data() function returns (void *)-1. For min() it
			 ** returns (void *)db, where db is the sqlite3* database pointer.
			 ** Therefore the next statement sets variable 'max' to 1 for the max()
			 ** aggregate, or 0 for min().
			 */
			max = libc.BoolInt32(Xsqlite3_user_data(tls, context) != uintptr(0))
			cmp = _sqlite3MemCompare(tls, pBest, pArg, pColl)
			if max != 0 && cmp < 0 || !(max != 0) && cmp > 0 {
				_sqlite3VdbeMemCopy(tls, pBest, pArg)
			} else {
				_sqlite3SkipAccumulatorLoad(tls, context)
			}
		} else {
			(*TMem)(unsafe.Pointer(pBest)).Fdb = Xsqlite3_context_db_handle(tls, context)
			_sqlite3VdbeMemCopy(tls, pBest, pArg)
		}
	}
}

// C documentation
//
//	/*
//	** Return the appropriate collating sequence for the iCol-th column of
//	** the result set for the compound-select statement "p".  Return NULL if
//	** the column has no default collating sequence.
//	**
//	** The collating sequence for the compound select is taken from the
//	** left-most term of the select that has a collating sequence.
//	*/
func _multiSelectCollSeq(tls *libc.TLS, pParse uintptr, p uintptr, iCol int32) (r uintptr) {
	var pRet uintptr
	_ = pRet
	if (*TSelect)(unsafe.Pointer(p)).FpPrior != 0 {
		pRet = _multiSelectCollSeq(tls, pParse, (*TSelect)(unsafe.Pointer(p)).FpPrior, iCol)
	} else {
		pRet = uintptr(0)
	}
	/* iCol must be less than p->pEList->nExpr.  Otherwise an error would
	 ** have been thrown during name resolution and we would not have gotten
	 ** this far */
	if pRet == uintptr(0) && iCol < (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList)).FnExpr {
		pRet = _sqlite3ExprCollSeq(tls, pParse, (*(*TExprList_item)(unsafe.Pointer((*TSelect)(unsafe.Pointer(p)).FpEList + 8 + uintptr(iCol)*20))).FpExpr)
	}
	return pRet
}

// C documentation
//
//	/*
//	** Implementation of the NULLIF(x,y) function.  The result is the first
//	** argument if the arguments are different.  The result is NULL if the
//	** arguments are equal to each other.
//	*/
func _nullifFunc(tls *libc.TLS, context uintptr, NotUsed int32, argv uintptr) {
	var pColl uintptr
	_ = pColl
	pColl = _sqlite3GetFuncCollSeq(tls, context)
	_ = NotUsed
	if _sqlite3MemCompare(tls, **(**uintptr)(__ccgo_up(argv)), **(**uintptr)(__ccgo_up(argv + 1*4)), pColl) != 0 {
		Xsqlite3_result_value(tls, context, **(**uintptr)(__ccgo_up(argv)))
	}
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xDestroy method.
//	**
//	** Destroy a cache allocated using pcache1Create().
//	*/
func _pcache1Destroy(tls *libc.TLS, p uintptr) {
	var pCache, pGroup uintptr
	_, _ = pCache, pGroup
	pCache = p
	pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	if (*TPCache1)(unsafe.Pointer(pCache)).FnPage != 0 {
		_pcache1TruncateUnsafe(tls, pCache, uint32(0))
	}
	**(**uint32)(__ccgo_up(pGroup + 4)) -= (*TPCache1)(unsafe.Pointer(pCache)).FnMax
	**(**uint32)(__ccgo_up(pGroup + 8)) -= (*TPCache1)(unsafe.Pointer(pCache)).FnMin
	(*TPGroup)(unsafe.Pointer(pGroup)).FmxPinned = (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage + uint32(10) - (*TPGroup)(unsafe.Pointer(pGroup)).FnMinPage
	_pcache1EnforceMaxPage(tls, pCache)
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	Xsqlite3_free(tls, (*TPCache1)(unsafe.Pointer(pCache)).FpBulk)
	Xsqlite3_free(tls, (*TPCache1)(unsafe.Pointer(pCache)).FapHash)
	Xsqlite3_free(tls, pCache)
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xFetch method.
//	**
//	** Fetch a page by key value.
//	**
//	** Whether or not a new page may be allocated by this function depends on
//	** the value of the createFlag argument.  0 means do not allocate a new
//	** page.  1 means allocate a new page if space is easily available.  2
//	** means to try really hard to allocate a new page.
//	**
//	** For a non-purgeable cache (a cache used as the storage for an in-memory
//	** database) there is really no difference between createFlag 1 and 2.  So
//	** the calling function (pcache.c) will never have a createFlag of 1 on
//	** a non-purgeable cache.
//	**
//	** There are three different approaches to obtaining space for a page,
//	** depending on the value of parameter createFlag (which may be 0, 1 or 2).
//	**
//	**   1. Regardless of the value of createFlag, the cache is searched for a
//	**      copy of the requested page. If one is found, it is returned.
//	**
//	**   2. If createFlag==0 and the page is not already in the cache, NULL is
//	**      returned.
//	**
//	**   3. If createFlag is 1, and the page is not already in the cache, then
//	**      return NULL (do not allocate a new page) if any of the following
//	**      conditions are true:
//	**
//	**       (a) the number of pages pinned by the cache is greater than
//	**           PCache1.nMax, or
//	**
//	**       (b) the number of pages pinned by the cache is greater than
//	**           the sum of nMax for all purgeable caches, less the sum of
//	**           nMin for all other purgeable caches, or
//	**
//	**   4. If none of the first three conditions apply and the cache is marked
//	**      as purgeable, and if one of the following is true:
//	**
//	**       (a) The number of pages allocated for the cache is already
//	**           PCache1.nMax, or
//	**
//	**       (b) The number of pages allocated for all purgeable caches is
//	**           already equal to or greater than the sum of nMax for all
//	**           purgeable caches,
//	**
//	**       (c) The system is under memory pressure and wants to avoid
//	**           unnecessary pages cache entry allocations
//	**
//	**      then attempt to recycle a page from the LRU list. If it is the right
//	**      size, return the recycled buffer. Otherwise, free the buffer and
//	**      proceed to step 5.
//	**
//	**   5. Otherwise, allocate and return a new page buffer.
//	**
//	** There are two versions of this routine.  pcache1FetchWithMutex() is
//	** the general case.  pcache1FetchNoMutex() is a faster implementation for
//	** the common case where pGroup->mutex is NULL.  The pcache1Fetch() wrapper
//	** invokes the appropriate routine.
//	*/
func _pcache1FetchNoMutex(tls *libc.TLS, p uintptr, iKey uint32, createFlag int32) (r uintptr) {
	var pCache, pPage uintptr
	_, _ = pCache, pPage
	pCache = p
	pPage = uintptr(0)
	/* Step 1: Search the hash table for an existing entry. */
	pPage = **(**uintptr)(__ccgo_up((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(iKey%(*TPCache1)(unsafe.Pointer(pCache)).FnHash)*4))
	for pPage != 0 && (*TPgHdr1)(unsafe.Pointer(pPage)).FiKey != iKey {
		pPage = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
	}
	/* Step 2: If the page was found in the hash table, then return it.
	 ** If the page was not in the hash table and createFlag is 0, abort.
	 ** Otherwise (page not in hash and createFlag!=0) continue with
	 ** subsequent steps to try to create the page. */
	if pPage != 0 {
		if (*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext != uintptr(0) {
			return _pcache1PinPage(tls, pPage)
		} else {
			return pPage
		}
	} else {
		if createFlag != 0 {
			/* Steps 3, 4, and 5 implemented by this subroutine */
			return _pcache1FetchStage2(tls, pCache, iKey, createFlag)
		} else {
			return uintptr(0)
		}
	}
	return r
}

// C documentation
//
//	/*
//	** Free an allocated buffer obtained from pcache1Alloc().
//	*/
func _pcache1Free(tls *libc.TLS, p uintptr) {
	var nFreed int32
	var pSlot uintptr
	_, _ = nFreed, pSlot
	if p == uintptr(0) {
		return
	}
	if uint32(p) >= uint32(_pcache1_g.FpStart) && uint32(p) < uint32(_pcache1_g.FpEnd) {
		Xsqlite3_mutex_enter(tls, _pcache1_g.Fmutex)
		_sqlite3StatusDown(tls, int32(SQLITE_STATUS_PAGECACHE_USED), int32(1))
		pSlot = p
		(*TPgFreeslot)(unsafe.Pointer(pSlot)).FpNext = _pcache1_g.FpFree
		_pcache1_g.FpFree = pSlot
		_pcache1_g.FnFreeSlot = _pcache1_g.FnFreeSlot + 1
		libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&_pcache1_g))+96, libc.BoolInt32(_pcache1_g.FnFreeSlot < _pcache1_g.FnReserve), libc.Int32FromInt32(__ATOMIC_RELAXED))
		Xsqlite3_mutex_leave(tls, _pcache1_g.Fmutex)
	} else {
		nFreed = 0
		nFreed = _sqlite3MallocSize(tls, p)
		Xsqlite3_mutex_enter(tls, _pcache1_g.Fmutex)
		_sqlite3StatusDown(tls, int32(SQLITE_STATUS_PAGECACHE_OVERFLOW), nFreed)
		Xsqlite3_mutex_leave(tls, _pcache1_g.Fmutex)
		Xsqlite3_free(tls, p)
	}
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xInit method.
//	*/
func _pcache1Init(tls *libc.TLS, NotUsed uintptr) (r int32) {
	_ = NotUsed
	libc.Xmemset(tls, uintptr(unsafe.Pointer(&_pcache1_g)), 0, uint32(100))
	/*
	 ** The pcache1.separateCache variable is true if each PCache has its own
	 ** private PGroup (mode-1).  pcache1.separateCache is false if the single
	 ** PGroup in pcache1.grp is used for all page caches (mode-2).
	 **
	 **   *  Always use a unified cache (mode-2) if ENABLE_MEMORY_MANAGEMENT
	 **
	 **   *  Use a unified cache in single-threaded applications that have
	 **      configured a start-time buffer for use as page-cache memory using
	 **      sqlite3_config(SQLITE_CONFIG_PAGECACHE, pBuf, sz, N) with non-NULL
	 **      pBuf argument.
	 **
	 **   *  Otherwise use separate caches (mode-1)
	 */
	_pcache1_g.FseparateCache = 0
	if _sqlite3Config.FbCoreMutex != 0 {
		_pcache1_g.Fgrp.Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_LRU))
		_pcache1_g.Fmutex = _sqlite3MutexAlloc(tls, int32(SQLITE_MUTEX_STATIC_PMEM))
	}
	if _pcache1_g.FseparateCache != 0 && _sqlite3Config.FnPage != 0 && _sqlite3Config.FpPage == uintptr(0) {
		_pcache1_g.FnInitPage = _sqlite3Config.FnPage
	} else {
		_pcache1_g.FnInitPage = 0
	}
	_pcache1_g.Fgrp.FmxPinned = uint32(10)
	libc.AtomicStorePInt32(uintptr(unsafe.Pointer(&_pcache1_g))+52, int32(1))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xRekey method.
//	*/
func _pcache1Rekey(tls *libc.TLS, p uintptr, pPg uintptr, iOld uint32, iNew uint32) {
	var hNew, hOld uint32
	var pCache, pPage, pp uintptr
	_, _, _, _, _ = hNew, hOld, pCache, pPage, pp
	pCache = p
	pPage = pPg
	/* The page number really is changing */
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
	/* pPg really is iOld */
	hOld = iOld % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
	pp = (*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hOld)*4
	for **(**uintptr)(__ccgo_up(pp)) != pPage {
		pp = **(**uintptr)(__ccgo_up(pp)) + 16
	}
	**(**uintptr)(__ccgo_up(pp)) = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
	/* iNew not in cache */
	hNew = iNew % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
	(*TPgHdr1)(unsafe.Pointer(pPage)).FiKey = iNew
	(*TPgHdr1)(unsafe.Pointer(pPage)).FpNext = **(**uintptr)(__ccgo_up((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hNew)*4))
	**(**uintptr)(__ccgo_up((*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(hNew)*4)) = pPage
	if iNew > (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey {
		(*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey = iNew
	}
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

// C documentation
//
//	/*
//	** Remove the page supplied as an argument from the hash table
//	** (PCache1.apHash structure) that it is currently stored in.
//	** Also free the page if freePage is true.
//	**
//	** The PGroup mutex must be held when this function is called.
//	*/
func _pcache1RemoveFromHash(tls *libc.TLS, pPage uintptr, freeFlag int32) {
	var h uint32
	var pCache, pp uintptr
	_, _, _ = h, pCache, pp
	pCache = (*TPgHdr1)(unsafe.Pointer(pPage)).FpCache
	h = (*TPgHdr1)(unsafe.Pointer(pPage)).FiKey % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
	pp = (*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*4
	for {
		if !(**(**uintptr)(__ccgo_up(pp)) != pPage) {
			break
		}
		goto _1
	_1:
		;
		pp = **(**uintptr)(__ccgo_up(pp)) + 16
	}
	**(**uintptr)(__ccgo_up(pp)) = (*TPgHdr1)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FpNext
	(*TPCache1)(unsafe.Pointer(pCache)).FnPage = (*TPCache1)(unsafe.Pointer(pCache)).FnPage - 1
	if freeFlag != 0 {
		_pcache1FreePage(tls, pPage)
	}
}

// C documentation
//
//	/*
//	** This function is used to resize the hash table used by the cache passed
//	** as the first argument.
//	**
//	** The PCache mutex must be held when this function is called.
//	*/
func _pcache1ResizeHash(tls *libc.TLS, p uintptr) {
	var apNew, pNext, pPage, v2 uintptr
	var h uint32
	var i Tu32
	var nNew Tu64
	_, _, _, _, _, _, _ = apNew, h, i, nNew, pNext, pPage, v2
	nNew = uint64(2) * uint64((*TPCache1)(unsafe.Pointer(p)).FnHash)
	if nNew < uint64(256) {
		nNew = uint64(256)
	}
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(p)).FpGroup)).Fmutex)
	if (*TPCache1)(unsafe.Pointer(p)).FnHash != 0 {
		_sqlite3BeginBenignMalloc(tls)
	}
	apNew = _sqlite3MallocZero(tls, uint64(4)*nNew)
	if (*TPCache1)(unsafe.Pointer(p)).FnHash != 0 {
		_sqlite3EndBenignMalloc(tls)
	}
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(p)).FpGroup)).Fmutex)
	if apNew != 0 {
		i = uint32(0)
		for {
			if !(i < (*TPCache1)(unsafe.Pointer(p)).FnHash) {
				break
			}
			pNext = **(**uintptr)(__ccgo_up((*TPCache1)(unsafe.Pointer(p)).FapHash + uintptr(i)*4))
			for {
				v2 = pNext
				pPage = v2
				if !(v2 != uintptr(0)) {
					break
				}
				h = uint32(uint64((*TPgHdr1)(unsafe.Pointer(pPage)).FiKey) % nNew)
				pNext = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
				(*TPgHdr1)(unsafe.Pointer(pPage)).FpNext = **(**uintptr)(__ccgo_up(apNew + uintptr(h)*4))
				**(**uintptr)(__ccgo_up(apNew + uintptr(h)*4)) = pPage
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_free(tls, (*TPCache1)(unsafe.Pointer(p)).FapHash)
		(*TPCache1)(unsafe.Pointer(p)).FapHash = apNew
		(*TPCache1)(unsafe.Pointer(p)).FnHash = uint32(nNew)
	}
}

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xShutdown method.
//	** Note that the static mutex allocated in xInit does
//	** not need to be freed.
//	*/
func _pcache1Shutdown(tls *libc.TLS, NotUsed uintptr) {
	_ = NotUsed
	libc.Xmemset(tls, uintptr(unsafe.Pointer(&_pcache1_g)), 0, uint32(100))
}

// C documentation
//
//	/*
//	** Discard all pages from cache pCache with a page number (key value)
//	** greater than or equal to iLimit. Any pinned pages that meet this
//	** criteria are unpinned before they are discarded.
//	**
//	** The PCache mutex must be held when this function is called.
//	*/
func _pcache1TruncateUnsafe(tls *libc.TLS, pCache uintptr, iLimit uint32) {
	var h, iStop uint32
	var pPage, pp, v2 uintptr
	_, _, _, _, _ = h, iStop, pPage, pp, v2
	if (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey-iLimit < (*TPCache1)(unsafe.Pointer(pCache)).FnHash {
		/* If we are just shaving the last few pages off the end of the
		 ** cache, then there is no point in scanning the entire hash table.
		 ** Only scan those hash slots that might contain pages that need to
		 ** be removed. */
		h = iLimit % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
		iStop = (*TPCache1)(unsafe.Pointer(pCache)).FiMaxKey % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
		/* Disable the pCache->nPage validity check */
	} else {
		/* This is the general case where many pages are being removed.
		 ** It is necessary to scan the entire hash table */
		h = (*TPCache1)(unsafe.Pointer(pCache)).FnHash / uint32(2)
		iStop = h - uint32(1)
	}
	for {
		pp = (*TPCache1)(unsafe.Pointer(pCache)).FapHash + uintptr(h)*4
		for {
			v2 = **(**uintptr)(__ccgo_up(pp))
			pPage = v2
			if !(v2 != uintptr(0)) {
				break
			}
			if (*TPgHdr1)(unsafe.Pointer(pPage)).FiKey >= iLimit {
				(*TPCache1)(unsafe.Pointer(pCache)).FnPage = (*TPCache1)(unsafe.Pointer(pCache)).FnPage - 1
				**(**uintptr)(__ccgo_up(pp)) = (*TPgHdr1)(unsafe.Pointer(pPage)).FpNext
				if (*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext != uintptr(0) {
					_pcache1PinPage(tls, pPage)
				}
				_pcache1FreePage(tls, pPage)
			} else {
				pp = pPage + 16
			}
		}
		if h == iStop {
			break
		}
		h = (h + uint32(1)) % (*TPCache1)(unsafe.Pointer(pCache)).FnHash
		goto _1
	_1:
	}
}

/******************************************************************************/
/******** sqlite3_pcache Methods **********************************************/

// C documentation
//
//	/*
//	** Return true if it desirable to avoid allocating a new page cache
//	** entry.
//	**
//	** If memory was allocated specifically to the page cache using
//	** SQLITE_CONFIG_PAGECACHE but that memory has all been used, then
//	** it is desirable to avoid allocating a new page cache entry because
//	** presumably SQLITE_CONFIG_PAGECACHE was suppose to be sufficient
//	** for all page cache needs and we should not need to spill the
//	** allocation onto the heap.
//	**
//	** Or, the heap is used for all page cache memory but the heap is
//	** under memory pressure, then again it is desirable to avoid
//	** allocating a new page cache entry in order to avoid stressing
//	** the heap even further.
//	*/
func _pcache1UnderMemoryPressure(tls *libc.TLS, pCache uintptr) (r int32) {
	if _pcache1_g.FnSlot != 0 && (*TPCache1)(unsafe.Pointer(pCache)).FszPage+(*TPCache1)(unsafe.Pointer(pCache)).FszExtra <= _pcache1_g.FszSlot {
		return libc.AtomicLoadNInt32(uintptr(unsafe.Pointer(&_pcache1_g))+96, libc.Int32FromInt32(__ATOMIC_RELAXED))
	} else {
		return _sqlite3HeapNearlyFull(tls)
	}
	return r
}

/******************************************************************************/
/******** General Implementation Functions ************************************/

// C documentation
//
//	/*
//	** Implementation of the sqlite3_pcache.xUnpin method.
//	**
//	** Mark a page as unpinned (eligible for asynchronous recycling).
//	*/
func _pcache1Unpin(tls *libc.TLS, p uintptr, pPg uintptr, reuseUnlikely int32) {
	var pCache, pGroup, pPage, ppFirst, v1 uintptr
	_, _, _, _, _ = pCache, pGroup, pPage, ppFirst, v1
	pCache = p
	pPage = pPg
	pGroup = (*TPCache1)(unsafe.Pointer(pCache)).FpGroup
	Xsqlite3_mutex_enter(tls, (*TPGroup)(unsafe.Pointer(pGroup)).Fmutex)
	/* It is an error to call this function if the page is already
	 ** part of the PGroup LRU list.
	 */
	if reuseUnlikely != 0 || (*TPGroup)(unsafe.Pointer(pGroup)).FnPurgeable > (*TPGroup)(unsafe.Pointer(pGroup)).FnMaxPage {
		_pcache1RemoveFromHash(tls, pPage, int32(1))
	} else {
		/* Add the page to the PGroup LRU list. */
		ppFirst = pGroup + 20 + 24
		(*TPgHdr1)(unsafe.Pointer(pPage)).FpLruPrev = pGroup + 20
		v1 = **(**uintptr)(__ccgo_up(ppFirst))
		(*TPgHdr1)(unsafe.Pointer(pPage)).FpLruNext = v1
		(*TPgHdr1)(unsafe.Pointer(v1)).FpLruPrev = pPage
		**(**uintptr)(__ccgo_up(ppFirst)) = pPage
		(*TPCache1)(unsafe.Pointer(pCache)).FnRecyclable = (*TPCache1)(unsafe.Pointer(pCache)).FnRecyclable + 1
	}
	Xsqlite3_mutex_leave(tls, (*TPGroup)(unsafe.Pointer((*TPCache1)(unsafe.Pointer(pCache)).FpGroup)).Fmutex)
}

// C documentation
//
//	/*
//	** This is a helper routine for sqlite3PcacheFetchFinish()
//	**
//	** In the uncommon case where the page being fetched has not been
//	** initialized, this routine is invoked to do the initialization.
//	** This routine is broken out into a separate function since it
//	** requires extra stack manipulation that can be avoided in the common
//	** case.
//	*/
func _pcacheFetchFinishWithInit(tls *libc.TLS, pCache uintptr, pgno TPgno, pPage uintptr) (r uintptr) {
	var pPgHdr uintptr
	_ = pPgHdr
	pPgHdr = (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage)).FpExtra
	libc.Xmemset(tls, pPgHdr+16, 0, libc.Uint32FromInt64(48)-uint32(libc.UintptrFromInt32(0)+16))
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpPage = pPage
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpData = (*Tsqlite3_pcache_page)(unsafe.Pointer(pPage)).FpBuf
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpExtra = pPgHdr + 1*48
	libc.Xmemset(tls, (*TPgHdr)(unsafe.Pointer(pPgHdr)).FpExtra, 0, uint32(8))
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).FpCache = pCache
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).Fpgno = pgno
	(*TPgHdr)(unsafe.Pointer(pPgHdr)).Fflags = uint16(PGHDR_CLEAN)
	return _sqlite3PcacheFetchFinish(tls, pCache, pgno, pPage)
}

// C documentation
//
//	/*
//	** Merge two lists of pages connected by pDirty and in pgno order.
//	** Do not bother fixing the pDirtyPrev pointers.
//	*/
func _pcacheMergeDirtyList(tls *libc.TLS, pA uintptr, pB uintptr) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var pTail uintptr
	var _ /* result at bp+0 */ TPgHdr
	_ = pTail
	pTail = bp
	for {
		if (*TPgHdr)(unsafe.Pointer(pA)).Fpgno < (*TPgHdr)(unsafe.Pointer(pB)).Fpgno {
			(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pA
			pTail = pA
			pA = (*TPgHdr)(unsafe.Pointer(pA)).FpDirty
			if pA == uintptr(0) {
				(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pB
				break
			}
		} else {
			(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pB
			pTail = pB
			pB = (*TPgHdr)(unsafe.Pointer(pB)).FpDirty
			if pB == uintptr(0) {
				(*TPgHdr)(unsafe.Pointer(pTail)).FpDirty = pA
				break
			}
		}
		goto _1
	_1:
	}
	return (**(**TPgHdr)(__ccgo_up(bp))).FpDirty
}

// C documentation
//
//	/*
//	** Sort the list of pages in ascending order by pgno.  Pages are
//	** connected by pDirty pointers.  The pDirtyPrev pointers are
//	** corrupted by this sort.
//	**
//	** Since there cannot be more than 2^31 distinct pages in a database,
//	** there cannot be more than 31 buckets required by the merge sorter.
//	** One extra bucket is added to catch overflow in case something
//	** ever changes to make the previous sentence incorrect.
//	*/
func _pcacheSortDirtyList(tls *libc.TLS, pIn uintptr) (r uintptr) {
	bp := tls.Alloc(128)
	defer tls.Free(128)
	var i int32
	var p, v3 uintptr
	var _ /* a at bp+0 */ [32]uintptr
	_, _, _ = i, p, v3
	libc.Xmemset(tls, bp, 0, uint32(128))
	for pIn != 0 {
		p = pIn
		pIn = (*TPgHdr)(unsafe.Pointer(p)).FpDirty
		(*TPgHdr)(unsafe.Pointer(p)).FpDirty = uintptr(0)
		i = 0
		for {
			if !(i < libc.Int32FromInt32(N_SORT_BUCKET)-libc.Int32FromInt32(1)) {
				break
			}
			if (**(**[32]uintptr)(__ccgo_up(bp)))[i] == uintptr(0) {
				(**(**[32]uintptr)(__ccgo_up(bp)))[i] = p
				break
			} else {
				p = _pcacheMergeDirtyList(tls, (**(**[32]uintptr)(__ccgo_up(bp)))[i], p)
				(**(**[32]uintptr)(__ccgo_up(bp)))[i] = uintptr(0)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		if i == libc.Int32FromInt32(N_SORT_BUCKET)-libc.Int32FromInt32(1) {
			/* To get here, there need to be 2^(N_SORT_BUCKET) elements in
			 ** the input list.  But that is impossible.
			 */
			(**(**[32]uintptr)(__ccgo_up(bp)))[i] = _pcacheMergeDirtyList(tls, (**(**[32]uintptr)(__ccgo_up(bp)))[i], p)
		}
	}
	p = (**(**[32]uintptr)(__ccgo_up(bp)))[0]
	i = int32(1)
	for {
		if !(i < int32(N_SORT_BUCKET)) {
			break
		}
		if (**(**[32]uintptr)(__ccgo_up(bp)))[i] == uintptr(0) {
			goto _2
		}
		if p != 0 {
			v3 = _pcacheMergeDirtyList(tls, p, (**(**[32]uintptr)(__ccgo_up(bp)))[i])
		} else {
			v3 = (**(**[32]uintptr)(__ccgo_up(bp)))[i]
		}
		p = v3
		goto _2
	_2:
		;
		i = i + 1
	}
	return p
}

// C documentation
//
//	/* Create a new cursor for the pragma virtual table */
func _pragmaVtabOpen(tls *libc.TLS, pVtab uintptr, ppCursor uintptr) (r int32) {
	var pCsr uintptr
	_ = pCsr
	pCsr = Xsqlite3_malloc(tls, int32(24))
	if pCsr == uintptr(0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pCsr, 0, uint32(24))
	(*TPragmaVtabCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVtab
	**(**uintptr)(__ccgo_up(ppCursor)) = pCsr
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Argument zFmt is a sqlite3_mprintf() style format string. The trailing
//	** arguments are the usual subsitution values. This function performs
//	** the printf() style substitutions and executes the result as an SQL
//	** statement on the RBU handles database.
//	**
//	** If an error occurs, an error code and error message is stored in the
//	** RBU handle. If an error has already occurred when this function is
//	** called, it is a no-op.
//	*/
func _rbuMPrintfExec(tls *libc.TLS, p uintptr, db uintptr, zFmt uintptr, va uintptr) (r int32) {
	var ap Tva_list
	var zSql uintptr
	_, _ = ap, zSql
	ap = va
	zSql = Xsqlite3_vmprintf(tls, zFmt, ap)
	if (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc == SQLITE_OK {
		if zSql == uintptr(0) {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = int32(SQLITE_NOMEM)
		} else {
			(*Tsqlite3rbu)(unsafe.Pointer(p)).Frc = Xsqlite3_exec(tls, db, zSql, uintptr(0), uintptr(0), p+36)
		}
	}
	Xsqlite3_free(tls, zSql)
	_ = ap
	return (*Tsqlite3rbu)(unsafe.Pointer(p)).Frc
}

// C documentation
//
//	/*
//	** Remove an item from the main-db lists.
//	*/
func _rbuMainlistRemove(tls *libc.TLS, p uintptr) {
	var pp uintptr
	_ = pp
	Xsqlite3_mutex_enter(tls, (*Trbu_vfs)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs)).Fmutex)
	pp = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs + 100
	for {
		if !(**(**uintptr)(__ccgo_up(pp)) != 0 && **(**uintptr)(__ccgo_up(pp)) != p) {
			break
		}
		goto _1
	_1:
		;
		pp = **(**uintptr)(__ccgo_up(pp)) + 56
	}
	if **(**uintptr)(__ccgo_up(pp)) != 0 {
		**(**uintptr)(__ccgo_up(pp)) = (*Trbu_file)(unsafe.Pointer(p)).FpMainNext
	}
	(*Trbu_file)(unsafe.Pointer(p)).FpMainNext = uintptr(0)
	pp = (*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs + 104
	for {
		if !(**(**uintptr)(__ccgo_up(pp)) != 0 && **(**uintptr)(__ccgo_up(pp)) != p) {
			break
		}
		goto _2
	_2:
		;
		pp = **(**uintptr)(__ccgo_up(pp)) + 60
	}
	if **(**uintptr)(__ccgo_up(pp)) != 0 {
		**(**uintptr)(__ccgo_up(pp)) = (*Trbu_file)(unsafe.Pointer(p)).FpMainRbuNext
	}
	(*Trbu_file)(unsafe.Pointer(p)).FpMainRbuNext = uintptr(0)
	Xsqlite3_mutex_leave(tls, (*Trbu_vfs)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpRbuVfs)).Fmutex)
}

// C documentation
//
//	/*
//	** Clean up any resources allocated as part of the iterator object passed
//	** as the only argument.
//	*/
func _rbuObjIterFinalize(tls *libc.TLS, pIter uintptr) {
	_rbuObjIterClearStatements(tls, pIter)
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpTblIter)
	Xsqlite3_finalize(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FpIdxIter)
	_rbuObjIterFreeCols(tls, pIter)
	libc.Xmemset(tls, pIter, 0, uint32(108))
}

// C documentation
//
//	/*
//	** Free the RbuObjIter.azTblCol[] and RbuObjIter.abTblPk[] arrays allocated
//	** by an earlier call to rbuObjIterCacheTableInfo().
//	*/
func _rbuObjIterFreeCols(tls *libc.TLS, pIter uintptr) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol) {
			break
		}
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol + uintptr(i)*4)))
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up((*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType + uintptr(i)*4)))
		goto _1
	_1:
		;
		i = i + 1
	}
	Xsqlite3_free(tls, (*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblCol = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FazTblType = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FaiSrcOrder = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FabTblPk = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FabNotNull = uintptr(0)
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FnTblCol = 0
	(*TRbuObjIter)(unsafe.Pointer(pIter)).FeType = 0 /* Invalid value */
}

// C documentation
//
//	/*
//	** The first argument must be a nul-terminated string. This function
//	** returns a copy of the string in memory obtained from sqlite3_malloc().
//	** It is the responsibility of the caller to eventually free this memory
//	** using sqlite3_free().
//	**
//	** If an OOM condition is encountered when attempting to allocate memory,
//	** output variable (*pRc) is set to SQLITE_NOMEM before returning. Otherwise,
//	** if the allocation succeeds, (*pRc) is left unchanged.
//	*/
func _rbuStrndup(tls *libc.TLS, zStr uintptr, pRc uintptr) (r uintptr) {
	var nCopy Tsize_t
	var zRet uintptr
	_, _ = nCopy, zRet
	zRet = uintptr(0)
	if **(**int32)(__ccgo_up(pRc)) == SQLITE_OK {
		if zStr != 0 {
			nCopy = libc.Xstrlen(tls, zStr) + uint32(1)
			zRet = Xsqlite3_malloc64(tls, uint64(nCopy))
			if zRet != 0 {
				libc.Xmemcpy(tls, zRet, zStr, nCopy)
			} else {
				**(**int32)(__ccgo_up(pRc)) = int32(SQLITE_NOMEM)
			}
		}
	}
	return zRet
}

// C documentation
//
//	/*
//	** Close an rbu file.
//	*/
func _rbuVfsClose(tls *libc.TLS, pFile uintptr) (r int32) {
	var i, rc int32
	var p, pMeth uintptr
	_, _, _, _ = i, p, pMeth, rc
	p = pFile
	/* Free the contents of the apShm[] array. And the array itself. */
	i = 0
	for {
		if !(i < (*Trbu_file)(unsafe.Pointer(p)).FnShm) {
			break
		}
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up((*Trbu_file)(unsafe.Pointer(p)).FapShm + uintptr(i)*4)))
		goto _1
	_1:
		;
		i = i + 1
	}
	Xsqlite3_free(tls, (*Trbu_file)(unsafe.Pointer(p)).FapShm)
	(*Trbu_file)(unsafe.Pointer(p)).FapShm = uintptr(0)
	Xsqlite3_free(tls, (*Trbu_file)(unsafe.Pointer(p)).FzDel)
	if (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_MAIN_DB) != 0 {
		pMeth = (*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods
		_rbuMainlistRemove(tls, p)
		_rbuUnlockShm(tls, p)
		if (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FiVersion > int32(1) && (*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmUnmap != 0 {
			(*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer(pMeth)).FxShmUnmap})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal, 0)
		}
	} else {
		if (*Trbu_file)(unsafe.Pointer(p)).FopenFlags&int32(SQLITE_OPEN_DELETEONCLOSE) != 0 && (*Trbu_file)(unsafe.Pointer(p)).FpRbu != 0 {
			_rbuUpdateTempSize(tls, p, 0)
		}
	}
	/* Close the underlying file handle */
	rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer((*Trbu_file)(unsafe.Pointer(p)).FpReal)).FpMethods)).FxClose})))(tls, (*Trbu_file)(unsafe.Pointer(p)).FpReal)
	return rc
}

func _recomputeColumnsUsed(tls *libc.TLS, pSelect uintptr, pSrcItem uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	if (*TSrcItem)(unsafe.Pointer(pSrcItem)).FpSTab == uintptr(0) {
		return
	}
	libc.Xmemset(tls, bp, 0, uint32(28))
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_recomputeColumnsUsedExpr)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pSrcItem
	(*TSrcItem)(unsafe.Pointer(pSrcItem)).FcolUsed = uint64(0)
	_sqlite3WalkSelect(tls, bp, pSelect)
}

// C documentation
//
//	/*
//	** Free all structures in the Pager.aSavepoint[] array and set both
//	** Pager.aSavepoint and Pager.nSavepoint to zero. Close the sub-journal
//	** if it is open and the pager is not in exclusive mode.
//	*/
func _releaseAllSavepoints(tls *libc.TLS, pPager uintptr) {
	var ii int32
	_ = ii /* Iterator for looping through Pager.aSavepoint */
	ii = 0
	for {
		if !(ii < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
			break
		}
		_sqlite3BitvecDestroy(tls, (**(**TPagerSavepoint)(__ccgo_up((*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(ii)*48))).FpInSavepoint)
		goto _1
	_1:
		;
		ii = ii + 1
	}
	if !((*TPager)(unsafe.Pointer(pPager)).FexclusiveMode != 0) || _sqlite3JournalIsInMemory(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd) != 0 {
		_sqlite3OsClose(tls, (*TPager)(unsafe.Pointer(pPager)).Fsjfd)
	}
	Xsqlite3_free(tls, (*TPager)(unsafe.Pointer(pPager)).FaSavepoint)
	(*TPager)(unsafe.Pointer(pPager)).FaSavepoint = uintptr(0)
	(*TPager)(unsafe.Pointer(pPager)).FnSavepoint = 0
	(*TPager)(unsafe.Pointer(pPager)).FnSubRec = uint32(0)
}

// C documentation
//
//	/* Remove a single entry from the hash table given a pointer to that
//	** element and a hash on the element's key.
//	*/
func _removeElement(tls *libc.TLS, pH uintptr, elem uintptr) {
	var pEntry uintptr
	_ = pEntry
	if (*THashElem)(unsafe.Pointer(elem)).Fprev != 0 {
		(*THashElem)(unsafe.Pointer((*THashElem)(unsafe.Pointer(elem)).Fprev)).Fnext = (*THashElem)(unsafe.Pointer(elem)).Fnext
	} else {
		(*THash)(unsafe.Pointer(pH)).Ffirst = (*THashElem)(unsafe.Pointer(elem)).Fnext
	}
	if (*THashElem)(unsafe.Pointer(elem)).Fnext != 0 {
		(*THashElem)(unsafe.Pointer((*THashElem)(unsafe.Pointer(elem)).Fnext)).Fprev = (*THashElem)(unsafe.Pointer(elem)).Fprev
	}
	if (*THash)(unsafe.Pointer(pH)).Fht != 0 {
		pEntry = (*THash)(unsafe.Pointer(pH)).Fht + uintptr((*THashElem)(unsafe.Pointer(elem)).Fh%(*THash)(unsafe.Pointer(pH)).Fhtsize)*8
		if (*T_ht)(unsafe.Pointer(pEntry)).Fchain == elem {
			(*T_ht)(unsafe.Pointer(pEntry)).Fchain = (*THashElem)(unsafe.Pointer(elem)).Fnext
		}
		(*T_ht)(unsafe.Pointer(pEntry)).Fcount = (*T_ht)(unsafe.Pointer(pEntry)).Fcount - 1
	}
	Xsqlite3_free(tls, elem)
	(*THash)(unsafe.Pointer(pH)).Fcount = (*THash)(unsafe.Pointer(pH)).Fcount - 1
	if (*THash)(unsafe.Pointer(pH)).Fcount == uint32(0) {
		_sqlite3HashClear(tls, pH)
	}
}

// C documentation
//
//	/*
//	** For each name in the the expression-list pEList (i.e. each
//	** pEList->a[i].zName) that matches the string in zOld, extract the
//	** corresponding rename-token from Parse object pParse and add it
//	** to the RenameCtx pCtx.
//	*/
func _renameColumnElistNames(tls *libc.TLS, pParse uintptr, pCtx uintptr, pEList uintptr, zOld uintptr) {
	var i int32
	var zName uintptr
	_, _ = i, zName
	if pEList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			zName = (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FzEName
			if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME && zName != uintptr(0) && 0 == Xsqlite3_stricmp(tls, zName, zOld) {
				_renameTokenFind(tls, pParse, pCtx, zName)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
}

// C documentation
//
//	/*
//	** For each name in the the id-list pIdList (i.e. each pIdList->a[i].zName)
//	** that matches the string in zOld, extract the corresponding rename-token
//	** from Parse object pParse and add it to the RenameCtx pCtx.
//	*/
func _renameColumnIdlistNames(tls *libc.TLS, pParse uintptr, pCtx uintptr, pIdList uintptr, zOld uintptr) {
	var i int32
	var zName uintptr
	_, _ = i, zName
	if pIdList != 0 {
		i = 0
		for {
			if !(i < (*TIdList)(unsafe.Pointer(pIdList)).FnId) {
				break
			}
			zName = (*(*TIdList_item)(unsafe.Pointer(pIdList + 4 + uintptr(i)*4))).FzName
			if 0 == Xsqlite3_stricmp(tls, zName, zOld) {
				_renameTokenFind(tls, pParse, pCtx, zName)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
}

// C documentation
//
//	/*
//	** The RenameCtx contains a list of tokens that reference a column that
//	** is being renamed by an ALTER TABLE statement.  Return the "last"
//	** RenameToken in the RenameCtx and remove that RenameToken from the
//	** RenameContext.  "Last" means the last RenameToken encountered when
//	** the input SQL is parsed from left to right.  Repeated calls to this routine
//	** return all column name tokens in the order that they are encountered
//	** in the SQL statement.
//	*/
func _renameColumnTokenNext(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pBest, pToken, pp uintptr
	_, _, _ = pBest, pToken, pp
	pBest = (*TRenameCtx)(unsafe.Pointer(pCtx)).FpList
	pToken = (*TRenameToken)(unsafe.Pointer(pBest)).FpNext
	for {
		if !(pToken != 0) {
			break
		}
		if (*TRenameToken)(unsafe.Pointer(pToken)).Ft.Fz > (*TRenameToken)(unsafe.Pointer(pBest)).Ft.Fz {
			pBest = pToken
		}
		goto _1
	_1:
		;
		pToken = (*TRenameToken)(unsafe.Pointer(pToken)).FpNext
	}
	pp = pCtx
	for {
		if !(**(**uintptr)(__ccgo_up(pp)) != pBest) {
			break
		}
		goto _2
	_2:
		;
		pp = **(**uintptr)(__ccgo_up(pp)) + 12
	}
	**(**uintptr)(__ccgo_up(pp)) = (*TRenameToken)(unsafe.Pointer(pBest)).FpNext
	return pBest
}

// C documentation
//
//	/*
//	** Resolve all symbols in the trigger at pParse->pNewTrigger, assuming
//	** it was read from the schema of database zDb. Return SQLITE_OK if
//	** successful. Otherwise, return an SQLite error code and leave an error
//	** message in the Parse object.
//	*/
func _renameResolveTrigger(tls *libc.TLS, pParse uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, p, pNew, pSel, pSrc, pStep, pUpsert, pUpsertSet uintptr
	var i, rc, v2 int32
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _, _, _, _, _, _, _ = db, i, p, pNew, pSel, pSrc, pStep, pUpsert, pUpsertSet, rc, v2
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = (*TParse)(unsafe.Pointer(pParse)).FpNewTrigger
	rc = SQLITE_OK
	libc.Xmemset(tls, bp, 0, uint32(36))
	(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
	(*TParse)(unsafe.Pointer(pParse)).FpTriggerTab = _sqlite3FindTable(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).Ftable, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(_sqlite3SchemaToIndex(tls, db, (*TTrigger)(unsafe.Pointer(pNew)).FpTabSchema))*16))).FzDbSName)
	(*TParse)(unsafe.Pointer(pParse)).FeTriggerOp = (*TTrigger)(unsafe.Pointer(pNew)).Fop
	/* ALWAYS() because if the table of the trigger does not exist, the
	 ** error would have been hit before this point */
	if (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab != 0 {
		rc = libc.BoolInt32(_sqlite3ViewGetColumnNames(tls, pParse, (*TParse)(unsafe.Pointer(pParse)).FpTriggerTab) != 0)
	}
	/* Resolve symbols in WHEN clause */
	if rc == SQLITE_OK && (*TTrigger)(unsafe.Pointer(pNew)).FpWhen != 0 {
		rc = _sqlite3ResolveExprNames(tls, bp, (*TTrigger)(unsafe.Pointer(pNew)).FpWhen)
	}
	pStep = (*TTrigger)(unsafe.Pointer(pNew)).Fstep_list
	for {
		if !(rc == SQLITE_OK && pStep != 0) {
			break
		}
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect != 0 {
			_sqlite3SelectPrep(tls, pParse, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect, bp)
			if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
				rc = (*TParse)(unsafe.Pointer(pParse)).Frc
			}
		}
		if rc == SQLITE_OK && (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
			pSrc = _sqlite3SrcListDup(tls, db, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc, 0)
			if pSrc != 0 {
				pSel = _sqlite3SelectNew(tls, pParse, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, pSrc, uintptr(0), uintptr(0), uintptr(0), uintptr(0), uint32(0), uintptr(0))
				if pSel == uintptr(0) {
					(*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList = uintptr(0)
					pSrc = uintptr(0)
					rc = int32(SQLITE_NOMEM)
				} else {
					/* pStep->pExprList contains an expression-list used for an UPDATE
					 ** statement. So the a[].zEName values are the RHS of the
					 ** "<col> = <expr>" clauses of the UPDATE statement. So, before
					 ** running SelectPrep(), change all the eEName values in
					 ** pStep->pExprList to ENAME_SPAN (from their current value of
					 ** ENAME_NAME). This is to prevent any ids in ON() clauses that are
					 ** part of pSrc from being incorrectly resolved against the
					 ** a[].zEName values as if they were column aliases.  */
					_renameSetENames(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, int32(ENAME_SPAN))
					_sqlite3SelectPrep(tls, pParse, pSel, uintptr(0))
					_renameSetENames(tls, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList, ENAME_NAME)
					if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
						v2 = int32(SQLITE_ERROR)
					} else {
						v2 = SQLITE_OK
					}
					rc = v2
					if (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList != 0 {
						(*TSelect)(unsafe.Pointer(pSel)).FpEList = uintptr(0)
					}
					(*TSelect)(unsafe.Pointer(pSel)).FpSrc = uintptr(0)
					_sqlite3SelectDelete(tls, db, pSel)
				}
				if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
					i = 0
					for {
						if !(i < (*TSrcList)(unsafe.Pointer((*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc)).FnSrc && rc == SQLITE_OK) {
							break
						}
						p = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc + 8 + uintptr(i)*48
						if int32(*(*uint32)(unsafe.Pointer(p + 12 + 4))&0x4>>2) != 0 {
							_sqlite3SelectPrep(tls, pParse, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 44)))).FpSelect, uintptr(0))
						}
						goto _3
					_3:
						;
						i = i + 1
					}
				}
				if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
					rc = int32(SQLITE_NOMEM)
				}
				(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = pSrc
				if rc == SQLITE_OK && (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere != 0 {
					rc = _sqlite3ResolveExprNames(tls, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere)
				}
				if rc == SQLITE_OK {
					rc = _sqlite3ResolveExprListNames(tls, bp, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList)
				}
				if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 && rc == SQLITE_OK {
					pUpsert = (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert
					(*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSrc = pSrc
					*(*uintptr)(unsafe.Pointer(bp + 8)) = pUpsert
					(**(**TNameContext)(__ccgo_up(bp))).FncFlags = int32(NC_UUpsert)
					rc = _sqlite3ResolveExprListNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
					if rc == SQLITE_OK {
						pUpsertSet = (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSet
						rc = _sqlite3ResolveExprListNames(tls, bp, pUpsertSet)
					}
					if rc == SQLITE_OK {
						rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere)
					}
					if rc == SQLITE_OK {
						rc = _sqlite3ResolveExprNames(tls, bp, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
					}
					(**(**TNameContext)(__ccgo_up(bp))).FncFlags = 0
				}
				(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = uintptr(0)
				_sqlite3SrcListDelete(tls, db, pSrc)
			} else {
				rc = int32(SQLITE_NOMEM)
			}
		}
		goto _1
	_1:
		;
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
	return rc
}

// C documentation
//
//	/*
//	** Search the Parse object passed as the first argument for a RenameToken
//	** object associated with parse tree element pPtr. If found, return a pointer
//	** to it. Otherwise, return NULL.
//	**
//	** If the second argument passed to this function is not NULL and a matching
//	** RenameToken object is found, remove it from the Parse object and add it to
//	** the list maintained by the RenameCtx object.
//	*/
func _renameTokenFind(tls *libc.TLS, pParse uintptr, pCtx uintptr, pPtr uintptr) (r uintptr) {
	var pToken, pp uintptr
	_, _ = pToken, pp
	if pPtr == uintptr(0) {
		return uintptr(0)
	}
	pp = pParse + 276
	for {
		if !(**(**uintptr)(__ccgo_up(pp)) != 0) {
			break
		}
		if (*TRenameToken)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).Fp == pPtr {
			pToken = **(**uintptr)(__ccgo_up(pp))
			if pCtx != 0 {
				**(**uintptr)(__ccgo_up(pp)) = (*TRenameToken)(unsafe.Pointer(pToken)).FpNext
				(*TRenameToken)(unsafe.Pointer(pToken)).FpNext = (*TRenameCtx)(unsafe.Pointer(pCtx)).FpList
				(*TRenameCtx)(unsafe.Pointer(pCtx)).FpList = pToken
				(*TRenameCtx)(unsafe.Pointer(pCtx)).FnList = (*TRenameCtx)(unsafe.Pointer(pCtx)).FnList + 1
			}
			return pToken
		}
		goto _1
	_1:
		;
		pp = **(**uintptr)(__ccgo_up(pp)) + 12
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Invoke sqlite3WalkExpr() or sqlite3WalkSelect() on all Select or Expr
//	** objects that are part of the trigger passed as the second argument.
//	*/
func _renameWalkTrigger(tls *libc.TLS, pWalker uintptr, pTrigger uintptr) {
	var i int32
	var pSrc, pStep, pUpsert uintptr
	_, _, _, _ = i, pSrc, pStep, pUpsert
	/* Find tokens to edit in WHEN clause */
	_sqlite3WalkExpr(tls, pWalker, (*TTrigger)(unsafe.Pointer(pTrigger)).FpWhen)
	/* Find tokens to edit in trigger steps */
	pStep = (*TTrigger)(unsafe.Pointer(pTrigger)).Fstep_list
	for {
		if !(pStep != 0) {
			break
		}
		_sqlite3WalkSelect(tls, pWalker, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect)
		_sqlite3WalkExpr(tls, pWalker, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere)
		_sqlite3WalkExprList(tls, pWalker, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList)
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert != 0 {
			pUpsert = (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert
			_sqlite3WalkExprList(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTarget)
			_sqlite3WalkExprList(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertSet)
			_sqlite3WalkExpr(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertWhere)
			_sqlite3WalkExpr(tls, pWalker, (*TUpsert)(unsafe.Pointer(pUpsert)).FpUpsertTargetWhere)
		}
		if (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc != 0 {
			pSrc = (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc
			i = 0
			for {
				if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
					break
				}
				if int32(*(*uint32)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 12 + 4))&0x4>>2) != 0 {
					_sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48 + 44)))).FpSelect)
				}
				goto _2
			_2:
				;
				i = i + 1
			}
		}
		goto _1
	_1:
		;
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
}

// C documentation
//
//	/*
//	** Iterate through the Select objects that are part of WITH clauses attached
//	** to select statement pSelect.
//	*/
func _renameWalkWith(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var i int32
	var p, pCopy, pParse, pWith uintptr
	var _ /* sNC at bp+0 */ TNameContext
	_, _, _, _, _ = i, p, pCopy, pParse, pWith
	pWith = (*TSelect)(unsafe.Pointer(pSelect)).FpWith
	if pWith != 0 {
		pParse = (*TWalker)(unsafe.Pointer(pWalker)).FpParse
		pCopy = uintptr(0)
		if (*TSelect)(unsafe.Pointer((*(*TCte)(unsafe.Pointer(pWith + 12))).FpSelect)).FselFlags&uint32(SF_Expanded) == uint32(0) {
			/* Push a copy of the With object onto the with-stack. We use a copy
			 ** here as the original will be expanded and resolved (flags SF_Expanded
			 ** and SF_Resolved) below. And the parser code that uses the with-stack
			 ** fails if the Select objects on it have already been expanded and
			 ** resolved.  */
			pCopy = _sqlite3WithDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pWith)
			pCopy = _sqlite3WithPush(tls, pParse, pCopy, uint8(1))
		}
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(pWith)).FnCte) {
				break
			}
			p = (*(*TCte)(unsafe.Pointer(pWith + 12 + uintptr(i)*24))).FpSelect
			libc.Xmemset(tls, bp, 0, uint32(36))
			(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
			if pCopy != 0 {
				_sqlite3SelectPrep(tls, (**(**TNameContext)(__ccgo_up(bp))).FpParse, p, bp)
			}
			if (*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer((**(**TNameContext)(__ccgo_up(bp))).FpParse)).Fdb)).FmallocFailed != 0 {
				return
			}
			_sqlite3WalkSelect(tls, pWalker, p)
			_sqlite3RenameExprlistUnmap(tls, pParse, (*(*TCte)(unsafe.Pointer(pWith + 12 + uintptr(i)*24))).FpCols)
			goto _1
		_1:
			;
			i = i + 1
		}
		if pCopy != 0 && (*TParse)(unsafe.Pointer(pParse)).FpWith == pCopy {
			(*TParse)(unsafe.Pointer(pParse)).FpWith = (*TWith)(unsafe.Pointer(pCopy)).FpOuter
		}
	}
}

// C documentation
//
//	/*
//	** *piCursor is a cursor number.  Change it if it needs to be mapped.
//	*/
func _renumberCursorDoMapping(tls *libc.TLS, pWalker uintptr, piCursor uintptr) {
	var aCsrMap uintptr
	var iCsr int32
	_, _ = aCsrMap, iCsr
	aCsrMap = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	iCsr = **(**int32)(__ccgo_up(piCursor))
	if iCsr < **(**int32)(__ccgo_up(aCsrMap)) && **(**int32)(__ccgo_up(aCsrMap + uintptr(iCsr+int32(1))*4)) > 0 {
		**(**int32)(__ccgo_up(piCursor)) = **(**int32)(__ccgo_up(aCsrMap + uintptr(iCsr+int32(1))*4))
	}
}

// C documentation
//
//	/*
//	** Assign a new cursor number to each cursor in the FROM clause (Select.pSrc)
//	** of the SELECT statement passed as the second argument, and to each
//	** cursor in the FROM clause of any FROM clause sub-selects, recursively.
//	** Except, do not assign a new cursor number to the iExcept'th element in
//	** the FROM clause of (*p). Update all expressions and other references
//	** to refer to the new cursor numbers.
//	**
//	** Argument aCsrMap is an array that may be used for temporary working
//	** space. Two guarantees are made by the caller:
//	**
//	**   * the array is larger than the largest cursor number used within the
//	**     select statement passed as an argument, and
//	**
//	**   * the array entries for all cursor numbers that do *not* appear in
//	**     FROM clauses of the select statement as described above are
//	**     initialized to zero.
//	*/
func _renumberCursors(tls *libc.TLS, pParse uintptr, p uintptr, iExcept int32, aCsrMap uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	_srclistRenumberCursors(tls, pParse, aCsrMap, (*TSelect)(unsafe.Pointer(p)).FpSrc, iExcept)
	libc.Xmemset(tls, bp, 0, uint32(28))
	*(*uintptr)(unsafe.Pointer(bp + 24)) = aCsrMap
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_renumberCursorsCb)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	_sqlite3WalkSelect(tls, bp, p)
}

// C documentation
//
//	/*
//	** pE is a pointer to an expression which is a single term in the
//	** ORDER BY of a compound SELECT.  The expression has not been
//	** name resolved.
//	**
//	** At the point this routine is called, we already know that the
//	** ORDER BY term is not an integer index into the result set.  That
//	** case is handled by the calling routine.
//	**
//	** Attempt to match pE against result set columns in the left-most
//	** SELECT statement.  Return the index i of the matching column,
//	** as an indication to the caller that it should sort by the i-th column.
//	** The left-most column is 1.  In other words, the value returned is the
//	** same integer value that would be used in the SQL statement to indicate
//	** the column.
//	**
//	** If there is no match, return 0.  Return -1 if an error occurs.
//	*/
func _resolveOrderByTermToExprList(tls *libc.TLS, pParse uintptr, pSelect uintptr, pE uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var db, pEList uintptr
	var i, rc int32
	var savedSuppErr Tu8
	var _ /* nc at bp+0 */ TNameContext
	_, _, _, _, _ = db, i, pEList, rc, savedSuppErr /* Saved value of db->suppressErr */
	pEList = (*TSelect)(unsafe.Pointer(pSelect)).FpEList
	/* Resolve all names in the ORDER BY term expression
	 */
	libc.Xmemset(tls, bp, 0, uint32(36))
	(**(**TNameContext)(__ccgo_up(bp))).FpParse = pParse
	(**(**TNameContext)(__ccgo_up(bp))).FpSrcList = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	*(*uintptr)(unsafe.Pointer(bp + 8)) = pEList
	(**(**TNameContext)(__ccgo_up(bp))).FncFlags = libc.Int32FromInt32(NC_AllowAgg) | libc.Int32FromInt32(NC_UEList) | libc.Int32FromInt32(NC_NoSelect)
	(**(**TNameContext)(__ccgo_up(bp))).FnNcErr = 0
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	savedSuppErr = (*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr
	(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = uint8(1)
	rc = _sqlite3ResolveExprNames(tls, bp, pE)
	(*Tsqlite3)(unsafe.Pointer(db)).FsuppressErr = savedSuppErr
	if rc != 0 {
		return 0
	}
	/* Try to match the ORDER BY expression against an expression
	 ** in the result set.  Return an 1-based index of the matching
	 ** result-set entry.
	 */
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
			break
		}
		if _sqlite3ExprCompare(tls, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FpExpr, pE, -int32(1)) < int32(2) {
			return i + int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	/* If no match, return 0. */
	return 0
}

// C documentation
//
//	/*
//	** Merge two lists of RowSetEntry objects.  Remove duplicates.
//	**
//	** The input lists are connected via pRight pointers and are
//	** assumed to each already be in sorted order.
//	*/
func _rowSetEntryMerge(tls *libc.TLS, pA uintptr, pB uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pTail, v2 uintptr
	var _ /* head at bp+0 */ TRowSetEntry
	_, _ = pTail, v2
	pTail = bp
	for {
		if (*TRowSetEntry)(unsafe.Pointer(pA)).Fv <= (*TRowSetEntry)(unsafe.Pointer(pB)).Fv {
			if (*TRowSetEntry)(unsafe.Pointer(pA)).Fv < (*TRowSetEntry)(unsafe.Pointer(pB)).Fv {
				v2 = pA
				(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = v2
				pTail = v2
			}
			pA = (*TRowSetEntry)(unsafe.Pointer(pA)).FpRight
			if pA == uintptr(0) {
				(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = pB
				break
			}
		} else {
			v2 = pB
			(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = v2
			pTail = v2
			pB = (*TRowSetEntry)(unsafe.Pointer(pB)).FpRight
			if pB == uintptr(0) {
				(*TRowSetEntry)(unsafe.Pointer(pTail)).FpRight = pA
				break
			}
		}
		goto _1
	_1:
	}
	return (**(**TRowSetEntry)(__ccgo_up(bp))).FpRight
}

// C documentation
//
//	/*
//	** Sort all elements on the list of RowSetEntry objects into order of
//	** increasing v.
//	*/
func _rowSetEntrySort(tls *libc.TLS, pIn uintptr) (r uintptr) {
	bp := tls.Alloc(160)
	defer tls.Free(160)
	var i uint32
	var pNext, v3 uintptr
	var _ /* aBucket at bp+0 */ [40]uintptr
	_, _, _ = i, pNext, v3
	libc.Xmemset(tls, bp, 0, uint32(160))
	for pIn != 0 {
		pNext = (*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight
		(*TRowSetEntry)(unsafe.Pointer(pIn)).FpRight = uintptr(0)
		i = uint32(0)
		for {
			if !((**(**[40]uintptr)(__ccgo_up(bp)))[i] != 0) {
				break
			}
			pIn = _rowSetEntryMerge(tls, (**(**[40]uintptr)(__ccgo_up(bp)))[i], pIn)
			(**(**[40]uintptr)(__ccgo_up(bp)))[i] = uintptr(0)
			goto _1
		_1:
			;
			i = i + 1
		}
		(**(**[40]uintptr)(__ccgo_up(bp)))[i] = pIn
		pIn = pNext
	}
	pIn = (**(**[40]uintptr)(__ccgo_up(bp)))[0]
	i = uint32(1)
	for {
		if !(i < libc.Uint32FromInt64(160)/libc.Uint32FromInt64(4)) {
			break
		}
		if (**(**[40]uintptr)(__ccgo_up(bp)))[i] == uintptr(0) {
			goto _2
		}
		if pIn != 0 {
			v3 = _rowSetEntryMerge(tls, pIn, (**(**[40]uintptr)(__ccgo_up(bp)))[i])
		} else {
			v3 = (**(**[40]uintptr)(__ccgo_up(bp)))[i]
		}
		pIn = v3
		goto _2
	_2:
		;
		i = i + 1
	}
	return pIn
}

// C documentation
//
//	/*
//	** Remove the entry with rowid=iDelete from the r-tree structure.
//	*/
func _rtreeDeleteRowid(tls *libc.TLS, pRtree uintptr, iDelete Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var iChild Ti64
	var rc, rc2, rc21 int32
	var _ /* iCell at bp+4 */ int32
	var _ /* pChild at bp+12 */ uintptr
	var _ /* pLeaf at bp+0 */ uintptr
	var _ /* pRoot at bp+8 */ uintptr
	_, _, _, _ = iChild, rc, rc2, rc21            /* Return code */
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)     /* Index of iDelete cell in pLeaf */
	**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0) /* Root node of rtree structure */
	/* Obtain a reference to the root node to initialize Rtree.iDepth */
	rc = _nodeAcquire(tls, pRtree, int64(1), uintptr(0), bp+8)
	/* Obtain a reference to the leaf node that contains the entry
	 ** about to be deleted.
	 */
	if rc == SQLITE_OK {
		rc = _findLeafNode(tls, pRtree, iDelete, bp, uintptr(0))
	}
	/* Delete the cell in question from the leaf node. */
	if rc == SQLITE_OK && **(**uintptr)(__ccgo_up(bp)) != 0 {
		rc = _nodeRowidIndex(tls, pRtree, **(**uintptr)(__ccgo_up(bp)), iDelete, bp+4)
		if rc == SQLITE_OK {
			rc = _deleteCell(tls, pRtree, **(**uintptr)(__ccgo_up(bp)), **(**int32)(__ccgo_up(bp + 4)), 0)
		}
		rc2 = _nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp)))
		if rc == SQLITE_OK {
			rc = rc2
		}
	}
	/* Delete the corresponding entry in the <rtree>_rowid table. */
	if rc == SQLITE_OK {
		Xsqlite3_bind_int64(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteRowid, int32(1), iDelete)
		Xsqlite3_step(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
		rc = Xsqlite3_reset(tls, (*TRtree)(unsafe.Pointer(pRtree)).FpDeleteRowid)
	}
	/* Check if the root node now has exactly one child. If so, remove
	 ** it, schedule the contents of the child for reinsertion and
	 ** reduce the tree height by one.
	 **
	 ** This is equivalent to copying the contents of the child into
	 ** the root node (the operation that Gutman's paper says to perform
	 ** in this scenario).
	 */
	if rc == SQLITE_OK && (*TRtree)(unsafe.Pointer(pRtree)).FiDepth > 0 && _readInt16(tls, (*TRtreeNode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FzData+2) == int32(1) {
		**(**uintptr)(__ccgo_up(bp + 12)) = uintptr(0)
		iChild = _nodeGetRowid(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 8)), 0)
		rc = _nodeAcquire(tls, pRtree, iChild, **(**uintptr)(__ccgo_up(bp + 8)), bp+12) /* tag-20210916a */
		if rc == SQLITE_OK {
			rc = _removeNode(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 12)), (*TRtree)(unsafe.Pointer(pRtree)).FiDepth-int32(1))
		}
		rc21 = _nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 12)))
		if rc == SQLITE_OK {
			rc = rc21
		}
		if rc == SQLITE_OK {
			(*TRtree)(unsafe.Pointer(pRtree)).FiDepth = (*TRtree)(unsafe.Pointer(pRtree)).FiDepth - 1
			_writeInt16(tls, (*TRtreeNode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FzData, (*TRtree)(unsafe.Pointer(pRtree)).FiDepth)
			(*TRtreeNode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp + 8)))).FisDirty = int32(1)
		}
	}
	/* Re-insert the contents of any underfull nodes removed from the tree. */
	**(**uintptr)(__ccgo_up(bp)) = (*TRtree)(unsafe.Pointer(pRtree)).FpDeleted
	for {
		if !(**(**uintptr)(__ccgo_up(bp)) != 0) {
			break
		}
		if rc == SQLITE_OK {
			rc = _reinsertNodeContent(tls, pRtree, **(**uintptr)(__ccgo_up(bp)))
		}
		(*TRtree)(unsafe.Pointer(pRtree)).FpDeleted = (*TRtreeNode)(unsafe.Pointer(**(**uintptr)(__ccgo_up(bp)))).FpNext
		(*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef = (*TRtree)(unsafe.Pointer(pRtree)).FnNodeRef - 1
		Xsqlite3_free(tls, **(**uintptr)(__ccgo_up(bp)))
		goto _1
	_1:
		;
		**(**uintptr)(__ccgo_up(bp)) = (*TRtree)(unsafe.Pointer(pRtree)).FpDeleted
	}
	/* Release the reference to the root node. */
	if rc == SQLITE_OK {
		rc = _nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 8)))
	} else {
		_nodeRelease(tls, pRtree, **(**uintptr)(__ccgo_up(bp + 8)))
	}
	return rc
}

/*
** Rounding constants for float->double conversion.
 */

// C documentation
//
//	/*
//	** Check the leaf RTree cell given by pCellData against constraint p.
//	** If this constraint is not satisfied, set *peWithin to NOT_WITHIN.
//	** If the constraint is satisfied, leave *peWithin unchanged.
//	**
//	** The constraint is of the form:  xN op $val
//	**
//	** The op is given by p->op.  The xN is p->iCoord-th coordinate in
//	** pCellData.  $val is given by p->u.rValue.
//	*/
func _rtreeLeafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var xN TRtreeDValue
	var v1 Tsqlite3_rtree_dbl
	var _ /* c at bp+0 */ TRtreeCoord
	_, _ = xN, v1 /* Coordinate value converted to a double */
	pCellData = pCellData + uintptr(int32(8)+(*TRtreeConstraint)(unsafe.Pointer(p)).FiCoord*int32(4))
	/* Coordinate decoded */
	libc.Xmemcpy(tls, bp, pCellData, uint32(4))
	*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp))&uint32(0xff)<<int32(24) | *(*Tu32)(unsafe.Pointer(bp))&uint32(0xff00)<<int32(8)
	if eInt != 0 {
		v1 = float64(*(*int32)(unsafe.Pointer(bp)))
	} else {
		v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
	}
	xN = v1
	switch (*TRtreeConstraint)(unsafe.Pointer(p)).Fop {
	case int32(RTREE_TRUE):
		return /* Always satisfied */
	case int32(RTREE_FALSE):
	case int32(RTREE_LE):
		if xN <= *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	case int32(RTREE_LT):
		if xN < *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	case int32(RTREE_GE):
		if xN >= *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	case int32(RTREE_GT):
		if xN > *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
	default:
		if xN == *(*TRtreeDValue)(unsafe.Pointer(p + 8)) {
			return
		}
		break
	}
	**(**int32)(__ccgo_up(peWithin)) = NOT_WITHIN
}

// C documentation
//
//	/*
//	** This routine frees the BLOB that is returned by geomCallback().
//	*/
func _rtreeMatchArgFree(tls *libc.TLS, pArg uintptr) {
	var i int32
	var p uintptr
	_, _ = i, p
	p = pArg
	i = 0
	for {
		if !(i < (*TRtreeMatchArg)(unsafe.Pointer(p)).FnParam) {
			break
		}
		Xsqlite3_value_free(tls, **(**uintptr)(__ccgo_up((*TRtreeMatchArg)(unsafe.Pointer(p)).FapSqlParam + uintptr(i)*4)))
		goto _1
	_1:
		;
		i = i + 1
	}
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Check the internal RTree node given by pCellData against constraint p.
//	** If this constraint cannot be satisfied by any child within the node,
//	** set *peWithin to NOT_WITHIN.
//	*/
func _rtreeNonleafConstraint(tls *libc.TLS, p uintptr, eInt int32, pCellData uintptr, peWithin uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var val, v1 Tsqlite3_rtree_dbl
	var _ /* c at bp+0 */ TRtreeCoord
	var _ /* c at bp+12 */ TRtreeCoord
	var _ /* c at bp+4 */ TRtreeCoord
	var _ /* c at bp+8 */ TRtreeCoord
	_, _ = val, v1 /* Coordinate value convert to a double */
	/* p->iCoord might point to either a lower or upper bound coordinate
	 ** in a coordinate pair.  But make pCellData point to the lower bound.
	 */
	pCellData = pCellData + uintptr(int32(8)+int32(4)*((*TRtreeConstraint)(unsafe.Pointer(p)).FiCoord&int32(0xfe)))
	switch (*TRtreeConstraint)(unsafe.Pointer(p)).Fop {
	case int32(RTREE_TRUE):
		return /* Always satisfied */
	case int32(RTREE_FALSE):
	case int32(RTREE_EQ):
		/* Coordinate decoded */ libc.Xmemcpy(tls, bp, pCellData, uint32(4))
		*(*Tu32)(unsafe.Pointer(bp)) = *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp))&uint32(0xff)<<int32(24) | *(*Tu32)(unsafe.Pointer(bp))&uint32(0xff00)<<int32(8)
		if eInt != 0 {
			v1 = float64(*(*int32)(unsafe.Pointer(bp)))
		} else {
			v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp)))
		}
		val = v1
		/* val now holds the lower bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) >= val {
			pCellData = pCellData + uintptr(4)
			/* Coordinate decoded */ libc.Xmemcpy(tls, bp+4, pCellData, uint32(4))
			*(*Tu32)(unsafe.Pointer(bp + 4)) = *(*Tu32)(unsafe.Pointer(bp + 4))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp + 4))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp + 4))&uint32(0xff)<<int32(24) | *(*Tu32)(unsafe.Pointer(bp + 4))&uint32(0xff00)<<int32(8)
			if eInt != 0 {
				v1 = float64(*(*int32)(unsafe.Pointer(bp + 4)))
			} else {
				v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 4)))
			}
			val = v1
			/* val now holds the upper bound of the coordinate pair */
			if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) <= val {
				return
			}
		}
	case int32(RTREE_LE):
		fallthrough
	case int32(RTREE_LT):
		/* Coordinate decoded */ libc.Xmemcpy(tls, bp+8, pCellData, uint32(4))
		*(*Tu32)(unsafe.Pointer(bp + 8)) = *(*Tu32)(unsafe.Pointer(bp + 8))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp + 8))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp + 8))&uint32(0xff)<<int32(24) | *(*Tu32)(unsafe.Pointer(bp + 8))&uint32(0xff00)<<int32(8)
		if eInt != 0 {
			v1 = float64(*(*int32)(unsafe.Pointer(bp + 8)))
		} else {
			v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 8)))
		}
		val = v1
		/* val now holds the lower bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) >= val {
			return
		}
	default:
		pCellData = pCellData + uintptr(4)
		/* Coordinate decoded */ libc.Xmemcpy(tls, bp+12, pCellData, uint32(4))
		*(*Tu32)(unsafe.Pointer(bp + 12)) = *(*Tu32)(unsafe.Pointer(bp + 12))>>libc.Int32FromInt32(24)&uint32(0xff) | *(*Tu32)(unsafe.Pointer(bp + 12))>>libc.Int32FromInt32(8)&uint32(0xff00) | *(*Tu32)(unsafe.Pointer(bp + 12))&uint32(0xff)<<int32(24) | *(*Tu32)(unsafe.Pointer(bp + 12))&uint32(0xff00)<<int32(8)
		if eInt != 0 {
			v1 = float64(*(*int32)(unsafe.Pointer(bp + 12)))
		} else {
			v1 = float64(*(*TRtreeValue)(unsafe.Pointer(bp + 12)))
		}
		val = v1
		/* val now holds the upper bound of the coordinate pair */
		if *(*TRtreeDValue)(unsafe.Pointer(p + 8)) <= val {
			return
		}
		break
	}
	**(**int32)(__ccgo_up(peWithin)) = NOT_WITHIN
}

// C documentation
//
//	/*
//	** Return the search point with the lowest current score.
//	*/
func _rtreeSearchPointFirst(tls *libc.TLS, pCur uintptr) (r uintptr) {
	var v1, v2 uintptr
	_, _ = v1, v2
	if (*TRtreeCursor)(unsafe.Pointer(pCur)).FbPoint != 0 {
		v1 = pCur + 40
	} else {
		if (*TRtreeCursor)(unsafe.Pointer(pCur)).FnPoint != 0 {
			v2 = (*TRtreeCursor)(unsafe.Pointer(pCur)).FaPoint
		} else {
			v2 = uintptr(0)
		}
		v1 = v2
	}
	return v1
}

// C documentation
//
//	/*
//	** Return true if zName is the extension on one of the shadow tables used
//	** by this module.
//	*/
func _rtreeShadowName(tls *libc.TLS, zName uintptr) (r int32) {
	var i uint32
	_ = i
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(12)/libc.Uint32FromInt64(4)) {
			break
		}
		if Xsqlite3_stricmp(tls, zName, _azName1[i]) == 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return 0
}

// C documentation
//
//	/*
//	** If any term of pSrc, or any SF_NestedFrom sub-query, is not the same
//	** as pSrcItem but has the same alias as p0, then return true.
//	** Otherwise return false.
//	*/
func _sameSrcAlias(tls *libc.TLS, p0 uintptr, pSrc uintptr) (r int32) {
	var i int32
	var p1 uintptr
	_, _ = i, p1
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		p1 = pSrc + 8 + uintptr(i)*48
		if p1 == p0 {
			goto _1
		}
		if (*TSrcItem)(unsafe.Pointer(p0)).FpSTab == (*TSrcItem)(unsafe.Pointer(p1)).FpSTab && 0 == Xsqlite3_stricmp(tls, (*TSrcItem)(unsafe.Pointer(p0)).FzAlias, (*TSrcItem)(unsafe.Pointer(p1)).FzAlias) {
			return int32(1)
		}
		if int32(*(*uint32)(unsafe.Pointer(p1 + 12 + 4))&0x4>>2) != 0 && (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p1 + 44)))).FpSelect)).FselFlags&uint32(SF_NestedFrom) != uint32(0) && _sameSrcAlias(tls, p0, (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p1 + 44)))).FpSelect)).FpSrc) != 0 {
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return 0
}

// C documentation
//
//	/* Reclaim memory used by a StatSample
//	*/
func _sampleClear(tls *libc.TLS, db uintptr, p uintptr) {
	if (*TStatSample)(unsafe.Pointer(p)).FnRowid != 0 {
		_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(&(*TStatSample)(unsafe.Pointer(p)).Fu)))
		(*TStatSample)(unsafe.Pointer(p)).FnRowid = uint32(0)
	}
}

// C documentation
//
//	/*
//	** Argument pWith (which may be NULL) points to a linked list of nested
//	** WITH contexts, from inner to outermost. If the table identified by
//	** FROM clause element pItem is really a common-table-expression (CTE)
//	** then return a pointer to the CTE definition for that table. Otherwise
//	** return NULL.
//	**
//	** If a non-NULL value is returned, set *ppContext to point to the With
//	** object that the returned CTE belongs to.
//	*/
func _searchWith(tls *libc.TLS, pWith uintptr, pItem uintptr, ppContext uintptr) (r uintptr) {
	var i int32
	var p, zName uintptr
	_, _, _ = i, p, zName
	zName = (*TSrcItem)(unsafe.Pointer(pItem)).FzName
	p = pWith
	for {
		if !(p != 0) {
			break
		}
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(p)).FnCte) {
				break
			}
			if _sqlite3StrICmp(tls, zName, (*(*TCte)(unsafe.Pointer(p + 12 + uintptr(i)*24))).FzName) == 0 {
				**(**uintptr)(__ccgo_up(ppContext)) = p
				return p + 12 + uintptr(i)*24
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		if (*TWith)(unsafe.Pointer(p)).FbView != 0 {
			break
		}
		goto _1
	_1:
		;
		p = (*TWith)(unsafe.Pointer(p)).FpOuter
	}
	return uintptr(0)
}

func _selectRefLeave(tls *libc.TLS, pWalker uintptr, pSelect uintptr) {
	var p, pSrc uintptr
	_, _ = p, pSrc
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	if (*TRefSrcList)(unsafe.Pointer(p)).FnExclude != 0 {
		**(**Ti64)(__ccgo_up(p + 8)) -= int64((*TSrcList)(unsafe.Pointer(pSrc)).FnSrc)
	}
}

// C documentation
//
//	/*
//	** Iterate through each expression in expression-list pEList. For each:
//	**
//	**   * TK_COLUMN,
//	**   * aggregate function, or
//	**   * window function with a Window object that is not a member of the
//	**     Window list passed as the second argument (pWin).
//	**
//	** Append the node to output expression-list (*ppSub). And replace it
//	** with a TK_COLUMN that reads the (N-1)th element of table
//	** pWin->iEphCsr, where N is the number of elements in (*ppSub) after
//	** appending the new one.
//	*/
func _selectWindowRewriteEList(tls *libc.TLS, pParse uintptr, pWin uintptr, pSrc uintptr, pEList uintptr, pTab uintptr, ppSub uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* sRewrite at bp+28 */ TWindowRewrite
	var _ /* sWalker at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	libc.Xmemset(tls, bp+28, 0, uint32(20))
	(**(**TWindowRewrite)(__ccgo_up(bp + 28))).FpSub = **(**uintptr)(__ccgo_up(ppSub))
	(**(**TWindowRewrite)(__ccgo_up(bp + 28))).FpWin = pWin
	(**(**TWindowRewrite)(__ccgo_up(bp + 28))).FpSrc = pSrc
	(**(**TWindowRewrite)(__ccgo_up(bp + 28))).FpTab = pTab
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_selectWindowRewriteExprCb)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_selectWindowRewriteSelectCb)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = bp + 28
	_sqlite3WalkExprList(tls, bp, pEList)
	**(**uintptr)(__ccgo_up(ppSub)) = (**(**TWindowRewrite)(__ccgo_up(bp + 28))).FpSub
}

func _selectWindowRewriteSelectCb(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	var p, pSave uintptr
	_, _ = p, pSave
	p = *(*uintptr)(unsafe.Pointer(pWalker + 24))
	pSave = (*TWindowRewrite)(unsafe.Pointer(p)).FpSubSelect
	if pSave == pSelect {
		return WRC_Continue
	} else {
		(*TWindowRewrite)(unsafe.Pointer(p)).FpSubSelect = pSelect
		_sqlite3WalkSelect(tls, pWalker, pSelect)
		(*TWindowRewrite)(unsafe.Pointer(p)).FpSubSelect = pSave
	}
	return int32(WRC_Prune)
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append a single byte to the buffer.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendByte(tls *libc.TLS, p uintptr, v Tu8, pRc uintptr) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	if 0 == _sessionBufferGrow(tls, p, int64(1), pRc) {
		v2 = p + 4
		v1 = *(*int32)(unsafe.Pointer(v2))
		*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
		**(**Tu8)(__ccgo_up((*TSessionBuffer)(unsafe.Pointer(p)).FaBuf + uintptr(v1))) = v
	}
}

// C documentation
//
//	/*
//	** Append the value passed as the second argument to the buffer passed
//	** as the first.
//	**
//	** This function is a no-op if *pRc is non-zero when it is called.
//	** Otherwise, if an error occurs, *pRc is set to an SQLite error code
//	** before returning.
//	*/
func _sessionAppendValue(tls *libc.TLS, p uintptr, pVal uintptr, pRc uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var v1 uintptr
	var _ /* nByte at bp+8 */ Tsqlite3_int64
	var _ /* rc at bp+0 */ int32
	_ = v1
	**(**int32)(__ccgo_up(bp)) = **(**int32)(__ccgo_up(pRc))
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		**(**Tsqlite3_int64)(__ccgo_up(bp + 8)) = 0
		**(**int32)(__ccgo_up(bp)) = _sessionSerializeValue(tls, uintptr(0), pVal, bp+8)
		_sessionBufferGrow(tls, p, **(**Tsqlite3_int64)(__ccgo_up(bp + 8)), bp)
		if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp)) = _sessionSerializeValue(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), pVal, uintptr(0))
			v1 = p + 4
			*(*int32)(unsafe.Pointer(v1)) = int32(int64(*(*int32)(unsafe.Pointer(v1))) + **(**Tsqlite3_int64)(__ccgo_up(bp + 8)))
		} else {
			**(**int32)(__ccgo_up(pRc)) = **(**int32)(__ccgo_up(bp))
		}
	}
}

// C documentation
//
//	/*
//	** This function is a no-op if *pRc is other than SQLITE_OK when it is
//	** called. Otherwise, append a single varint to the buffer.
//	**
//	** If an OOM condition is encountered, set *pRc to SQLITE_NOMEM before
//	** returning.
//	*/
func _sessionAppendVarint(tls *libc.TLS, p uintptr, v int32, pRc uintptr) {
	if 0 == _sessionBufferGrow(tls, p, int64(9), pRc) {
		**(**int32)(__ccgo_up(p + 4)) += _sessionVarintPut(tls, (*TSessionBuffer)(unsafe.Pointer(p)).FaBuf+uintptr((*TSessionBuffer)(unsafe.Pointer(p)).FnBuf), v)
	}
}

// C documentation
//
//	/*
//	** Attempt to apply the change that the iterator passed as the first argument
//	** currently points to to the database. If a conflict is encountered, invoke
//	** the conflict handler callback.
//	**
//	** If argument pbRetry is NULL, then ignore any CHANGESET_DATA conflict. If
//	** one is encountered, update or delete the row with the matching primary key
//	** instead. Or, if pbRetry is not NULL and a CHANGESET_DATA conflict occurs,
//	** invoke the conflict handler. If it returns CHANGESET_REPLACE, set *pbRetry
//	** to true before returning. In this case the caller will invoke this function
//	** again, this time with pbRetry set to NULL.
//	**
//	** If argument pbReplace is NULL and a CHANGESET_CONFLICT conflict is
//	** encountered invoke the conflict handler with CHANGESET_CONSTRAINT instead.
//	** Or, if pbReplace is not NULL, invoke it with CHANGESET_CONFLICT. If such
//	** an invocation returns SQLITE_CHANGESET_REPLACE, set *pbReplace to true
//	** before retrying. In this case the caller attempts to remove the conflicting
//	** row before invoking this function again, this time with pbReplace set
//	** to NULL.
//	**
//	** If any conflict handler returns SQLITE_CHANGESET_ABORT, this function
//	** returns SQLITE_ABORT. Otherwise, if no error occurs, SQLITE_OK is
//	** returned.
//	*/
func _sessionApplyOneOp(tls *libc.TLS, pIter uintptr, p uintptr, __ccgo_fp_xConflict uintptr, pCtx uintptr, pbReplace uintptr, pbRetry uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var abPK, pNew, pOld, v1 uintptr
	var bPatchset, i, rc int32
	var _ /* nCol at bp+8 */ int32
	var _ /* op at bp+4 */ int32
	var _ /* pUp at bp+12 */ uintptr
	var _ /* zDummy at bp+0 */ uintptr
	_, _, _, _, _, _, _ = abPK, bPatchset, i, pNew, pOld, rc, v1
	rc = SQLITE_OK
	Xsqlite3changeset_op(tls, pIter, bp, bp+8, bp+4, uintptr(0))
	if **(**int32)(__ccgo_up(bp + 4)) == int32(SQLITE_DELETE) {
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0 {
			v1 = (*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK
		} else {
			v1 = uintptr(0)
		}
		/* Bind values to the DELETE statement. If conflict handling is required,
		 ** bind values for all columns and set bound variable (nCol+1) to true.
		 ** Or, if conflict handling is not required, bind just the PK column
		 ** values and, if it exists, set (nCol+1) to false. Conflict handling
		 ** is not required if:
		 **
		 **   * this is a patchset, or
		 **   * (pbRetry==0), or
		 **   * all columns of the table are PK columns (in this case there is
		 **     no (nCol+1) variable to bind to).
		 */
		abPK = v1
		rc = _sessionBindRow(tls, pIter, __ccgo_fp(Xsqlite3changeset_old), **(**int32)(__ccgo_up(bp + 8)), abPK, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		if rc == SQLITE_OK && Xsqlite3_bind_parameter_count(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete) > **(**int32)(__ccgo_up(bp + 8)) {
			rc = Xsqlite3_bind_int(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete, **(**int32)(__ccgo_up(bp + 8))+int32(1), libc.BoolInt32(pbRetry == uintptr(0) || abPK != 0))
		}
		if rc != SQLITE_OK {
			return rc
		}
		Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		rc = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpDelete)
		if rc == SQLITE_OK && Xsqlite3_changes(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).Fdb) == 0 {
			rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_DATA), p, pIter, __ccgo_fp_xConflict, pCtx, pbRetry)
		} else {
			if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) {
				rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_CONFLICT), p, pIter, __ccgo_fp_xConflict, pCtx, uintptr(0))
			}
		}
	} else {
		if **(**int32)(__ccgo_up(bp + 4)) == int32(SQLITE_UPDATE) {
			**(**uintptr)(__ccgo_up(bp + 12)) = uintptr(0)
			bPatchset = libc.BoolInt32(pbRetry == uintptr(0) || (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != 0)
			rc = _sessionUpdateFind(tls, pIter, p, bPatchset, bp+12)
			/* Bind values to the UPDATE statement. */
			i = 0
			for {
				if !(rc == SQLITE_OK && i < **(**int32)(__ccgo_up(bp + 8))) {
					break
				}
				pOld = **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr(i)*4))
				pNew = **(**uintptr)(__ccgo_up((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FapValue + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FnCol+i)*4))
				if pOld != 0 && (**(**Tu8)(__ccgo_up((*TSessionApplyCtx)(unsafe.Pointer(p)).FabPK + uintptr(i))) != 0 || bPatchset == 0) {
					rc = _sessionBindValue(tls, **(**uintptr)(__ccgo_up(bp + 12)), i*int32(2)+int32(2), pOld)
				}
				if rc == SQLITE_OK && pNew != 0 {
					rc = _sessionBindValue(tls, **(**uintptr)(__ccgo_up(bp + 12)), i*int32(2)+int32(1), pNew)
				}
				goto _2
			_2:
				;
				i = i + 1
			}
			if rc != SQLITE_OK {
				return rc
			}
			/* Attempt the UPDATE. In the case of a NOTFOUND or DATA conflict,
			 ** the result will be SQLITE_OK with 0 rows modified. */
			Xsqlite3_step(tls, **(**uintptr)(__ccgo_up(bp + 12)))
			rc = Xsqlite3_reset(tls, **(**uintptr)(__ccgo_up(bp + 12)))
			if rc == SQLITE_OK && Xsqlite3_changes(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).Fdb) == 0 {
				/* A NOTFOUND or DATA error. Search the table to see if it contains
				 ** a row with a matching primary key. If so, this is a DATA conflict.
				 ** Otherwise, if there is no primary key match, it is a NOTFOUND. */
				rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_DATA), p, pIter, __ccgo_fp_xConflict, pCtx, pbRetry)
			} else {
				if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) {
					/* This is always a CONSTRAINT conflict. */
					rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_CONFLICT), p, pIter, __ccgo_fp_xConflict, pCtx, uintptr(0))
				}
			}
		} else {
			if (*TSessionApplyCtx)(unsafe.Pointer(p)).FbStat1 != 0 {
				/* Check if there is a conflicting row. For sqlite_stat1, this needs
				 ** to be done using a SELECT, as there is no PRIMARY KEY in the
				 ** database schema to throw an exception if a duplicate is inserted.  */
				rc = _sessionSeekToRow(tls, pIter, p)
				if rc == int32(SQLITE_ROW) {
					rc = int32(SQLITE_CONSTRAINT)
					Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpSelect)
				}
			}
			if rc == SQLITE_OK {
				rc = _sessionBindRow(tls, pIter, __ccgo_fp(Xsqlite3changeset_new), **(**int32)(__ccgo_up(bp + 8)), uintptr(0), (*TSessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
				if rc != SQLITE_OK {
					return rc
				}
				Xsqlite3_step(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
				rc = Xsqlite3_reset(tls, (*TSessionApplyCtx)(unsafe.Pointer(p)).FpInsert)
			}
			if rc&int32(0xff) == int32(SQLITE_CONSTRAINT) {
				rc = _sessionConflictHandler(tls, int32(SQLITE_CHANGESET_CONFLICT), p, pIter, __ccgo_fp_xConflict, pCtx, pbReplace)
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Serialize a changeset (or patchset) based on all changesets (or patchsets)
//	** added to the changegroup object passed as the first argument.
//	**
//	** If xOutput is not NULL, then the changeset/patchset is returned to the
//	** user via one or more calls to xOutput, as with the other streaming
//	** interfaces.
//	**
//	** Or, if xOutput is NULL, then (*ppOut) is populated with a pointer to a
//	** buffer containing the output changeset before this function returns. In
//	** this case (*pnOut) is set to the size of the output buffer in bytes. It
//	** is the responsibility of the caller to free the output buffer using
//	** sqlite3_free() when it is no longer required.
//	**
//	** If successful, SQLITE_OK is returned. Or, if an error occurs, an SQLite
//	** error code. If an error occurs and xOutput is NULL, (*ppOut) and (*pnOut)
//	** are both set to 0 before returning.
//	*/
func _sessionChangegroupOutput(tls *libc.TLS, pGrp uintptr, __ccgo_fp_xOutput uintptr, pOut uintptr, pnOut uintptr, ppOut uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var p, pTab uintptr
	var _ /* buf at bp+4 */ TSessionBuffer
	var _ /* rc at bp+0 */ int32
	_, _, _ = i, p, pTab
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	**(**TSessionBuffer)(__ccgo_up(bp + 4)) = TSessionBuffer{}
	/* Create the serialized output changeset based on the contents of the
	 ** hash tables attached to the SessionTable objects in list p->pList.
	 */
	pTab = (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList
	for {
		if !(**(**int32)(__ccgo_up(bp)) == SQLITE_OK && pTab != 0) {
			break
		}
		if (*TSessionTable)(unsafe.Pointer(pTab)).FnEntry == 0 {
			goto _1
		}
		_sessionAppendTableHdr(tls, bp+4, (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch, pTab, bp)
		i = 0
		for {
			if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange) {
				break
			}
			p = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*4))
			for {
				if !(p != 0) {
					break
				}
				_sessionAppendByte(tls, bp+4, (*TSessionChange)(unsafe.Pointer(p)).Fop, bp)
				_sessionAppendByte(tls, bp+4, (*TSessionChange)(unsafe.Pointer(p)).FbIndirect, bp)
				_sessionAppendBlob(tls, bp+4, (*TSessionChange)(unsafe.Pointer(p)).FaRecord, (*TSessionChange)(unsafe.Pointer(p)).FnRecord, bp)
				if **(**int32)(__ccgo_up(bp)) == SQLITE_OK && __ccgo_fp_xOutput != 0 && (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FnBuf >= _sessions_strm_chunk_size {
					**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FnBuf)
					(**(**TSessionBuffer)(__ccgo_up(bp + 4))).FnBuf = 0
				}
				goto _3
			_3:
				;
				p = (*TSessionChange)(unsafe.Pointer(p)).FpNext
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		goto _1
	_1:
		;
		pTab = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
	}
	if **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
		if __ccgo_fp_xOutput != 0 {
			if (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FnBuf > 0 {
				**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xOutput})))(tls, pOut, (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FaBuf, (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FnBuf)
			}
		} else {
			if ppOut != 0 {
				**(**uintptr)(__ccgo_up(ppOut)) = (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FaBuf
				if pnOut != 0 {
					**(**int32)(__ccgo_up(pnOut)) = (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FnBuf
				}
				(**(**TSessionBuffer)(__ccgo_up(bp + 4))).FaBuf = uintptr(0)
			}
		}
	}
	Xsqlite3_free(tls, (**(**TSessionBuffer)(__ccgo_up(bp + 4))).FaBuf)
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Do the work for either sqlite3changeset_start() or start_strm().
//	*/
func _sessionChangesetStart(tls *libc.TLS, pp uintptr, __ccgo_fp_xInput uintptr, pIn uintptr, nChangeset int32, pChangeset uintptr, bInvert int32, bSkipEmpty int32) (r int32) {
	var nByte, v1 int32
	var pRet uintptr
	_, _, _ = nByte, pRet, v1 /* Number of bytes to allocate for iterator */
	/* Zero the output variable in case an error occurs. */
	**(**uintptr)(__ccgo_up(pp)) = uintptr(0)
	/* Allocate and initialize the iterator structure. */
	nByte = int32(100)
	pRet = Xsqlite3_malloc(tls, nByte)
	if !(pRet != 0) {
		return int32(SQLITE_NOMEM)
	}
	libc.Xmemset(tls, pRet, 0, uint32(100))
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FaData = pChangeset
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FnData = nChangeset
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FxInput = __ccgo_fp_xInput
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FpIn = pIn
	if __ccgo_fp_xInput != 0 {
		v1 = 0
	} else {
		v1 = int32(1)
	}
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).Fin.FbEof = v1
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbInvert = bInvert
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pRet)).FbSkipEmpty = bSkipEmpty
	/* Populate the output variable and return success. */
	**(**uintptr)(__ccgo_up(pp)) = pRet
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Add all changes in the changeset traversed by the iterator passed as
//	** the first argument to the changegroup hash tables.
//	*/
func _sessionChangesetToHash(tls *libc.TLS, pIter uintptr, pGrp uintptr, bRebase int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* aRec at bp+0 */ uintptr
	var _ /* nRec at bp+4 */ int32
	_ = rc
	rc = SQLITE_OK
	(*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FbNoDiscard = int32(1)
	for int32(SQLITE_ROW) == _sessionChangesetNext(tls, pIter, bp, bp+4, uintptr(0)) {
		rc = _sessionOneChangeIterToHash(tls, pGrp, pIter, bRebase)
		if rc != SQLITE_OK {
			break
		}
	}
	if rc == SQLITE_OK {
		rc = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Frc
	}
	return rc
}

// C documentation
//
//	/*
//	** Free the list of table objects passed as the first argument. The contents
//	** of the changed-rows hash tables are also deleted.
//	*/
func _sessionDeleteTable(tls *libc.TLS, pSession uintptr, pList uintptr) {
	var i int32
	var p, pNext, pNextChange, pTab uintptr
	_, _, _, _, _ = i, p, pNext, pNextChange, pTab
	pTab = pList
	for {
		if !(pTab != 0) {
			break
		}
		pNext = (*TSessionTable)(unsafe.Pointer(pTab)).FpNext
		i = 0
		for {
			if !(i < (*TSessionTable)(unsafe.Pointer(pTab)).FnChange) {
				break
			}
			p = **(**uintptr)(__ccgo_up((*TSessionTable)(unsafe.Pointer(pTab)).FapChange + uintptr(i)*4))
			for {
				if !(p != 0) {
					break
				}
				pNextChange = (*TSessionChange)(unsafe.Pointer(p)).FpNext
				_sessionFree(tls, pSession, p)
				goto _3
			_3:
				;
				p = pNextChange
			}
			goto _2
		_2:
			;
			i = i + 1
		}
		Xsqlite3_finalize(tls, (*TSessionTable)(unsafe.Pointer(pTab)).FpDfltStmt)
		_sessionFree(tls, pSession, (*TSessionTable)(unsafe.Pointer(pTab)).FazCol) /* cast works around VC++ bug */
		_sessionFree(tls, pSession, (*TSessionTable)(unsafe.Pointer(pTab)).FapChange)
		_sessionFree(tls, pSession, pTab)
		goto _1
	_1:
		;
		pTab = pNext
	}
}

// C documentation
//
//	/*
//	** Free buffer pFree, which must have been allocated by an earlier
//	** call to sessionMalloc64(). If pSession is not NULL, decrease the
//	** sqlite3_session.nMalloc counter by the number of bytes freed.
//	*/
func _sessionFree(tls *libc.TLS, pSession uintptr, pFree uintptr) {
	var v1 uintptr
	_ = v1
	if pSession != 0 {
		v1 = pSession + 40
		*(*Ti64)(unsafe.Pointer(v1)) = Ti64(uint64(*(*Ti64)(unsafe.Pointer(v1))) - Xsqlite3_msize(tls, pFree))
	}
	Xsqlite3_free(tls, pFree)
}

/*
** This macro is used to calculate hash key values for data structures. In
** order to use this macro, the entire data structure must be represented
** as a series of unsigned integers. In order to calculate a hash-key value
** for a data structure represented as three such integers, the macro may
** then be used as follows:
**
**    int hash_key_value;
**    hash_key_value = HASH_APPEND(0, <value 1>);
**    hash_key_value = HASH_APPEND(hash_key_value, <value 2>);
**    hash_key_value = HASH_APPEND(hash_key_value, <value 3>);
**
** In practice, the data structures this macro is used for are the primary
** key values of modified rows.
 */

// C documentation
//
//	/*
//	** Ensure that there are at least nByte bytes available in the buffer. Or,
//	** if there are not nByte bytes remaining in the input, that all available
//	** data is in the buffer.
//	**
//	** Return an SQLite error code if an error occurs, or SQLITE_OK otherwise.
//	*/
func _sessionInputBuffer(tls *libc.TLS, pIn uintptr, nByte int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* nNew at bp+4 */ int32
	var _ /* rc at bp+0 */ int32
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	if (*TSessionInput)(unsafe.Pointer(pIn)).FxInput != 0 {
		for !((*TSessionInput)(unsafe.Pointer(pIn)).FbEof != 0) && (*TSessionInput)(unsafe.Pointer(pIn)).FiNext+nByte >= (*TSessionInput)(unsafe.Pointer(pIn)).FnData && **(**int32)(__ccgo_up(bp)) == SQLITE_OK {
			**(**int32)(__ccgo_up(bp + 4)) = _sessions_strm_chunk_size
			if (*TSessionInput)(unsafe.Pointer(pIn)).FbNoDiscard == 0 {
				_sessionDiscardData(tls, pIn)
			}
			if SQLITE_OK == _sessionBufferGrow(tls, pIn+20, int64(**(**int32)(__ccgo_up(bp + 4))), bp) {
				**(**int32)(__ccgo_up(bp)) = (*(*func(*libc.TLS, uintptr, uintptr, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSessionInput)(unsafe.Pointer(pIn)).FxInput})))(tls, (*TSessionInput)(unsafe.Pointer(pIn)).FpIn, (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf+uintptr((*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf), bp+4)
				if **(**int32)(__ccgo_up(bp + 4)) == 0 {
					(*TSessionInput)(unsafe.Pointer(pIn)).FbEof = int32(1)
				} else {
					(*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf += **(**int32)(__ccgo_up(bp + 4))
				}
			}
			(*TSessionInput)(unsafe.Pointer(pIn)).FaData = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FaBuf
			(*TSessionInput)(unsafe.Pointer(pIn)).FnData = (*TSessionInput)(unsafe.Pointer(pIn)).Fbuf.FnBuf
		}
	}
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Add the change currently indicated by iterator pIter to the hash table
//	** belonging to changegroup pGrp.
//	*/
func _sessionOneChangeIterToHash(tls *libc.TLS, pGrp uintptr, pIter uintptr, bRebase int32) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var aRec uintptr
	var nRec, rc int32
	var _ /* bIndirect at bp+12 */ int32
	var _ /* nCol at bp+4 */ int32
	var _ /* op at bp+8 */ int32
	var _ /* pTab at bp+16 */ uintptr
	var _ /* zTab at bp+0 */ uintptr
	_, _, _ = aRec, nRec, rc
	aRec = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FaData + uintptr((*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent+int32(2))
	nRec = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiNext - (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Fin.FiCurrent - int32(2)
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	**(**int32)(__ccgo_up(bp + 4)) = 0
	**(**int32)(__ccgo_up(bp + 8)) = 0
	**(**int32)(__ccgo_up(bp + 12)) = 0
	rc = SQLITE_OK
	**(**uintptr)(__ccgo_up(bp + 16)) = uintptr(0)
	/* Ensure that only changesets, or only patchsets, but not a mixture
	 ** of both, are being combined. It is an error to try to combine a
	 ** changeset and a patchset.  */
	if (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FpList == uintptr(0) {
		(*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset
	} else {
		if (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).FbPatchset != (*Tsqlite3_changegroup)(unsafe.Pointer(pGrp)).FbPatch {
			rc = int32(SQLITE_ERROR)
		}
	}
	if rc == SQLITE_OK {
		Xsqlite3changeset_op(tls, pIter, bp, bp+4, bp+8, bp+12)
		rc = _sessionChangesetFindTable(tls, pGrp, **(**uintptr)(__ccgo_up(bp)), pIter, bp+16)
	}
	if rc == SQLITE_OK {
		rc = _sessionOneChangeToHash(tls, pGrp, **(**uintptr)(__ccgo_up(bp + 16)), **(**int32)(__ccgo_up(bp + 8)), **(**int32)(__ccgo_up(bp + 12)), **(**int32)(__ccgo_up(bp + 4)), aRec, nRec, bRebase)
	}
	if rc == SQLITE_OK {
		rc = (*Tsqlite3_changeset_iter)(unsafe.Pointer(pIter)).Frc
	}
	return rc
}

// C documentation
//
//	/*
//	** Set the safety_level and pager flags for pager iDb.  Or if iDb<0
//	** set these values for all pagers.
//	*/
func _setAllPagerFlags(tls *libc.TLS, db uintptr) {
	var n, v1 int32
	var pDb uintptr
	_, _, _ = n, pDb, v1
	if (*Tsqlite3)(unsafe.Pointer(db)).FautoCommit != 0 {
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
		n = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
		for {
			v1 = n
			n = n - 1
			if !(v1 > 0) {
				break
			}
			if (*TDb)(unsafe.Pointer(pDb)).FpBt != 0 {
				_sqlite3BtreeSetPagerFlags(tls, (*TDb)(unsafe.Pointer(pDb)).FpBt, uint32(uint64((*TDb)(unsafe.Pointer(pDb)).Fsafety_level)|(*Tsqlite3)(unsafe.Pointer(db)).Fflags&uint64(PAGER_FLAGS_MASK)))
			}
			pDb += 16
		}
	}
}

// C documentation
//
//	/*
//	** Initialize a Walker object so that will persist AggInfo entries referenced
//	** by the tree that is walked.
//	*/
func _sqlite3AggInfoPersistWalkerInit(tls *libc.TLS, pWalker uintptr, pParse uintptr) {
	libc.Xmemset(tls, pWalker, 0, uint32(28))
	(*TWalker)(unsafe.Pointer(pWalker)).FpParse = pParse
	(*TWalker)(unsafe.Pointer(pWalker)).FxExprCallback = __ccgo_fp(_agginfoPersistExprCb)
	(*TWalker)(unsafe.Pointer(pWalker)).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
}

// C documentation
//
//	/*
//	** Generate VDBE code that prepares for doing an operation that
//	** might change the database.
//	**
//	** This routine starts a new transaction if we are not already within
//	** a transaction.  If we are already within a transaction, then a checkpoint
//	** is set if the setStatement parameter is true.  A checkpoint should
//	** be set for operations that might fail (due to a constraint) part of
//	** the way through and which will need to undo some writes without having to
//	** rollback the whole transaction.  For operations where all constraints
//	** can be checked before any changes are made to the database, it is never
//	** necessary to undo a write and the checkpoint should not be set.
//	*/
func _sqlite3BeginWriteOperation(tls *libc.TLS, pParse uintptr, setStatement int32, iDb int32) {
	var pToplevel, v1 uintptr
	_, _ = pToplevel, v1
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pToplevel = v1
	_sqlite3CodeVerifySchemaAtToplevel(tls, pToplevel, iDb)
	**(**TyDbMask)(__ccgo_up(pToplevel + 84)) |= libc.Uint32FromInt32(1) << iDb
	v1 = pToplevel + 20
	*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | setStatement)
}

// C documentation
//
//	/*
//	** Destroy a bitmap object.  Reclaim all memory used.
//	*/
func _sqlite3BitvecDestroy(tls *libc.TLS, p uintptr) {
	var i uint32
	_ = i
	if p == uintptr(0) {
		return
	}
	if (*TBitvec)(unsafe.Pointer(p)).FiDivisor != 0 {
		i = uint32(0)
		for {
			if !(i < (libc.Uint32FromInt32(BITVEC_SZ)-libc.Uint32FromInt32(3)*libc.Uint32FromInt64(4))/libc.Uint32FromInt64(4)*libc.Uint32FromInt64(4)/libc.Uint32FromInt64(4)) {
				break
			}
			_sqlite3BitvecDestroy(tls, **(**uintptr)(__ccgo_up(p + 12 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Initialize memory that will be converted into a BtCursor object.
//	**
//	** The simple approach here would be to memset() the entire object
//	** to zero.  But it turns out that the apPage[] and aiIdx[] arrays
//	** do not need to be zeroed and they are large, so we can save a lot
//	** of run-time by skipping the initialization of those elements.
//	*/
func _sqlite3BtreeCursorZero(tls *libc.TLS, p uintptr) {
	libc.Xmemset(tls, p, 0, uint32(libc.UintptrFromInt32(0)+20))
}

// C documentation
//
//	/*
//	** Run a checkpoint on database iDb. This is a no-op if database iDb is
//	** not currently open in WAL mode.
//	**
//	** If a transaction is open on the database being checkpointed, this
//	** function returns SQLITE_LOCKED and a checkpoint is not attempted. If
//	** an error occurs while running the checkpoint, an SQLite error code is
//	** returned (i.e. SQLITE_IOERR). Otherwise, SQLITE_OK.
//	**
//	** The mutex on database handle db should be held by the caller. The mutex
//	** associated with the specific b-tree being checkpointed is taken by
//	** this function while the checkpoint is running.
//	**
//	** If iDb is passed SQLITE_MAX_DB then all attached databases are
//	** checkpointed. If an error is encountered it is returned immediately -
//	** no attempt is made to checkpoint any remaining databases.
//	**
//	** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL, RESTART
//	** or TRUNCATE.
//	*/
func _sqlite3Checkpoint(tls *libc.TLS, db uintptr, iDb int32, eMode int32, pnLog uintptr, pnCkpt uintptr) (r int32) {
	var bBusy, i, rc, v2 int32
	_, _, _, _ = bBusy, i, rc, v2
	rc = SQLITE_OK /* Used to iterate through attached dbs */
	bBusy = 0      /* True if SQLITE_BUSY has been encountered */
	/* See forum post a006d86f72 */
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb && rc == SQLITE_OK) {
			break
		}
		if i == iDb || iDb == libc.Int32FromInt32(SQLITE_MAX_ATTACHED)+libc.Int32FromInt32(2) {
			rc = _sqlite3BtreeCheckpoint(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt, eMode, pnLog, pnCkpt)
			pnLog = uintptr(0)
			pnCkpt = uintptr(0)
			if rc == int32(SQLITE_BUSY) {
				bBusy = int32(1)
				rc = SQLITE_OK
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	if rc == SQLITE_OK && bBusy != 0 {
		v2 = int32(SQLITE_BUSY)
	} else {
		v2 = rc
	}
	return v2
}

// C documentation
//
//	/*
//	** Call this routine when the database connection is closing in order
//	** to clean up loaded extensions
//	*/
func _sqlite3CloseExtensions(tls *libc.TLS, db uintptr) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnExtension) {
			break
		}
		_sqlite3OsDlClose(tls, (*Tsqlite3)(unsafe.Pointer(db)).FpVfs, **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaExtension + uintptr(i)*4)))
		goto _1
	_1:
		;
		i = i + 1
	}
	_sqlite3DbFree(tls, db, (*Tsqlite3)(unsafe.Pointer(db)).FaExtension)
}

// C documentation
//
//	/*
//	** If argument zDb is NULL, then call sqlite3CodeVerifySchema() for each
//	** attached database. Otherwise, invoke it for the database named zDb only.
//	*/
func _sqlite3CodeVerifyNamedSchema(tls *libc.TLS, pParse uintptr, zDb uintptr) {
	var db, pDb uintptr
	var i int32
	_, _, _ = db, i, pDb
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16
		if (*TDb)(unsafe.Pointer(pDb)).FpBt != 0 && (!(zDb != 0) || 0 == _sqlite3StrICmp(tls, zDb, (*TDb)(unsafe.Pointer(pDb)).FzDbSName)) {
			_sqlite3CodeVerifySchema(tls, pParse, i)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** Record the fact that the schema cookie will need to be verified
//	** for database iDb.  The code to actually verify the schema cookie
//	** will occur at the end of the top-level VDBE and will be generated
//	** later, by sqlite3FinishCoding().
//	*/
func _sqlite3CodeVerifySchemaAtToplevel(tls *libc.TLS, pToplevel uintptr, iDb int32) {
	if libc.BoolInt32((*TParse)(unsafe.Pointer(pToplevel)).FcookieMask&(libc.Uint32FromInt32(1)<<iDb) != uint32(0)) == 0 {
		**(**TyDbMask)(__ccgo_up(pToplevel + 88)) |= libc.Uint32FromInt32(1) << iDb
		if libc.Bool(!(libc.Int32FromInt32(OMIT_TEMPDB) != 0)) && iDb == int32(1) {
			_sqlite3OpenTempDatabase(tls, pToplevel)
		}
	}
}

// C documentation
//
//	/*
//	** Create a new CTE object
//	*/
func _sqlite3CteNew(tls *libc.TLS, pParse uintptr, pName uintptr, pArglist uintptr, pQuery uintptr, eM10d Tu8) (r uintptr) {
	var db, pNew uintptr
	_, _ = db, pNew
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	pNew = _sqlite3DbMallocZero(tls, db, uint64(24))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3ExprListDelete(tls, db, pArglist)
		_sqlite3SelectDelete(tls, db, pQuery)
	} else {
		(*TCte)(unsafe.Pointer(pNew)).FpSelect = pQuery
		(*TCte)(unsafe.Pointer(pNew)).FpCols = pArglist
		(*TCte)(unsafe.Pointer(pNew)).FzName = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pName)
		(*TCte)(unsafe.Pointer(pNew)).FeM10d = eM10d
	}
	return pNew
}

// C documentation
//
//	/*
//	** Free memory that might be associated with a particular database
//	** connection.  Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
//	** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
//	*/
func _sqlite3DbFreeNN(tls *libc.TLS, db uintptr, p uintptr) {
	var pBuf, pBuf1 uintptr
	_, _ = pBuf, pBuf1
	if db != 0 {
		if uint32(p) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
			if uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
				pBuf = p
				(*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = pBuf
				return
			}
			if uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
				pBuf1 = p
				(*TLookasideSlot)(unsafe.Pointer(pBuf1)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
				(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = pBuf1
				return
			}
		}
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
			_measureAllocationSize(tls, db, p)
			return
		}
	}
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Allocate and zero memory.  If the allocation fails, make
//	** the mallocFailed flag in the connection pointer.
//	*/
func _sqlite3DbMallocZero(tls *libc.TLS, db uintptr, n Tu64) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3DbMallocRaw(tls, db, n)
	if p != 0 {
		libc.Xmemset(tls, p, 0, uint32(n))
	}
	return p
}

func _sqlite3DbNNFreeNN(tls *libc.TLS, db uintptr, p uintptr) {
	var pBuf, pBuf1 uintptr
	_, _ = pBuf, pBuf1
	if uint32(p) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
		if uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
			pBuf = p
			(*TLookasideSlot)(unsafe.Pointer(pBuf)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpSmallFree = pBuf
			return
		}
		if uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
			pBuf1 = p
			(*TLookasideSlot)(unsafe.Pointer(pBuf1)).FpNext = (*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree
			(*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpFree = pBuf1
			return
		}
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed != 0 {
		_measureAllocationSize(tls, db, p)
		return
	}
	Xsqlite3_free(tls, p)
}

// C documentation
//
//	/*
//	** Return the Btree pointer identified by zDbName.  Return NULL if not found.
//	*/
func _sqlite3DbNameToBtree(tls *libc.TLS, db uintptr, zDbName uintptr) (r uintptr) {
	var iDb, v1 int32
	var v2 uintptr
	_, _, _ = iDb, v1, v2
	if zDbName != 0 {
		v1 = _sqlite3FindDbName(tls, db, zDbName)
	} else {
		v1 = 0
	}
	iDb = v1
	if iDb < 0 {
		v2 = uintptr(0)
	} else {
		v2 = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpBt
	}
	return v2
}

// C documentation
//
//	/*
//	** Resize the block of memory pointed to by p to n bytes. If the
//	** resize fails, set the mallocFailed flag in the connection object.
//	*/
func _sqlite3DbRealloc(tls *libc.TLS, db uintptr, p uintptr, n Tu64) (r uintptr) {
	if p == uintptr(0) {
		return _sqlite3DbMallocRawNN(tls, db, n)
	}
	if uint32(p) < uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpEnd) {
		if uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpMiddle) {
			if n <= uint64(LOOKASIDE_SMALL) {
				return p
			}
		} else {
			if uint32(p) >= uint32((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FpStart) {
				if n <= uint64((*Tsqlite3)(unsafe.Pointer(db)).Flookaside.FszTrue) {
					return p
				}
			}
		}
	}
	return _dbReallocFinish(tls, db, p, n)
}

// C documentation
//
//	/*
//	** Make a copy of a string in memory obtained from sqliteMalloc(). These
//	** functions call sqlite3MallocRaw() directly instead of sqliteMalloc(). This
//	** is because when memory debugging is turned on, these two functions are
//	** called via macros that record the current file and line number in the
//	** ThreadData structure.
//	*/
func _sqlite3DbStrDup(tls *libc.TLS, db uintptr, z uintptr) (r uintptr) {
	var n Tsize_t
	var zNew uintptr
	_, _ = n, zNew
	if z == uintptr(0) {
		return uintptr(0)
	}
	n = libc.Xstrlen(tls, z) + uint32(1)
	zNew = _sqlite3DbMallocRaw(tls, db, uint64(n))
	if zNew != 0 {
		libc.Xmemcpy(tls, zNew, z, n)
	}
	return zNew
}

// C documentation
//
//	/*
//	** If the Index.aSample variable is not NULL, delete the aSample[] array
//	** and its contents.
//	*/
func _sqlite3DeleteIndexSamples(tls *libc.TLS, db uintptr, pIdx uintptr) {
	var j int32
	var p uintptr
	_, _ = j, p
	if (*TIndex)(unsafe.Pointer(pIdx)).FaSample != 0 {
		j = 0
		for {
			if !(j < (*TIndex)(unsafe.Pointer(pIdx)).FnSample) {
				break
			}
			p = (*TIndex)(unsafe.Pointer(pIdx)).FaSample + uintptr(j)*20
			_sqlite3DbFree(tls, db, (*TIndexSample)(unsafe.Pointer(p)).Fp)
			goto _1
		_1:
			;
			j = j + 1
		}
		_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer(pIdx)).FaSample)
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		(*TIndex)(unsafe.Pointer(pIdx)).FnSample = 0
		(*TIndex)(unsafe.Pointer(pIdx)).FaSample = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Clean up the data structures associated with the RETURNING clause.
//	*/
func _sqlite3DeleteReturning(tls *libc.TLS, db uintptr, pArg uintptr) {
	var pHash, pRet uintptr
	_, _ = pHash, pRet
	pRet = pArg
	pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema + 40
	_sqlite3HashInsert(tls, pHash, pRet+100, uintptr(0))
	_sqlite3ExprListDelete(tls, db, (*TReturning)(unsafe.Pointer(pRet)).FpReturnEL)
	_sqlite3DbFree(tls, db, pRet)
}

func _sqlite3DeleteTable(tls *libc.TLS, db uintptr, pTable uintptr) {
	var v1 Tu32
	var v2 uintptr
	var v3 bool
	_, _, _ = v1, v2, v3
	/* Do not delete the table until the reference count reaches zero. */
	if !(pTable != 0) {
		return
	}
	if v3 = (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0); v3 {
		v2 = pTable + 24
		*(*Tu32)(unsafe.Pointer(v2)) = *(*Tu32)(unsafe.Pointer(v2)) - 1
		v1 = *(*Tu32)(unsafe.Pointer(v2))
	}
	if v3 && v1 > uint32(0) {
		return
	}
	_deleteTable(tls, db, pTable)
}

// C documentation
//
//	/*
//	** Call sqlite3ExprAnalyzeAggregates() for every expression in an
//	** expression list.  Return the number of errors.
//	**
//	** If an error is found, the analysis is cut short.
//	*/
func _sqlite3ExprAnalyzeAggList(tls *libc.TLS, pNC uintptr, pList uintptr) {
	var i int32
	var pItem uintptr
	_, _ = i, pItem
	if pList != 0 {
		pItem = pList + 8
		i = libc.Int32FromInt32(0)
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			_sqlite3ExprAnalyzeAggregates(tls, pNC, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			goto _1
		_1:
			;
			i = i + 1
			pItem += 20
		}
	}
}

// C documentation
//
//	/*
//	** Analyze the pExpr expression looking for aggregate functions and
//	** for variables that need to be added to AggInfo object that pNC->pAggInfo
//	** points to.  Additional entries are made on the AggInfo object as
//	** necessary.
//	**
//	** This routine should only be called after the expression has been
//	** analyzed by sqlite3ResolveExprNames().
//	*/
func _sqlite3ExprAnalyzeAggregates(tls *libc.TLS, pNC uintptr, pExpr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_analyzeAggregate)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3WalkerDepthIncrease)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = __ccgo_fp(_sqlite3WalkerDepthDecrease)
	(**(**TWalker)(__ccgo_up(bp))).FwalkerDepth = 0
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pNC
	(**(**TWalker)(__ccgo_up(bp))).FpParse = uintptr(0)
	_sqlite3WalkExpr(tls, bp, pExpr)
}

// C documentation
//
//	/*
//	** Expr pIn is an IN(...) expression. This function checks that the
//	** sub-select on the RHS of the IN() operator has the same number of
//	** columns as the vector on the LHS. Or, if the RHS of the IN() is not
//	** a sub-query, that the LHS is a vector of size 1.
//	*/
func _sqlite3ExprCheckIN(tls *libc.TLS, pParse uintptr, pIn uintptr) (r int32) {
	var nVector int32
	_ = nVector
	nVector = _sqlite3ExprVectorSize(tls, (*TExpr)(unsafe.Pointer(pIn)).FpLeft)
	if (*TExpr)(unsafe.Pointer(pIn)).Fflags&uint32(EP_xIsSelect) != uint32(0) && !((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FmallocFailed != 0) {
		if nVector != (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIn + 20)))).FpEList)).FnExpr {
			_sqlite3SubselectError(tls, pParse, (*TExprList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pIn + 20)))).FpEList)).FnExpr, nVector)
			return int32(1)
		}
	} else {
		if nVector != int32(1) {
			_sqlite3VectorErrorMsg(tls, pParse, (*TExpr)(unsafe.Pointer(pIn)).FpLeft)
			return int32(1)
		}
	}
	return 0
}

// C documentation
//
//	/*
//	** Generate code that will evaluate expression pExpr and store the
//	** results in register target.  The results are guaranteed to appear
//	** in register target.  If the expression is constant, then this routine
//	** might choose to code the expression at initialization time.
//	*/
func _sqlite3ExprCodeFactorable(tls *libc.TLS, pParse uintptr, pExpr uintptr, target int32) {
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 28))&0x80>>7)) != 0 && _sqlite3ExprIsConstantNotJoin(tls, pParse, pExpr) != 0 {
		_sqlite3ExprCodeRunJustOnce(tls, pParse, pExpr, target)
	} else {
		_sqlite3ExprCodeCopy(tls, pParse, pExpr, target)
	}
}

// C documentation
//
//	/* Generate code that will load into register regOut a value that is
//	** appropriate for the iIdxCol-th column of index pIdx.
//	*/
func _sqlite3ExprCodeLoadIndexColumn(tls *libc.TLS, pParse uintptr, pIdx uintptr, iTabCur int32, iIdxCol int32, regOut int32) {
	var iTabCol Ti16
	_ = iTabCol
	iTabCol = **(**Ti16)(__ccgo_up((*TIndex)(unsafe.Pointer(pIdx)).FaiColumn + uintptr(iIdxCol)*2))
	if int32(iTabCol) == -int32(2) {
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = iTabCur + int32(1)
		_sqlite3ExprCodeCopy(tls, pParse, (*(*TExprList_item)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIdx)).FaColExpr + 8 + uintptr(iIdxCol)*20))).FpExpr, regOut)
		(*TParse)(unsafe.Pointer(pParse)).FiSelfTab = 0
	} else {
		_sqlite3ExprCodeGetColumnOfTable(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TIndex)(unsafe.Pointer(pIdx)).FpTable, iTabCur, int32(iTabCol), regOut)
	}
}

// C documentation
//
//	/*
//	** Determine if an index pIdx on table with cursor iCur contains will
//	** the expression pExpr.  Return true if the index does cover the
//	** expression and false if the pExpr expression references table columns
//	** that are not found in the index pIdx.
//	**
//	** An index covering an expression means that the expression can be
//	** evaluated using only the index and without having to lookup the
//	** corresponding table entry.
//	*/
func _sqlite3ExprCoveredByIndex(tls *libc.TLS, pExpr uintptr, iCur int32, pIdx uintptr) (r int32) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* w at bp+0 */ TWalker
	var _ /* xcov at bp+32 */ TIdxCover
	libc.Xmemset(tls, bp, 0, uint32(28))
	(**(**TIdxCover)(__ccgo_up(bp + 32))).FiCur = iCur
	(**(**TIdxCover)(__ccgo_up(bp + 32))).FpIdx = pIdx
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_exprIdxCover)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = bp + 32
	_sqlite3WalkExpr(tls, bp, pExpr)
	return libc.BoolInt32(!((**(**TWalker)(__ccgo_up(bp))).FeCode != 0))
}

func _sqlite3ExprListAppend(tls *libc.TLS, pParse uintptr, pList uintptr, pExpr uintptr) (r uintptr) {
	var pItem, v2 uintptr
	var v1 int32
	_, _, _ = pItem, v1, v2
	if pList == uintptr(0) {
		return _sqlite3ExprListAppendNew(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pExpr)
	}
	if (*TExprList)(unsafe.Pointer(pList)).FnAlloc < (*TExprList)(unsafe.Pointer(pList)).FnExpr+int32(1) {
		return _sqlite3ExprListAppendGrow(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList, pExpr)
	}
	v2 = pList
	v1 = *(*int32)(unsafe.Pointer(v2))
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	pItem = pList + 8 + uintptr(v1)*20
	**(**TExprList_item)(__ccgo_up(pItem)) = _zeroItem
	(*TExprList_item)(unsafe.Pointer(pItem)).FpExpr = pExpr
	return pList
}

// C documentation
//
//	/*
//	** Return the bitwise-OR of all Expr.flags fields in the given
//	** ExprList.
//	*/
func _sqlite3ExprListFlags(tls *libc.TLS, pList uintptr) (r Tu32) {
	var i int32
	var m Tu32
	var pExpr uintptr
	_, _, _ = i, m, pExpr
	m = uint32(0)
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		pExpr = (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr
		m = m | (*TExpr)(unsafe.Pointer(pExpr)).Fflags
		goto _1
	_1:
		;
		i = i + 1
	}
	return m
}

// C documentation
//
//	/*
//	** Set the ExprList.a[].zSpan element of the most recently added item
//	** on the expression list.
//	**
//	** pList might be NULL following an OOM error.  But pSpan should never be
//	** NULL.  If a memory allocation fails, the pParse->db->mallocFailed flag
//	** is set.
//	*/
func _sqlite3ExprListSetSpan(tls *libc.TLS, pParse uintptr, pList uintptr, zStart uintptr, zEnd uintptr) {
	var db, pItem uintptr
	_, _ = db, pItem
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if pList != 0 {
		pItem = pList + 8 + uintptr((*TExprList)(unsafe.Pointer(pList)).FnExpr-int32(1))*20
		if (*TExprList_item)(unsafe.Pointer(pItem)).FzEName == uintptr(0) {
			(*TExprList_item)(unsafe.Pointer(pItem)).FzEName = _sqlite3DbSpanDup(tls, db, zStart, zEnd)
			libc.SetBitFieldPtr16Uint32(pItem+8+4, libc.Uint32FromInt32(ENAME_SPAN), 0, 0x3)
		}
	}
}

// C documentation
//
//	/*
//	** Locate the in-memory structure that describes
//	** a particular index given the name of that index
//	** and the name of the database that contains the index.
//	** Return NULL if not found.
//	**
//	** If zDatabase is 0, all databases are searched for the
//	** table and the first matching index is returned.  (No checking
//	** for duplicate index names is done.)  The search order is
//	** TEMP first, then MAIN, then any auxiliary databases added
//	** using the ATTACH command.
//	*/
func _sqlite3FindIndex(tls *libc.TLS, db uintptr, zName uintptr, zDb uintptr) (r uintptr) {
	var i, j, v2 int32
	var p, pSchema uintptr
	_, _, _, _, _ = i, j, p, pSchema, v2
	p = uintptr(0)
	/* All mutexes are required for schema access.  Make sure we hold them. */
	i = OMIT_TEMPDB
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		if i < int32(2) {
			v2 = i ^ int32(1)
		} else {
			v2 = i
		}
		j = v2 /* Search TEMP before MAIN */
		pSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(j)*16))).FpSchema
		if zDb != 0 && _sqlite3DbIsNamed(tls, db, j, zDb) == 0 {
			goto _1
		}
		p = _sqlite3HashFind(tls, pSchema+24, zName)
		if p != 0 {
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return p
}

// C documentation
//
//	/*
//	** Return the latest reusable register in the set of all registers.
//	** The value returned is no less than iMin.  If any register iMin or
//	** greater is in permanent use, then return one more than that last
//	** permanent register.
//	*/
func _sqlite3FirstAvailableRegister(tls *libc.TLS, pParse uintptr, iMin int32) (r int32) {
	var i int32
	var pList uintptr
	_, _ = i, pList
	pList = (*TParse)(unsafe.Pointer(pParse)).FpConstExpr
	if pList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			if *(*int32)(unsafe.Pointer(pList + 8 + uintptr(i)*20 + 16)) >= iMin {
				iMin = *(*int32)(unsafe.Pointer(pList + 8 + uintptr(i)*20 + 16)) + int32(1)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	(*TParse)(unsafe.Pointer(pParse)).FnTempReg = uint8(0)
	(*TParse)(unsafe.Pointer(pParse)).FnRangeReg = 0
	return iMin
}

/*
** Validate that no temporary register falls within the range of
** iFirst..iLast, inclusive.  This routine is only call from within assert()
** statements.
 */

/************** End of expr.c ************************************************/
/************** Begin file alter.c *******************************************/
/*
** 2005 February 15
**
** 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.
**
*************************************************************************
** This file contains C code routines that used to generate VDBE code
** that implements the ALTER TABLE command.
 */
/* #include "sqliteInt.h" */

/*
** The code in this file only exists if we are not omitting the
** ALTER TABLE logic from the build.
 */

func _sqlite3FixExpr(tls *libc.TLS, pFix uintptr, pExpr uintptr) (r int32) {
	return _sqlite3WalkExpr(tls, pFix+4, pExpr)
}

// C documentation
//
//	/*
//	** Initialize a DbFixer structure.  This routine must be called prior
//	** to passing the structure to one of the sqliteFixAAAA() routines below.
//	*/
func _sqlite3FixInit(tls *libc.TLS, pFix uintptr, pParse uintptr, iDb int32, zType uintptr, pName uintptr) {
	var db uintptr
	_ = db
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	(*TDbFixer)(unsafe.Pointer(pFix)).FpParse = pParse
	(*TDbFixer)(unsafe.Pointer(pFix)).FzDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName
	(*TDbFixer)(unsafe.Pointer(pFix)).FpSchema = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema
	(*TDbFixer)(unsafe.Pointer(pFix)).FzType = zType
	(*TDbFixer)(unsafe.Pointer(pFix)).FpName = pName
	(*TDbFixer)(unsafe.Pointer(pFix)).FbTemp = libc.BoolUint8(iDb == libc.Int32FromInt32(1))
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FpParse = pParse
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FxExprCallback = __ccgo_fp(_fixExprCb)
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FxSelectCallback = __ccgo_fp(_fixSelectCb)
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FxSelectCallback2 = __ccgo_fp(_sqlite3WalkWinDefnDummyCallback)
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FwalkerDepth = 0
	(*TDbFixer)(unsafe.Pointer(pFix)).Fw.FeCode = uint16(0)
	*(*uintptr)(unsafe.Pointer(pFix + 4 + 24)) = pFix
}

func _sqlite3FixSelect(tls *libc.TLS, pFix uintptr, pSelect uintptr) (r int32) {
	return _sqlite3WalkSelect(tls, pFix+4, pSelect)
}

// C documentation
//
//	/*
//	** The following set of routines walk through the parse tree and assign
//	** a specific database to all table references where the database name
//	** was left unspecified in the original SQL statement.  The pFix structure
//	** must have been initialized by a prior call to sqlite3FixInit().
//	**
//	** These routines are used to make sure that an index, trigger, or
//	** view in one database does not refer to objects in a different database.
//	** (Exception: indices, triggers, and views in the TEMP database are
//	** allowed to refer to anything.)  If a reference is explicitly made
//	** to an object in a different database, an error message is added to
//	** pParse->zErrMsg and these routines return non-zero.  If everything
//	** checks out, these routines return 0.
//	*/
func _sqlite3FixSrcList(tls *libc.TLS, pFix uintptr, pList uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var res int32
	var _ /* s at bp+0 */ TSelect
	_ = res
	res = 0
	if pList != 0 {
		libc.Xmemset(tls, bp, 0, uint32(68))
		(**(**TSelect)(__ccgo_up(bp))).FpSrc = pList
		res = _sqlite3WalkSelect(tls, pFix+4, bp)
	}
	return res
}

func _sqlite3FixTriggerStep(tls *libc.TLS, pFix uintptr, pStep uintptr) (r int32) {
	var pUp uintptr
	_ = pUp
	for pStep != 0 {
		if _sqlite3WalkSelect(tls, pFix+4, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSelect) != 0 || _sqlite3WalkExpr(tls, pFix+4, (*TTriggerStep)(unsafe.Pointer(pStep)).FpWhere) != 0 || _sqlite3WalkExprList(tls, pFix+4, (*TTriggerStep)(unsafe.Pointer(pStep)).FpExprList) != 0 || _sqlite3FixSrcList(tls, pFix, (*TTriggerStep)(unsafe.Pointer(pStep)).FpSrc) != 0 {
			return int32(1)
		}
		pUp = (*TTriggerStep)(unsafe.Pointer(pStep)).FpUpsert
		for {
			if !(pUp != 0) {
				break
			}
			if _sqlite3WalkExprList(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertTarget) != 0 || _sqlite3WalkExpr(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertTargetWhere) != 0 || _sqlite3WalkExprList(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertSet) != 0 || _sqlite3WalkExpr(tls, pFix+4, (*TUpsert)(unsafe.Pointer(pUp)).FpUpsertWhere) != 0 {
				return int32(1)
			}
			goto _1
		_1:
			;
			pUp = (*TUpsert)(unsafe.Pointer(pUp)).FpNextUpsert
		}
		pStep = (*TTriggerStep)(unsafe.Pointer(pStep)).FpNext
	}
	return 0
}

// C documentation
//
//	/*
//	** Free all memory associated with foreign key definitions attached to
//	** table pTab. Remove the deleted foreign keys from the Schema.fkeyHash
//	** hash table.
//	*/
func _sqlite3FkDelete(tls *libc.TLS, db uintptr, pTab uintptr) {
	var pFKey, pNext, z, v2 uintptr
	_, _, _, _ = pFKey, pNext, z, v2 /* Copy of pFKey->pNextFrom */
	pFKey = (*(*struct {
		FaddColOffset int32
		FpFKey        uintptr
		FpDfltList    uintptr
	})(unsafe.Pointer(pTab + 44))).FpFKey
	for {
		if !(pFKey != 0) {
			break
		}
		/* Remove the FK from the fkeyHash hash table. */
		if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
			if (*TFKey)(unsafe.Pointer(pFKey)).FpPrevTo != 0 {
				(*TFKey)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpPrevTo)).FpNextTo = (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo
			} else {
				if (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo != 0 {
					v2 = (*TFKey)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpNextTo)).FzTo
				} else {
					v2 = (*TFKey)(unsafe.Pointer(pFKey)).FzTo
				}
				z = v2
				_sqlite3HashInsert(tls, (*TTable)(unsafe.Pointer(pTab)).FpSchema+56, z, (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo)
			}
			if (*TFKey)(unsafe.Pointer(pFKey)).FpNextTo != 0 {
				(*TFKey)(unsafe.Pointer((*TFKey)(unsafe.Pointer(pFKey)).FpNextTo)).FpPrevTo = (*TFKey)(unsafe.Pointer(pFKey)).FpPrevTo
			}
		}
		/* EV: R-30323-21917 Each foreign key constraint in SQLite is
		 ** classified as either immediate or deferred.
		 */
		/* Delete any triggers created to implement actions for this FK. */
		_fkTriggerDelete(tls, db, **(**uintptr)(__ccgo_up(pFKey + 28)))
		_fkTriggerDelete(tls, db, **(**uintptr)(__ccgo_up(pFKey + 28 + 1*4)))
		pNext = (*TFKey)(unsafe.Pointer(pFKey)).FpNextFrom
		_sqlite3DbFree(tls, db, pFKey)
		goto _1
	_1:
		;
		pFKey = pNext
	}
}

/************** End of fkey.c ************************************************/
/************** Begin file insert.c ******************************************/
/*
** 2001 September 15
**
** 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.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
 */
/* #include "sqliteInt.h" */

// C documentation
//
//	/*
//	** This function returns a linked list of FKey objects (connected by
//	** FKey.pNextTo) holding all children of table pTab.  For example,
//	** given the following schema:
//	**
//	**   CREATE TABLE t1(a PRIMARY KEY);
//	**   CREATE TABLE t2(b REFERENCES t1(a);
//	**
//	** Calling this function with table "t1" as an argument returns a pointer
//	** to the FKey structure representing the foreign key constraint on table
//	** "t2". Calling this function with "t2" as the argument would return a
//	** NULL pointer (as there are no FK constraints for which t2 is the parent
//	** table).
//	*/
func _sqlite3FkReferences(tls *libc.TLS, pTab uintptr) (r uintptr) {
	return _sqlite3HashFind(tls, (*TTable)(unsafe.Pointer(pTab)).FpSchema+56, (*TTable)(unsafe.Pointer(pTab)).FzName)
}

// C documentation
//
//	/*
//	** Insert a single OP_JournalMode query opcode in order to force the
//	** prepared statement to return false for sqlite3_stmt_readonly().  This
//	** is used by CREATE TABLE IF NOT EXISTS and similar if the table already
//	** exists, so that the prepared statement for CREATE TABLE IF NOT EXISTS
//	** will return false for sqlite3_stmt_readonly() even if that statement
//	** is a read-only no-op.
//	*/
func _sqlite3ForceNotReadOnly(tls *libc.TLS, pParse uintptr) {
	var iReg, v1 int32
	var v, v2 uintptr
	_, _, _, _ = iReg, v, v1, v2
	v2 = pParse + 48
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
	v1 = *(*int32)(unsafe.Pointer(v2))
	iReg = v1
	v = _sqlite3GetVdbe(tls, pParse)
	if v != 0 {
		_sqlite3VdbeAddOp3(tls, v, int32(OP_JournalMode), 0, iReg, -int32(1))
		_sqlite3VdbeUsesBtree(tls, v, 0)
	}
}

// C documentation
//
//	/*
//	** Reclaim the memory used by an index
//	*/
func _sqlite3FreeIndex(tls *libc.TLS, db uintptr, p uintptr) {
	_sqlite3DeleteIndexSamples(tls, db, p)
	_sqlite3ExprDelete(tls, db, (*TIndex)(unsafe.Pointer(p)).FpPartIdxWhere)
	_sqlite3ExprListDelete(tls, db, (*TIndex)(unsafe.Pointer(p)).FaColExpr)
	_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer(p)).FzColAff)
	if int32(uint32(*(*uint16)(unsafe.Pointer(p + 56))&0x10>>4)) != 0 {
		_sqlite3DbFree(tls, db, (*TIndex)(unsafe.Pointer(p)).FazColl)
	}
	Xsqlite3_free(tls, (*TIndex)(unsafe.Pointer(p)).FaiRowEst)
	_sqlite3DbFree(tls, db, p)
}

// C documentation
//
//	/*
//	** Free any buffer allocated by pBuf. Zero the structure before returning.
//	*/
func _sqlite3Fts5BufferFree(tls *libc.TLS, pBuf uintptr) {
	Xsqlite3_free(tls, (*TFts5Buffer)(unsafe.Pointer(pBuf)).Fp)
	libc.Xmemset(tls, pBuf, 0, uint32(12))
}

// C documentation
//
//	/*
//	** Free the configuration object passed as the only argument.
//	*/
func _sqlite3Fts5ConfigFree(tls *libc.TLS, pConfig uintptr) {
	var i int32
	_ = i
	if pConfig != 0 {
		if (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpTok != 0 {
			if (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi1 != 0 {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_tokenizer)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi1)).FxDelete})))(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpTok)
			} else {
				(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*Tfts5_tokenizer_v2)(unsafe.Pointer((*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpApi2)).FxDelete})))(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FpTok)
			}
		}
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).Ft.FazArg)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzDb)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzName)
		i = 0
		for {
			if !(i < (*TFts5Config)(unsafe.Pointer(pConfig)).FnCol) {
				break
			}
			Xsqlite3_free(tls, **(**uintptr)(__ccgo_up((*TFts5Config)(unsafe.Pointer(pConfig)).FazCol + uintptr(i)*4)))
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FazCol)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FaPrefix)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRank)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzRankArgs)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzContent)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzContentRowid)
		Xsqlite3_free(tls, (*TFts5Config)(unsafe.Pointer(pConfig)).FzContentExprlist)
		Xsqlite3_free(tls, pConfig)
	}
}

// C documentation
//
//	/*
//	** Clear the token mappings for all Fts5IndexIter objects managed by
//	** the expression passed as the only argument.
//	*/
func _sqlite3Fts5ExprClearTokens(tls *libc.TLS, pExpr uintptr) {
	var ii int32
	var pT uintptr
	_, _ = ii, pT
	ii = 0
	for {
		if !(ii < (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase) {
			break
		}
		pT = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(ii)*4)) + 20
		for {
			if !(pT != 0) {
				break
			}
			_sqlite3Fts5IndexIterClearTokendata(tls, (*TFts5ExprTerm)(unsafe.Pointer(pT)).FpIter)
			goto _2
		_2:
			;
			pT = (*TFts5ExprTerm)(unsafe.Pointer(pT)).FpSynonym
		}
		goto _1
	_1:
		;
		ii = ii + 1
	}
}

/*
** 2014 August 11
**
** 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.
**
******************************************************************************
**
 */

/* #include "fts5Int.h" */

// C documentation
//
//	/*
//	** Does the work of the fts5_api.xInstToken() API method.
//	*/
func _sqlite3Fts5ExprInstToken(tls *libc.TLS, pExpr uintptr, iRowid Ti64, iPhrase int32, iCol int32, iOff int32, iToken int32, ppOut uintptr, pnOut uintptr) (r int32) {
	var pPhrase, pTerm uintptr
	var rc int32
	_, _, _ = pPhrase, pTerm, rc
	pPhrase = uintptr(0)
	pTerm = uintptr(0)
	rc = SQLITE_OK
	if iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		return int32(SQLITE_RANGE)
	}
	pPhrase = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	if iToken < 0 || iToken >= (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm {
		return int32(SQLITE_RANGE)
	}
	pTerm = pPhrase + 20 + uintptr(iToken)*24
	if (*TFts5Config)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpConfig)).FbTokendata != 0 || (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FbPrefix != 0 {
		rc = _sqlite3Fts5IterToken(tls, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpIter, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm, (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnQueryTerm, iRowid, iCol, iOff+iToken, ppOut, pnOut)
	} else {
		**(**uintptr)(__ccgo_up(ppOut)) = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpTerm
		**(**int32)(__ccgo_up(pnOut)) = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FnFullTerm
	}
	return rc
}

// C documentation
//
//	/*
//	** This function is only called for detail=columns tables.
//	*/
func _sqlite3Fts5ExprPhraseCollist(tls *libc.TLS, pExpr uintptr, iPhrase int32, ppCollist uintptr, pnCollist uintptr) (r int32) {
	var pBuf, pNode, pPhrase, pTerm uintptr
	var rc int32
	_, _, _, _, _ = pBuf, pNode, pPhrase, pTerm, rc
	pPhrase = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	pNode = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FpNode
	rc = SQLITE_OK
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 && (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid == (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid && (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn > 0 {
		pTerm = pPhrase + 20
		if (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym != 0 {
			pBuf = (*TFts5ExprTerm)(unsafe.Pointer(pTerm)).FpSynonym + 1*24
			rc = _fts5ExprSynonymList(tls, pTerm, (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid, pBuf, ppCollist, pnCollist)
		} else {
			**(**uintptr)(__ccgo_up(ppCollist)) = (*TFts5IndexIter)(unsafe.Pointer((*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FpIter)).FpData
			**(**int32)(__ccgo_up(pnCollist)) = (*TFts5IndexIter)(unsafe.Pointer((*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FpIter)).FnData
		}
	} else {
		**(**uintptr)(__ccgo_up(ppCollist)) = uintptr(0)
		**(**int32)(__ccgo_up(pnCollist)) = 0
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the number of terms in the iPhrase'th phrase in pExpr.
//	*/
func _sqlite3Fts5ExprPhraseSize(tls *libc.TLS, pExpr uintptr, iPhrase int32) (r int32) {
	if iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		return 0
	}
	return (*TFts5ExprPhrase)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4)))).FnTerm
}

func _sqlite3Fts5ExprPopulatePoslists(tls *libc.TLS, pConfig uintptr, pExpr uintptr, aPopulator uintptr, iCol int32, z uintptr, n int32) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var i int32
	var pColset, pNode uintptr
	var _ /* sCtx at bp+0 */ TFts5ExprCtx
	_, _, _ = i, pColset, pNode
	(**(**TFts5ExprCtx)(__ccgo_up(bp))).FpExpr = pExpr
	(**(**TFts5ExprCtx)(__ccgo_up(bp))).FaPopulator = aPopulator
	(**(**TFts5ExprCtx)(__ccgo_up(bp))).FiOff = int64(iCol)<<libc.Int32FromInt32(32) - int64(1)
	i = 0
	for {
		if !(i < (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase) {
			break
		}
		pNode = (*TFts5ExprPhrase)(unsafe.Pointer(**(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(i)*4)))).FpNode
		pColset = (*TFts5ExprNearset)(unsafe.Pointer((*TFts5ExprNode)(unsafe.Pointer(pNode)).FpNear)).FpColset
		if pColset != 0 && 0 == _fts5ExprColsetTest(tls, pColset, iCol) || (**(**TFts5PoslistPopulator)(__ccgo_up(aPopulator + uintptr(i)*16))).FbMiss != 0 {
			(**(**TFts5PoslistPopulator)(__ccgo_up(aPopulator + uintptr(i)*16))).FbOk = 0
		} else {
			(**(**TFts5PoslistPopulator)(__ccgo_up(aPopulator + uintptr(i)*16))).FbOk = int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return _sqlite3Fts5Tokenize(tls, pConfig, int32(FTS5_TOKENIZE_DOCUMENT), z, n, bp, __ccgo_fp(_fts5ExprPopulatePoslistsCb))
}

// C documentation
//
//	/*
//	** This function is used to access the current position list for phrase
//	** iPhrase.
//	*/
func _sqlite3Fts5ExprPoslist(tls *libc.TLS, pExpr uintptr, iPhrase int32, pa uintptr) (r int32) {
	var nRet int32
	var pNode, pPhrase uintptr
	_, _, _ = nRet, pNode, pPhrase
	pPhrase = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	pNode = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FpNode
	if (*TFts5ExprNode)(unsafe.Pointer(pNode)).FbEof == 0 && (*TFts5ExprNode)(unsafe.Pointer(pNode)).FiRowid == (*TFts5ExprNode)(unsafe.Pointer((*TFts5Expr)(unsafe.Pointer(pExpr)).FpRoot)).FiRowid {
		**(**uintptr)(__ccgo_up(pa)) = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fp
		nRet = (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).Fposlist.Fn
	} else {
		**(**uintptr)(__ccgo_up(pa)) = uintptr(0)
		nRet = 0
	}
	return nRet
}

// C documentation
//
//	/*
//	** Does the work of the fts5_api.xQueryToken() API method.
//	*/
func _sqlite3Fts5ExprQueryToken(tls *libc.TLS, pExpr uintptr, iPhrase int32, iToken int32, ppOut uintptr, pnOut uintptr) (r int32) {
	var pPhrase uintptr
	_ = pPhrase
	pPhrase = uintptr(0)
	if iPhrase < 0 || iPhrase >= (*TFts5Expr)(unsafe.Pointer(pExpr)).FnPhrase {
		return int32(SQLITE_RANGE)
	}
	pPhrase = **(**uintptr)(__ccgo_up((*TFts5Expr)(unsafe.Pointer(pExpr)).FapExprPhrase + uintptr(iPhrase)*4))
	if iToken < 0 || iToken >= (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm {
		return int32(SQLITE_RANGE)
	}
	**(**uintptr)(__ccgo_up(ppOut)) = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr(iToken)*24))).FpTerm
	**(**int32)(__ccgo_up(pnOut)) = (*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20 + uintptr(iToken)*24))).FnFullTerm
	return SQLITE_OK
}

func _sqlite3Fts5HashScanInit(tls *libc.TLS, p uintptr, pTerm uintptr, nTerm int32) (r int32) {
	return _fts5HashEntrySort(tls, p, pTerm, nTerm, p+16)
}

// C documentation
//
//	/*
//	** Indicate that all subsequent calls to sqlite3Fts5IndexWrite() pertain
//	** to the document with rowid iRowid.
//	*/
func _sqlite3Fts5IndexBeginWrite(tls *libc.TLS, p uintptr, bDelete int32, iRowid Ti64) (r int32) {
	/* Allocate the hash table if it has not already been allocated */
	if (*TFts5Index)(unsafe.Pointer(p)).FpHash == uintptr(0) {
		(*TFts5Index)(unsafe.Pointer(p)).Frc = _sqlite3Fts5HashNew(tls, (*TFts5Index)(unsafe.Pointer(p)).FpConfig, p+12, p+16)
	}
	/* Flush the hash table to disk if required */
	if iRowid < (*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid || iRowid == (*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid && (*TFts5Index)(unsafe.Pointer(p)).FbDelete == 0 || (*TFts5Index)(unsafe.Pointer(p)).FnPendingData > (*TFts5Config)(unsafe.Pointer((*TFts5Index)(unsafe.Pointer(p)).FpConfig)).FnHashSize {
		_fts5IndexFlush(tls, p)
	}
	(*TFts5Index)(unsafe.Pointer(p)).FiWriteRowid = iRowid
	(*TFts5Index)(unsafe.Pointer(p)).FbDelete = bDelete
	if bDelete == 0 {
		(*TFts5Index)(unsafe.Pointer(p)).FnPendingRow = (*TFts5Index)(unsafe.Pointer(p)).FnPendingRow + 1
	}
	return _fts5IndexReturn(tls, p)
}

// C documentation
//
//	/*
//	** Free the phrase object passed as the second argument.
//	*/
func _sqlite3Fts5ParseNearsetFree(tls *libc.TLS, pNear uintptr) {
	var i int32
	_ = i
	if pNear != 0 {
		i = 0
		for {
			if !(i < (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FnPhrase) {
				break
			}
			_fts5ExprPhraseFree(tls, *(*uintptr)(unsafe.Pointer(pNear + 12 + uintptr(i)*4)))
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_free(tls, (*TFts5ExprNearset)(unsafe.Pointer(pNear)).FpColset)
		Xsqlite3_free(tls, pNear)
	}
}

// C documentation
//
//	/*
//	** Set the "bFirst" flag on the first token of the phrase passed as the
//	** only argument.
//	*/
func _sqlite3Fts5ParseSetCaret(tls *libc.TLS, pPhrase uintptr) {
	if pPhrase != 0 && (*TFts5ExprPhrase)(unsafe.Pointer(pPhrase)).FnTerm != 0 {
		(*(*TFts5ExprTerm)(unsafe.Pointer(pPhrase + 20))).FbFirst = uint8(1)
	}
}

// C documentation
//
//	/*
//	** This function allocates a new parser.
//	** The only argument is a pointer to a function which works like
//	** malloc.
//	**
//	** Inputs:
//	** A pointer to the function used to allocate memory.
//	**
//	** Outputs:
//	** A pointer to a parser.  This pointer is used in subsequent calls
//	** to sqlite3Fts5Parser and sqlite3Fts5ParserFree.
//	*/
func _sqlite3Fts5ParserAlloc(tls *libc.TLS, __ccgo_fp_mallocProc uintptr) (r uintptr) {
	var fts5yypParser uintptr
	_ = fts5yypParser
	fts5yypParser = (*(*func(*libc.TLS, Tu64) uintptr)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_mallocProc})))(tls, libc.Uint64FromInt64(1216))
	if fts5yypParser != 0 {
		_sqlite3Fts5ParserInit(tls, fts5yypParser)
	}
	return fts5yypParser
}

// C documentation
//
//	/* Initialize a new parser that has already been allocated.
//	*/
func _sqlite3Fts5ParserInit(tls *libc.TLS, fts5yypRawParser uintptr) {
	var fts5yypParser uintptr
	_ = fts5yypParser
	fts5yypParser = fts5yypRawParser
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack = fts5yypParser + 16
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystackEnd = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack + uintptr(libc.Int32FromInt32(fts5YYSTACKDEPTH)-libc.Int32FromInt32(1))*12
	(*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yytos = (*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack
	(**(**Tfts5yyStackEntry)(__ccgo_up((*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack))).Fstateno = uint8(0)
	(**(**Tfts5yyStackEntry)(__ccgo_up((*Tfts5yyParser)(unsafe.Pointer(fts5yypParser)).Ffts5yystack))).Fmajor = uint8(0)
}

// C documentation
//
//	/*
//	** Arrange for subsequent calls to sqlite3Fts5Tokenize() to use the locale
//	** specified by pLocale/nLocale. The buffer indicated by pLocale must remain
//	** valid until after the final call to sqlite3Fts5Tokenize() that will use
//	** the locale.
//	*/
func _sqlite3Fts5SetLocale(tls *libc.TLS, pConfig uintptr, zLocale uintptr, nLocale int32) {
	var pT uintptr
	_ = pT
	pT = pConfig + 76
	(*TFts5TokenizerConfig)(unsafe.Pointer(pT)).FpLocale = zLocale
	(*TFts5TokenizerConfig)(unsafe.Pointer(pT)).FnLocale = nLocale
}

func _sqlite3Fts5TermsetNew(tls *libc.TLS, pp uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var _ /* rc at bp+0 */ int32
	**(**int32)(__ccgo_up(bp)) = SQLITE_OK
	**(**uintptr)(__ccgo_up(pp)) = _sqlite3Fts5MallocZero(tls, bp, int64(2048))
	return **(**int32)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Search a FuncDefHash for a function with the given name.  Return
//	** a pointer to the matching FuncDef if found, or 0 if there is no match.
//	*/
func _sqlite3FunctionSearch(tls *libc.TLS, h int32, zFunc uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = **(**uintptr)(__ccgo_up(uintptr(unsafe.Pointer(&_sqlite3BuiltinFunctions)) + uintptr(h)*4))
	for {
		if !(p != 0) {
			break
		}
		if _sqlite3StrICmp(tls, (*TFuncDef)(unsafe.Pointer(p)).FzName, zFunc) == 0 {
			return p
		}
		goto _1
	_1:
		;
		p = *(*uintptr)(unsafe.Pointer(p + 36))
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Return the collating function associated with a function.
//	*/
func _sqlite3GetFuncCollSeq(tls *libc.TLS, context uintptr) (r uintptr) {
	var pOp uintptr
	_ = pOp
	pOp = (*TVdbe)(unsafe.Pointer((*Tsqlite3_context)(unsafe.Pointer(context)).FpVdbe)).FaOp + uintptr((*Tsqlite3_context)(unsafe.Pointer(context)).FiOp-int32(1))*20
	return *(*uintptr)(unsafe.Pointer(pOp + 16))
}

// C documentation
//
//	/*
//	** Allocate or deallocate a block of nReg consecutive registers.
//	*/
func _sqlite3GetTempRange(tls *libc.TLS, pParse uintptr, nReg int32) (r int32) {
	var i, n int32
	_, _ = i, n
	if nReg == int32(1) {
		return _sqlite3GetTempReg(tls, pParse)
	}
	i = (*TParse)(unsafe.Pointer(pParse)).FiRangeReg
	n = (*TParse)(unsafe.Pointer(pParse)).FnRangeReg
	if nReg <= n {
		**(**int32)(__ccgo_up(pParse + 36)) += nReg
		**(**int32)(__ccgo_up(pParse + 32)) -= nReg
	} else {
		i = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
		**(**int32)(__ccgo_up(pParse + 48)) += nReg
	}
	return i
}

// C documentation
//
//	/*
//	** pTab is a pointer to a Table structure representing a virtual-table.
//	** Return a pointer to the VTable object used by connection db to access
//	** this virtual-table, if one has been created, or NULL otherwise.
//	*/
func _sqlite3GetVTable(tls *libc.TLS, db uintptr, pTab uintptr) (r uintptr) {
	var pVtab uintptr
	_ = pVtab
	pVtab = (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(pTab + 44))).Fp
	for {
		if !(pVtab != 0 && (*TVTable)(unsafe.Pointer(pVtab)).Fdb != db) {
			break
		}
		goto _1
	_1:
		;
		pVtab = (*TVTable)(unsafe.Pointer(pVtab)).FpNext
	}
	return pVtab
}

// C documentation
//
//	/* Insert an element into the hash table pH.  The key is pKey
//	** and the data is "data".
//	**
//	** If no element exists with a matching key, then a new
//	** element is created and NULL is returned.
//	**
//	** If another element already exists with the same key, then the
//	** new data replaces the old data and the old data is returned.
//	** The key is not copied in this instance.  If a malloc fails, then
//	** the new data is returned and the hash table is unchanged.
//	**
//	** If the "data" parameter to this function is NULL, then the
//	** element corresponding to "key" is removed from the hash table.
//	*/
func _sqlite3HashInsert(tls *libc.TLS, pH uintptr, pKey uintptr, data uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var elem, new_elem, old_data, v1 uintptr
	var _ /* h at bp+0 */ uint32
	_, _, _, _ = elem, new_elem, old_data, v1 /* New element added to the pH */
	elem = _findElementWithHash(tls, pH, pKey, bp)
	if (*THashElem)(unsafe.Pointer(elem)).Fdata != 0 {
		old_data = (*THashElem)(unsafe.Pointer(elem)).Fdata
		if data == uintptr(0) {
			_removeElement(tls, pH, elem)
		} else {
			(*THashElem)(unsafe.Pointer(elem)).Fdata = data
			(*THashElem)(unsafe.Pointer(elem)).FpKey = pKey
		}
		return old_data
	}
	if data == uintptr(0) {
		return uintptr(0)
	}
	new_elem = _sqlite3Malloc(tls, uint64(20))
	if new_elem == uintptr(0) {
		return data
	}
	(*THashElem)(unsafe.Pointer(new_elem)).FpKey = pKey
	(*THashElem)(unsafe.Pointer(new_elem)).Fh = **(**uint32)(__ccgo_up(bp))
	(*THashElem)(unsafe.Pointer(new_elem)).Fdata = data
	(*THash)(unsafe.Pointer(pH)).Fcount = (*THash)(unsafe.Pointer(pH)).Fcount + 1
	if (*THash)(unsafe.Pointer(pH)).Fcount >= uint32(5) && (*THash)(unsafe.Pointer(pH)).Fcount > uint32(2)*(*THash)(unsafe.Pointer(pH)).Fhtsize {
		_rehash(tls, pH, (*THash)(unsafe.Pointer(pH)).Fcount*uint32(3))
	}
	if (*THash)(unsafe.Pointer(pH)).Fht != 0 {
		v1 = (*THash)(unsafe.Pointer(pH)).Fht + uintptr((*THashElem)(unsafe.Pointer(new_elem)).Fh%(*THash)(unsafe.Pointer(pH)).Fhtsize)*8
	} else {
		v1 = uintptr(0)
	}
	_insertElement(tls, pH, v1, new_elem)
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Delete an IdList.
//	*/
func _sqlite3IdListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	var i int32
	_ = i
	if pList == uintptr(0) {
		return
	}
	i = 0
	for {
		if !(i < (*TIdList)(unsafe.Pointer(pList)).FnId) {
			break
		}
		_sqlite3DbFree(tls, db, (*(*TIdList_item)(unsafe.Pointer(pList + 4 + uintptr(i)*4))).FzName)
		goto _1
	_1:
		;
		i = i + 1
	}
	_sqlite3DbNNFreeNN(tls, db, pList)
}

// C documentation
//
//	/*
//	** Return the index in pList of the identifier named zId.  Return -1
//	** if not found.
//	*/
func _sqlite3IdListIndex(tls *libc.TLS, pList uintptr, zName uintptr) (r int32) {
	var i int32
	_ = i
	i = 0
	for {
		if !(i < (*TIdList)(unsafe.Pointer(pList)).FnId) {
			break
		}
		if _sqlite3StrICmp(tls, (*(*TIdList_item)(unsafe.Pointer(pList + 4 + uintptr(i)*4))).FzName, zName) == 0 {
			return i
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return -int32(1)
}

/*
** Maximum size of a SrcList object.
** The SrcList object is used to represent the FROM clause of a
** SELECT statement, and the query planner cannot deal with more
** than 64 tables in a join.  So any value larger than 64 here
** is sufficient for most uses.  Smaller values, like say 10, are
** appropriate for small and memory-limited applications.
 */

// C documentation
//
//	/*
//	** Return true if the floating point value is Not a Number (NaN).
//	**
//	** Use the math library isnan() function if compiled with SQLITE_HAVE_ISNAN.
//	** Otherwise, we have our own implementation that works on most systems.
//	*/
func _sqlite3IsNaN(tls *libc.TLS, _x float64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = _x
	var rc int32
	var _ /* y at bp+8 */ Tu64
	_ = rc
	libc.Xmemcpy(tls, bp+8, bp, uint32(8))
	rc = libc.BoolInt32(**(**Tu64)(__ccgo_up(bp + 8))&(libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52)) == libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52) && **(**Tu64)(__ccgo_up(bp + 8))&(libc.Uint64FromInt32(1)<<libc.Int32FromInt32(52)-libc.Uint64FromInt32(1)) != uint64(0))
	return rc
}

// C documentation
//
//	/*
//	** Return true if the floating point value is NaN or +Inf or -Inf.
//	*/
func _sqlite3IsOverflow(tls *libc.TLS, _x float64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = _x
	var rc int32
	var _ /* y at bp+8 */ Tu64
	_ = rc
	libc.Xmemcpy(tls, bp+8, bp, uint32(8))
	rc = libc.BoolInt32(**(**Tu64)(__ccgo_up(bp + 8))&(libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52)) == libc.Uint64FromInt32(0x7ff)<<libc.Int32FromInt32(52))
	return rc
}

// C documentation
//
//	/*
//	** Register the JSON table-valued function named zName and return a
//	** pointer to its Module object.  Return NULL if something goes wrong.
//	*/
func _sqlite3JsonVtabRegister(tls *libc.TLS, db uintptr, zName uintptr) (r uintptr) {
	var i uint32
	_ = i
	i = uint32(0)
	for {
		if !(i < libc.Uint32FromInt64(16)/libc.Uint32FromInt64(4)) {
			break
		}
		if _sqlite3StrICmp(tls, _azModule[i], zName) == 0 {
			return _sqlite3VtabCreateModule(tls, db, _azModule[i], uintptr(unsafe.Pointer(&_jsonEachModule)), uintptr(0), uintptr(0))
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Given an expression list, generate a KeyInfo structure that records
//	** the collating sequence for each expression in that expression list.
//	**
//	** If the ExprList is an ORDER BY or GROUP BY clause then the resulting
//	** KeyInfo structure is appropriate for initializing a virtual index to
//	** implement that clause.  If the ExprList is the result set of a SELECT
//	** then the KeyInfo structure is appropriate for initializing a virtual
//	** index to implement a DISTINCT test.
//	**
//	** Space to hold the KeyInfo structure is obtained from malloc.  The calling
//	** function is responsible for seeing that this structure is eventually
//	** freed.
//	*/
func _sqlite3KeyInfoFromExprList(tls *libc.TLS, pParse uintptr, pList uintptr, iStart int32, nExtra int32) (r uintptr) {
	var db, pInfo, pItem uintptr
	var i, nExpr int32
	_, _, _, _, _ = db, i, nExpr, pInfo, pItem
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	nExpr = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	pInfo = _sqlite3KeyInfoAlloc(tls, db, nExpr-iStart, nExtra+int32(1))
	if pInfo != 0 {
		i = iStart
		pItem = pList + 8 + uintptr(iStart)*20
		for {
			if !(i < nExpr) {
				break
			}
			*(*uintptr)(unsafe.Pointer(pInfo + 20 + uintptr(i-iStart)*4)) = _sqlite3ExprNNCollSeq(tls, pParse, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr)
			**(**Tu8)(__ccgo_up((*TKeyInfo)(unsafe.Pointer(pInfo)).FaSortFlags + uintptr(i-iStart))) = (*TExprList_item)(unsafe.Pointer(pItem)).Ffg.FsortFlags
			goto _1
		_1:
			;
			i = i + 1
			pItem += 20
		}
	}
	return pInfo
}

// C documentation
//
//	/*
//	** Locate the table identified by *p.
//	**
//	** This is a wrapper around sqlite3LocateTable(). The difference between
//	** sqlite3LocateTable() and this function is that this function restricts
//	** the search to schema (p->pSchema) if it is not NULL. p->pSchema may be
//	** non-NULL if it is part of a view or trigger program definition. See
//	** sqlite3FixSrcList() for details.
//	*/
func _sqlite3LocateTableItem(tls *libc.TLS, pParse uintptr, flags Tu32, p uintptr) (r uintptr) {
	var iDb int32
	var zDb uintptr
	_, _ = iDb, zDb
	if int32(*(*uint32)(unsafe.Pointer(p + 12 + 4))&0x10000>>16) != 0 {
		iDb = _sqlite3SchemaToIndex(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(p + 44)))
		zDb = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FzDbSName
	} else {
		zDb = *(*uintptr)(unsafe.Pointer(p + 44))
	}
	return _sqlite3LocateTable(tls, pParse, flags, (*TSrcItem)(unsafe.Pointer(p)).FzName, zDb)
}

// C documentation
//
//	/*
//	** Allocate and zero memory.
//	*/
func _sqlite3MallocZero(tls *libc.TLS, n Tu64) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3Malloc(tls, n)
	if p != 0 {
		libc.Xmemset(tls, p, 0, uint32(n))
	}
	return p
}

// C documentation
//
//	/*
//	** Evaluate a view and store its result in an ephemeral table.  The
//	** pWhere argument is an optional WHERE clause that restricts the
//	** set of rows in the view that are to be added to the ephemeral table.
//	*/
func _sqlite3MaterializeView(tls *libc.TLS, pParse uintptr, pView uintptr, pWhere uintptr, pOrderBy uintptr, pLimit uintptr, iCur int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var db, pFrom, pSel uintptr
	var iDb int32
	var _ /* dest at bp+0 */ TSelectDest
	_, _, _, _ = db, iDb, pFrom, pSel
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	iDb = _sqlite3SchemaToIndex(tls, db, (*TTable)(unsafe.Pointer(pView)).FpSchema)
	pWhere = _sqlite3ExprDup(tls, db, pWhere, 0)
	pFrom = _sqlite3SrcListAppend(tls, pParse, uintptr(0), uintptr(0), uintptr(0))
	if pFrom != 0 {
		(*(*TSrcItem)(unsafe.Pointer(pFrom + 8))).FzName = _sqlite3DbStrDup(tls, db, (*TTable)(unsafe.Pointer(pView)).FzName)
		*(*uintptr)(unsafe.Pointer(pFrom + 8 + 44)) = _sqlite3DbStrDup(tls, db, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FzDbSName)
	}
	pSel = _sqlite3SelectNew(tls, pParse, uintptr(0), pFrom, pWhere, uintptr(0), uintptr(0), pOrderBy, uint32(SF_IncludeHidden), pLimit)
	_sqlite3SelectDestInit(tls, bp, int32(SRT_EphemTab), iCur)
	_sqlite3Select(tls, pParse, pSel, bp)
	_sqlite3SelectDelete(tls, db, pSel)
}

/*      && !defined(SQLITE_OMIT_SUBQUERY) */

// C documentation
//
//	/*
//	** The code generator calls this routine if is discovers that it is
//	** possible to abort a statement prior to completion.  In order to
//	** perform this abort without corrupting the database, we need to make
//	** sure that the statement is protected by a statement transaction.
//	**
//	** Technically, we only need to set the mayAbort flag if the
//	** isMultiWrite flag was previously set.  There is a time dependency
//	** such that the abort must occur after the multiwrite.  This makes
//	** some statements involving the REPLACE conflict resolution algorithm
//	** go a little faster.  But taking advantage of this time dependency
//	** makes it more difficult to prove that the code is correct (in
//	** particular, it prevents us from writing an effective
//	** implementation of sqlite3AssertMayAbort()) and so we have chosen
//	** to take the safe route and skip the optimization.
//	*/
func _sqlite3MayAbort(tls *libc.TLS, pParse uintptr) {
	var pToplevel, v1 uintptr
	_, _ = pToplevel, v1
	if (*TParse)(unsafe.Pointer(pParse)).FpToplevel != 0 {
		v1 = (*TParse)(unsafe.Pointer(pParse)).FpToplevel
	} else {
		v1 = pParse
	}
	pToplevel = v1
	libc.SetBitFieldPtr16Uint32(pToplevel+28, libc.Uint32FromInt32(1), 1, 0x2)
}

// C documentation
//
//	/*
//	** Set the iIdx'th entry of array aMem[] to contain integer value val.
//	*/
func _sqlite3MemSetArrayInt64(tls *libc.TLS, aMem uintptr, iIdx int32, val Ti64) {
	_sqlite3VdbeMemSetInt64(tls, aMem+uintptr(iIdx)*40, val)
}

// C documentation
//
//	/*
//	** If argument pVal is a Select object returned by an sqlite3MultiValues()
//	** that was able to use the co-routine optimization, finish coding the
//	** co-routine.
//	*/
func _sqlite3MultiValuesEnd(tls *libc.TLS, pParse uintptr, pVal uintptr) {
	var pItem uintptr
	_ = pItem
	if pVal != 0 && (*TSrcList)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pVal)).FpSrc)).FnSrc > 0 {
		pItem = (*TSelect)(unsafe.Pointer(pVal)).FpSrc + 8
		if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0 {
			_sqlite3VdbeEndCoroutine(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FregReturn)
			_sqlite3VdbeJumpHere(tls, (*TParse)(unsafe.Pointer(pParse)).FpVdbe, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FaddrFillSub-int32(1))
		}
	}
}

// C documentation
//
//	/*
//	** This function is called during initialization if a static buffer is
//	** supplied to use for the page-cache by passing the SQLITE_CONFIG_PAGECACHE
//	** verb to sqlite3_config(). Parameter pBuf points to an allocation large
//	** enough to contain 'n' buffers of 'sz' bytes each.
//	**
//	** This routine is called from sqlite3_initialize() and so it is guaranteed
//	** to be serialized already.  There is no need for further mutexing.
//	*/
func _sqlite3PCacheBufferSetup(tls *libc.TLS, pBuf uintptr, sz int32, n int32) {
	var p uintptr
	var v1 int32
	_, _ = p, v1
	if libc.AtomicLoadPInt32(uintptr(unsafe.Pointer(&_pcache1_g))+52) != 0 {
		if pBuf == uintptr(0) {
			v1 = libc.Int32FromInt32(0)
			n = v1
			sz = v1
		}
		if n == 0 {
			sz = 0
		}
		sz = sz & ^libc.Int32FromInt32(7)
		_pcache1_g.FszSlot = sz
		v1 = n
		_pcache1_g.FnFreeSlot = v1
		_pcache1_g.FnSlot = v1
		if n > int32(90) {
			v1 = int32(10)
		} else {
			v1 = n/int32(10) + int32(1)
		}
		_pcache1_g.FnReserve = v1
		_pcache1_g.FpStart = pBuf
		_pcache1_g.FpFree = uintptr(0)
		libc.AtomicStoreNInt32(uintptr(unsafe.Pointer(&_pcache1_g))+96, libc.Int32FromInt32(0), libc.Int32FromInt32(__ATOMIC_RELAXED))
		for {
			v1 = n
			n = n - 1
			if !(v1 != 0) {
				break
			}
			p = pBuf
			(*TPgFreeslot)(unsafe.Pointer(p)).FpNext = _pcache1_g.FpFree
			_pcache1_g.FpFree = p
			pBuf = pBuf + uintptr(sz)
		}
		_pcache1_g.FpEnd = pBuf
	}
}

// C documentation
//
//	/*
//	** Add a new cleanup operation to a Parser.  The cleanup should happen when
//	** the parser object is destroyed.  But, beware: the cleanup might happen
//	** immediately.
//	**
//	** Use this mechanism for uncommon cleanups.  There is a higher setup
//	** cost for this mechanism (an extra malloc), so it should not be used
//	** for common cleanups that happen on most calls.  But for less
//	** common cleanups, we save a single NULL-pointer comparison in
//	** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
//	**
//	** If a memory allocation error occurs, then the cleanup happens immediately.
//	** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
//	** pParse->earlyCleanup flag is set in that case.  Calling code show verify
//	** that test cases exist for which this happens, to guard against possible
//	** use-after-free errors following an OOM.  The preferred way to do this is
//	** to immediately follow the call to this routine with:
//	**
//	**       testcase( pParse->earlyCleanup );
//	**
//	** This routine returns a copy of its pPtr input (the third parameter)
//	** except if an early cleanup occurs, in which case it returns NULL.  So
//	** another way to check for early cleanup is to check the return value.
//	** Or, stop using the pPtr parameter with this call and use only its
//	** return value thereafter.  Something like this:
//	**
//	**       pObj = sqlite3ParserAddCleanup(pParse, destructor, pObj);
//	*/
func _sqlite3ParserAddCleanup(tls *libc.TLS, pParse uintptr, __ccgo_fp_xCleanup uintptr, pPtr uintptr) (r uintptr) {
	var pCleanup uintptr
	_ = pCleanup
	if _sqlite3FaultSim(tls, int32(300)) != 0 {
		pCleanup = uintptr(0)
		_sqlite3OomFault(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb)
	} else {
		pCleanup = _sqlite3DbMallocRaw(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(12))
	}
	if pCleanup != 0 {
		(*TParseCleanup)(unsafe.Pointer(pCleanup)).FpNext = (*TParse)(unsafe.Pointer(pParse)).FpCleanup
		(*TParse)(unsafe.Pointer(pParse)).FpCleanup = pCleanup
		(*TParseCleanup)(unsafe.Pointer(pCleanup)).FpPtr = pPtr
		(*TParseCleanup)(unsafe.Pointer(pCleanup)).FxCleanup = __ccgo_fp_xCleanup
	} else {
		(*(*func(*libc.TLS, uintptr, uintptr))(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xCleanup})))(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pPtr)
		pPtr = uintptr(0)
	}
	return pPtr
}

// C documentation
//
//	/* Initialize a new parser that has already been allocated.
//	*/
func _sqlite3ParserInit(tls *libc.TLS, yypRawParser uintptr, pParse uintptr) {
	var yypParser uintptr
	_ = yypParser
	yypParser = yypRawParser
	(*TyyParser)(unsafe.Pointer(yypParser)).FpParse = pParse
	(*TyyParser)(unsafe.Pointer(yypParser)).Fyystack = yypParser + 16
	(*TyyParser)(unsafe.Pointer(yypParser)).FyystackEnd = (*TyyParser)(unsafe.Pointer(yypParser)).Fyystack + uintptr(libc.Int32FromInt32(YYSTACKDEPTH)-libc.Int32FromInt32(1))*12
	(*TyyParser)(unsafe.Pointer(yypParser)).Fyytos = (*TyyParser)(unsafe.Pointer(yypParser)).Fyystack
	(**(**TyyStackEntry)(__ccgo_up((*TyyParser)(unsafe.Pointer(yypParser)).Fyystack))).Fstateno = uint16(0)
	(**(**TyyStackEntry)(__ccgo_up((*TyyParser)(unsafe.Pointer(yypParser)).Fyystack))).Fmajor = uint16(0)
}

// C documentation
//
//	/*
//	** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
//	*/
func _sqlite3PcacheClearSyncFlags(tls *libc.TLS, pCache uintptr) {
	var p, v2 uintptr
	_, _ = p, v2
	p = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
	for {
		if !(p != 0) {
			break
		}
		v2 = p + 28
		*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) & ^libc.Int32FromInt32(PGHDR_NEED_SYNC))
		goto _1
	_1:
		;
		p = (*TPgHdr)(unsafe.Pointer(p)).FpDirtyNext
	}
	(*TPCache)(unsafe.Pointer(pCache)).FpSynced = (*TPCache)(unsafe.Pointer(pCache)).FpDirtyTail
}

// C documentation
//
//	/*
//	** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
//	*/
func _sqlite3PcacheClearWritable(tls *libc.TLS, pCache uintptr) {
	var p, v2 uintptr
	_, _ = p, v2
	p = (*TPCache)(unsafe.Pointer(pCache)).FpDirty
	for {
		if !(p != 0) {
			break
		}
		v2 = p + 28
		*(*Tu16)(unsafe.Pointer(v2)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v2))) & ^(libc.Int32FromInt32(PGHDR_NEED_SYNC) | libc.Int32FromInt32(PGHDR_WRITEABLE)))
		goto _1
	_1:
		;
		p = (*TPgHdr)(unsafe.Pointer(p)).FpDirtyNext
	}
	(*TPCache)(unsafe.Pointer(pCache)).FpSynced = (*TPCache)(unsafe.Pointer(pCache)).FpDirtyTail
}

// C documentation
//
//	/*
//	** Make sure the page is marked as clean. If it isn't clean already,
//	** make it so.
//	*/
func _sqlite3PcacheMakeClean(tls *libc.TLS, p uintptr) {
	var v1 uintptr
	_ = v1
	_pcacheManageDirtyList(tls, p, uint8(PCACHE_DIRTYLIST_REMOVE))
	v1 = p + 28
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^(libc.Int32FromInt32(PGHDR_DIRTY) | libc.Int32FromInt32(PGHDR_NEED_SYNC) | libc.Int32FromInt32(PGHDR_WRITEABLE)))
	v1 = p + 28
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) | libc.Int32FromInt32(PGHDR_CLEAN))
	if (*TPgHdr)(unsafe.Pointer(p)).FnRef == 0 {
		_pcacheUnpin(tls, p)
	}
}

// C documentation
//
//	/*
//	** Return the PRIMARY KEY index of a table
//	*/
func _sqlite3PrimaryKeyIndex(tls *libc.TLS, pTab uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = (*TTable)(unsafe.Pointer(pTab)).FpIndex
	for {
		if !(p != 0 && !(int32(uint32(*(*uint16)(unsafe.Pointer(p + 56))&0x3>>0)) == libc.Int32FromInt32(SQLITE_IDXTYPE_PRIMARYKEY))) {
			break
		}
		goto _1
	_1:
		;
		p = (*TIndex)(unsafe.Pointer(p)).FpNext
	}
	return p
}

func _sqlite3PrngRestoreState(tls *libc.TLS) {
	libc.Xmemcpy(tls, uintptr(unsafe.Pointer(&_sqlite3Prng)), uintptr(unsafe.Pointer(&_sqlite3SavedPrng)), uint32(132))
}

func _sqlite3PrngSaveState(tls *libc.TLS) {
	libc.Xmemcpy(tls, uintptr(unsafe.Pointer(&_sqlite3SavedPrng)), uintptr(unsafe.Pointer(&_sqlite3Prng)), uint32(132))
}

// C documentation
//
//	/*
//	** Scan the expression list that is the argument to RETURNING looking
//	** for subqueries that depend on the table which is being modified in the
//	** statement that is hosting the RETURNING clause (pTab).  Mark all such
//	** subqueries as SF_Correlated.  If the subqueries are part of an
//	** expression, mark the expression as EP_VarSelect.
//	**
//	** https://sqlite.org/forum/forumpost/2c83569ce8945d39
//	*/
func _sqlite3ProcessReturningSubqueries(tls *libc.TLS, pEList uintptr, pTab uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	libc.Xmemset(tls, bp, 0, uint32(28))
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_sqlite3ExprWalkNoop)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3ReturningSubqueryCorrelated)
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pTab
	_sqlite3WalkExprList(tls, bp, pEList)
	if (**(**TWalker)(__ccgo_up(bp))).FeCode != 0 {
		(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_sqlite3ReturningSubqueryVarSelect)
		(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
		_sqlite3WalkExprList(tls, bp, pEList)
	}
}

// C documentation
//
//	/*
//	** This routine is a no-op if the database schema is already initialized.
//	** Otherwise, the schema is loaded. An error code is returned.
//	*/
func _sqlite3ReadSchema(tls *libc.TLS, pParse uintptr) (r int32) {
	var db uintptr
	var rc int32
	_, _ = db, rc
	rc = SQLITE_OK
	db = (*TParse)(unsafe.Pointer(pParse)).Fdb
	if !((*Tsqlite3)(unsafe.Pointer(db)).Finit1.Fbusy != 0) {
		rc = _sqlite3Init(tls, db, pParse+4)
		if rc != SQLITE_OK {
			(*TParse)(unsafe.Pointer(pParse)).Frc = rc
			(*TParse)(unsafe.Pointer(pParse)).FnErr = (*TParse)(unsafe.Pointer(pParse)).FnErr + 1
		} else {
			if (*Tsqlite3)(unsafe.Pointer(db)).FnoSharedCache != 0 {
				**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaKnownOk)
			}
		}
	}
	return rc
}

// C documentation
//
//	/* Compare a floating point value to an integer.  Return true if the two
//	** values are the same within the precision of the floating point value.
//	**
//	** This function assumes that i was obtained by assignment from r1.
//	**
//	** For some versions of GCC on 32-bit machines, if you do the more obvious
//	** comparison of "r1==(double)i" you sometimes get an answer of false even
//	** though the r1 and (double)i values are bit-for-bit the same.
//	*/
func _sqlite3RealSameAsInt(tls *libc.TLS, _r1 float64, i Tsqlite3_int64) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*float64)(unsafe.Pointer(bp)) = _r1
	var _ /* r2 at bp+8 */ float64
	**(**float64)(__ccgo_up(bp + 8)) = float64(i)
	return libc.BoolInt32(**(**float64)(__ccgo_up(bp)) == float64(0) || libc.Xmemcmp(tls, bp, bp+8, uint32(8)) == 0 && i >= -int64(2251799813685248) && i < int64(2251799813685248))
}

// C documentation
//
//	/*
//	** The z string points to the first character of a token that is
//	** associated with an error.  If db does not already have an error
//	** byte offset recorded, try to compute the error byte offset for
//	** z and set the error byte offset in db.
//	*/
func _sqlite3RecordErrorByteOffset(tls *libc.TLS, db uintptr, z uintptr) {
	var pParse, zEnd, zText uintptr
	_, _, _ = pParse, zEnd, zText
	if db == uintptr(0) {
		return
	}
	if (*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset != -int32(2) {
		return
	}
	pParse = (*Tsqlite3)(unsafe.Pointer(db)).FpParse
	if pParse == uintptr(0) {
		return
	}
	zText = (*TParse)(unsafe.Pointer(pParse)).FzTail
	if zText == uintptr(0) {
		return
	}
	zEnd = zText + uintptr(libc.Xstrlen(tls, zText))
	if uint32(z) >= uint32(zText) && uint32(z) < uint32(zEnd) {
		(*Tsqlite3)(unsafe.Pointer(db)).FerrByteOffset = int32(z) - int32(zText)
	}
}

// C documentation
//
//	/*
//	** Remove all nodes that are part of expression pExpr from the rename list.
//	*/
func _sqlite3RenameExprUnmap(tls *libc.TLS, pParse uintptr, pExpr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var eMode Tu8
	var _ /* sWalker at bp+0 */ TWalker
	_ = eMode
	eMode = (*TParse)(unsafe.Pointer(pParse)).FeParseMode
	libc.Xmemset(tls, bp, 0, uint32(28))
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_renameUnmapExprCb)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_renameUnmapSelectCb)
	(*TParse)(unsafe.Pointer(pParse)).FeParseMode = uint8(PARSE_MODE_UNMAP)
	_sqlite3WalkExpr(tls, bp, pExpr)
	(*TParse)(unsafe.Pointer(pParse)).FeParseMode = eMode
}

// C documentation
//
//	/*
//	** Remove all nodes that are part of expression-list pEList from the
//	** rename list.
//	*/
func _sqlite3RenameExprlistUnmap(tls *libc.TLS, pParse uintptr, pEList uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var i int32
	var _ /* sWalker at bp+0 */ TWalker
	_ = i
	if pEList != 0 {
		libc.Xmemset(tls, bp, 0, uint32(28))
		(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
		(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_renameUnmapExprCb)
		_sqlite3WalkExprList(tls, bp, pEList)
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pEList)).FnExpr) {
				break
			}
			if int32(uint32(*(*uint16)(unsafe.Pointer(pEList + 8 + uintptr(i)*20 + 8 + 4))&0x3>>0)) == ENAME_NAME {
				_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TExprList_item)(unsafe.Pointer(pEList + 8 + uintptr(i)*20))).FzEName)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
}

// C documentation
//
//	/*
//	** Resolve all names in all expressions of a SELECT and in all
//	** descendants of the SELECT, including compounds off of p->pPrior,
//	** subqueries in expressions, and subqueries used as FROM clause
//	** terms.
//	**
//	** See sqlite3ResolveExprNames() for a description of the kinds of
//	** transformations that occur.
//	**
//	** All SELECT statements should have been expanded using
//	** sqlite3SelectExpand() prior to invoking this routine.
//	*/
func _sqlite3ResolveSelectNames(tls *libc.TLS, pParse uintptr, p uintptr, pOuterNC uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_resolveExprStep)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_resolveSelectStep)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = uintptr(0)
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	*(*uintptr)(unsafe.Pointer(bp + 24)) = pOuterNC
	_sqlite3WalkSelect(tls, bp, p)
}

// C documentation
//
//	/*
//	** If the SELECT references the table pWalker->u.pTab, then do two things:
//	**
//	**    (1) Mark the SELECT as as SF_Correlated.
//	**    (2) Set pWalker->eCode to non-zero so that the caller will know
//	**        that (1) has happened.
//	*/
func _sqlite3ReturningSubqueryCorrelated(tls *libc.TLS, pWalker uintptr, pSelect uintptr) (r int32) {
	var i int32
	var pSrc uintptr
	_, _ = i, pSrc
	pSrc = (*TSelect)(unsafe.Pointer(pSelect)).FpSrc
	i = 0
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		if (*(*TSrcItem)(unsafe.Pointer(pSrc + 8 + uintptr(i)*48))).FpSTab == *(*uintptr)(unsafe.Pointer(pWalker + 24)) {
			**(**Tu32)(__ccgo_up(pSelect + 4)) |= uint32(SF_Correlated)
			(*TWalker)(unsafe.Pointer(pWalker)).FeCode = uint16(1)
			break
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** This function is called by the VDBE to adjust the internal schema
//	** used by SQLite when the btree layer moves a table root page. The
//	** root-page of a table or index in database iDb has changed from iFrom
//	** to iTo.
//	**
//	** Ticket #1728:  The symbol table might still contain information
//	** on tables and/or indices that are the process of being deleted.
//	** If you are unlucky, one of those deleted indices or tables might
//	** have the same rootpage number as the real table or index that is
//	** being moved.  So we cannot stop searching after the first match
//	** because the first match might be for one of the deleted indices
//	** or tables and not the table/index that is actually being moved.
//	** We must continue looping until all tables and indices with
//	** rootpage==iFrom have been converted to have a rootpage of iTo
//	** in order to be certain that we got the right one.
//	*/
func _sqlite3RootPageMoved(tls *libc.TLS, db uintptr, iDb int32, iFrom TPgno, iTo TPgno) {
	var pDb, pElem, pHash, pIdx, pTab uintptr
	_, _, _, _, _ = pDb, pElem, pHash, pIdx, pTab
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	pHash = (*TDb)(unsafe.Pointer(pDb)).FpSchema + 8
	pElem = (*THash)(unsafe.Pointer(pHash)).Ffirst
	for {
		if !(pElem != 0) {
			break
		}
		pTab = (*THashElem)(unsafe.Pointer(pElem)).Fdata
		if (*TTable)(unsafe.Pointer(pTab)).Ftnum == iFrom {
			(*TTable)(unsafe.Pointer(pTab)).Ftnum = iTo
		}
		goto _1
	_1:
		;
		pElem = (*THashElem)(unsafe.Pointer(pElem)).Fnext
	}
	pHash = (*TDb)(unsafe.Pointer(pDb)).FpSchema + 24
	pElem = (*THash)(unsafe.Pointer(pHash)).Ffirst
	for {
		if !(pElem != 0) {
			break
		}
		pIdx = (*THashElem)(unsafe.Pointer(pElem)).Fdata
		if (*TIndex)(unsafe.Pointer(pIdx)).Ftnum == iFrom {
			(*TIndex)(unsafe.Pointer(pIdx)).Ftnum = iTo
		}
		goto _2
	_2:
		;
		pElem = (*THashElem)(unsafe.Pointer(pElem)).Fnext
	}
}

// C documentation
//
//	/*
//	** Insert a new value into a RowSet.
//	**
//	** The mallocFailed flag of the database connection is set if a
//	** memory allocation fails.
//	*/
func _sqlite3RowSetInsert(tls *libc.TLS, p uintptr, rowid Ti64) {
	var pEntry, pLast, v1 uintptr
	_, _, _ = pEntry, pLast, v1 /* The last prior entry */
	/* This routine is never called after sqlite3RowSetNext() */
	pEntry = _rowSetEntryAlloc(tls, p)
	if pEntry == uintptr(0) {
		return
	}
	(*TRowSetEntry)(unsafe.Pointer(pEntry)).Fv = rowid
	(*TRowSetEntry)(unsafe.Pointer(pEntry)).FpRight = uintptr(0)
	pLast = (*TRowSet)(unsafe.Pointer(p)).FpLast
	if pLast != 0 {
		if rowid <= (*TRowSetEntry)(unsafe.Pointer(pLast)).Fv { /*OPTIMIZATION-IF-FALSE*/
			/* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
			 ** where possible */
			v1 = p + 26
			*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & ^libc.Int32FromInt32(ROWSET_SORTED))
		}
		(*TRowSetEntry)(unsafe.Pointer(pLast)).FpRight = pEntry
	} else {
		(*TRowSet)(unsafe.Pointer(p)).FpEntry = pEntry
	}
	(*TRowSet)(unsafe.Pointer(p)).FpLast = pEntry
}

// C documentation
//
//	/*
//	** Convert a schema pointer into the iDb index that indicates
//	** which database file in db->aDb[] the schema refers to.
//	**
//	** If the same database is attached more than once, the first
//	** attached database is returned.
//	*/
func _sqlite3SchemaToIndex(tls *libc.TLS, db uintptr, pSchema uintptr) (r int32) {
	var i int32
	_ = i
	i = -int32(32768)
	/* If pSchema is NULL, then return -32768. This happens when code in
	 ** expr.c is trying to resolve a reference to a transient table (i.e. one
	 ** created by a sub-select). In this case the return value of this
	 ** function should never be used.
	 **
	 ** We return -32768 instead of the more usual -1 simply because using
	 ** -32768 as the incorrect index into db->aDb[] is much
	 ** more likely to cause a segfault than -1 (of course there are assert()
	 ** statements too, but it never hurts to play the odds) and
	 ** -32768 will still fit into a 16-bit signed integer.
	 */
	if pSchema != 0 {
		i = 0
		for {
			if !(int32(1) != 0) {
				break
			}
			if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpSchema == pSchema {
				break
			}
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	return i
}

// C documentation
//
//	/*
//	** This routine adds datatype and collating sequence information to
//	** the Table structures of all FROM-clause subqueries in a
//	** SELECT statement.
//	**
//	** Use this routine after name resolution.
//	*/
func _sqlite3SelectAddTypeInfo(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_sqlite3SelectWalkNoop)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = __ccgo_fp(_selectAddSubqueryTypeInfo)
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_sqlite3ExprWalkNoop)
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	_sqlite3WalkSelect(tls, bp, pSelect)
}

// C documentation
//
//	/*
//	** This routine "expands" a SELECT statement and all of its subqueries.
//	** For additional information on what it means to "expand" a SELECT
//	** statement, see the comment on the selectExpand worker callback above.
//	**
//	** Expanding a SELECT statement is the first step in processing a
//	** SELECT statement.  The SELECT statement must be expanded before
//	** name resolution is performed.
//	**
//	** If anything goes wrong, an error message is written into pParse.
//	** The calling function can detect the problem by looking at pParse->nErr
//	** and/or pParse->db->mallocFailed.
//	*/
func _sqlite3SelectExpand(tls *libc.TLS, pParse uintptr, pSelect uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* w at bp+0 */ TWalker
	(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_sqlite3ExprWalkNoop)
	(**(**TWalker)(__ccgo_up(bp))).FpParse = pParse
	if int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 28))&0x4>>2)) != 0 {
		(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_convertCompoundSelectToSubquery)
		(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = uintptr(0)
		_sqlite3WalkSelect(tls, bp, pSelect)
	}
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback = __ccgo_fp(_selectExpander)
	(**(**TWalker)(__ccgo_up(bp))).FxSelectCallback2 = __ccgo_fp(_sqlite3SelectPopWith)
	(**(**TWalker)(__ccgo_up(bp))).FeCode = uint16(0)
	_sqlite3WalkSelect(tls, bp, pSelect)
}

// C documentation
//
//	/*
//	** Set the EP_OuterON property on all terms of the given expression.
//	** And set the Expr.w.iJoin to iTable for every term in the
//	** expression.
//	**
//	** The EP_OuterON property is used on terms of an expression to tell
//	** the OUTER JOIN processing logic that this term is part of the
//	** join restriction specified in the ON or USING clause and not a part
//	** of the more general WHERE clause.  These terms are moved over to the
//	** WHERE clause during join processing but we need to remember that they
//	** originated in the ON or USING clause.
//	**
//	** The Expr.w.iJoin tells the WHERE clause processing that the
//	** expression depends on table w.iJoin even if that table is not
//	** explicitly mentioned in the expression.  That information is needed
//	** for cases like this:
//	**
//	**    SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5
//	**
//	** The where clause needs to defer the handling of the t1.x=5
//	** term until after the t2 loop of the join.  In that way, a
//	** NULL t2 row will be inserted whenever t1.x!=5.  If we do not
//	** defer the handling of t1.x=5, it will be processed immediately
//	** after the t1 loop and rows with t1.x!=5 will never appear in
//	** the output, which is incorrect.
//	*/
func _sqlite3SetJoinExpr(tls *libc.TLS, p uintptr, iTable int32, joinFlag Tu32) {
	var i int32
	_ = i
	for p != 0 {
		**(**Tu32)(__ccgo_up(p + 4)) |= joinFlag
		*(*int32)(unsafe.Pointer(p + 36)) = iTable
		if (*TExpr)(unsafe.Pointer(p)).Fflags&uint32(EP_xIsSelect) == uint32(0) {
			if *(*uintptr)(unsafe.Pointer(p + 20)) != 0 {
				i = 0
				for {
					if !(i < (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)))).FnExpr) {
						break
					}
					_sqlite3SetJoinExpr(tls, (*(*TExprList_item)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(p + 20)) + 8 + uintptr(i)*20))).FpExpr, iTable, joinFlag)
					goto _1
				_1:
					;
					i = i + 1
				}
			}
		}
		_sqlite3SetJoinExpr(tls, (*TExpr)(unsafe.Pointer(p)).FpLeft, iTable, joinFlag)
		p = (*TExpr)(unsafe.Pointer(p)).FpRight
	}
}

// C documentation
//
//	/*
//	** Attach a Subquery object to pItem->uv.pSubq.  Set the
//	** pSelect value but leave all the other values initialized
//	** to zero.
//	**
//	** A copy of the Select object is made if dupSelect is true, and the
//	** SrcItem takes responsibility for deleting the copy.  If dupSelect is
//	** false, ownership of the Select passes to the SrcItem.  Either way,
//	** the SrcItem will take responsibility for deleting the Select.
//	**
//	** When dupSelect is zero, that means the Select might get deleted right
//	** away if there is an OOM error.  Beware.
//	**
//	** Return non-zero on success.  Return zero on an OOM error.
//	*/
func _sqlite3SrcItemAttachSubquery(tls *libc.TLS, pParse uintptr, pItem uintptr, pSelect uintptr, dupSelect int32) (r int32) {
	var p, v1 uintptr
	_, _ = p, v1
	if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x10000>>16) != 0 {
		*(*uintptr)(unsafe.Pointer(pItem + 44)) = uintptr(0)
		libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(0), 16, 0x10000)
	} else {
		if *(*uintptr)(unsafe.Pointer(pItem + 44)) != uintptr(0) {
			_sqlite3DbFree(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, *(*uintptr)(unsafe.Pointer(pItem + 44)))
			*(*uintptr)(unsafe.Pointer(pItem + 44)) = uintptr(0)
		}
	}
	if dupSelect != 0 {
		pSelect = _sqlite3SelectDup(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSelect, 0)
		if pSelect == uintptr(0) {
			return 0
		}
	}
	v1 = _sqlite3DbMallocRawNN(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, uint64(16))
	*(*uintptr)(unsafe.Pointer(pItem + 44)) = v1
	p = v1
	if p == uintptr(0) {
		_sqlite3SelectDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pSelect)
		return 0
	}
	libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(1), 2, 0x4)
	(*TSubquery)(unsafe.Pointer(p)).FpSelect = pSelect
	libc.Xmemset(tls, p+uintptr(4), 0, libc.Uint32FromInt64(16)-libc.Uint32FromInt64(4))
	return int32(1)
}

// C documentation
//
//	/*
//	** Mark a subquery result column as having been used.
//	*/
func _sqlite3SrcItemColumnUsed(tls *libc.TLS, pItem uintptr, iCol int32) {
	var pResults uintptr
	_ = pResults
	if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4000>>14) != 0 {
		pResults = (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect)).FpEList
		libc.SetBitFieldPtr16Uint32(pResults+8+uintptr(iCol)*20+8+4, libc.Uint32FromInt32(1), 6, 0x40)
	}
}

// C documentation
//
//	/*
//	** Assign VdbeCursor index numbers to all tables in a SrcList
//	*/
func _sqlite3SrcListAssignCursors(tls *libc.TLS, pParse uintptr, pList uintptr) {
	var i, v2 int32
	var pItem, v3 uintptr
	_, _, _, _ = i, pItem, v2, v3
	if pList != 0 {
		i = 0
		pItem = pList + 8
		for {
			if !(i < (*TSrcList)(unsafe.Pointer(pList)).FnSrc) {
				break
			}
			if (*TSrcItem)(unsafe.Pointer(pItem)).FiCursor >= 0 {
				goto _1
			}
			v3 = pParse + 44
			v2 = *(*int32)(unsafe.Pointer(v3))
			*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = v2
			if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0 {
				_sqlite3SrcListAssignCursors(tls, pParse, (*TSelect)(unsafe.Pointer((*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect)).FpSrc)
			}
			goto _1
		_1:
			;
			i = i + 1
			pItem += 48
		}
	}
}

// C documentation
//
//	/*
//	** Delete an entire SrcList including all its substructure.
//	*/
func _sqlite3SrcListDelete(tls *libc.TLS, db uintptr, pList uintptr) {
	var i int32
	var pItem uintptr
	_, _ = i, pItem
	if pList == uintptr(0) {
		return
	}
	pItem = pList + 8
	i = libc.Int32FromInt32(0)
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pList)).FnSrc) {
			break
		}
		/* Check invariants on SrcItem */
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzName != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FzName)
		}
		if (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias != 0 {
			_sqlite3DbNNFreeNN(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FzAlias)
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0 {
			_sqlite3SubqueryDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 44)))
		} else {
			if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x10000>>16) == 0 && *(*uintptr)(unsafe.Pointer(pItem + 44)) != uintptr(0) {
				_sqlite3DbNNFreeNN(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 44)))
			}
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x2>>1) != 0 {
			_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 32)))
		}
		if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x8>>3) != 0 {
			_sqlite3ExprListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 32)))
		}
		_sqlite3DeleteTable(tls, db, (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)
		if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x800>>11) != 0 {
			_sqlite3IdListDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 40)))
		} else {
			if *(*uintptr)(unsafe.Pointer(pItem + 40)) != 0 {
				_sqlite3ExprDelete(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 40)))
			}
		}
		goto _1
	_1:
		;
		i = i + 1
		pItem += 48
	}
	_sqlite3DbNNFreeNN(tls, db, pList)
}

// C documentation
//
//	/*
//	** Add the list of function arguments to the SrcList entry for a
//	** table-valued-function.
//	*/
func _sqlite3SrcListFuncArgs(tls *libc.TLS, pParse uintptr, p uintptr, pList uintptr) {
	var pItem uintptr
	_ = pItem
	if p != 0 {
		pItem = p + 8 + uintptr((*TSrcList)(unsafe.Pointer(p)).FnSrc-int32(1))*48
		*(*uintptr)(unsafe.Pointer(pItem + 32)) = pList
		libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(1), 3, 0x8)
	} else {
		_sqlite3ExprListDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pList)
	}
}

// C documentation
//
//	/*
//	** Add an INDEXED BY or NOT INDEXED clause to the most recently added
//	** element of the source-list passed as the second argument.
//	*/
func _sqlite3SrcListIndexedBy(tls *libc.TLS, pParse uintptr, p uintptr, pIndexedBy uintptr) {
	var pItem uintptr
	_ = pItem
	if p != 0 && (*TToken)(unsafe.Pointer(pIndexedBy)).Fn > uint32(0) {
		pItem = p + 8 + uintptr((*TSrcList)(unsafe.Pointer(p)).FnSrc-int32(1))*48
		if (*TToken)(unsafe.Pointer(pIndexedBy)).Fn == uint32(1) && !((*TToken)(unsafe.Pointer(pIndexedBy)).Fz != 0) {
			/* A "NOT INDEXED" clause was supplied. See parse.y
			 ** construct "indexed_opt" for details. */
			libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(1), 0, 0x1)
		} else {
			*(*uintptr)(unsafe.Pointer(pItem + 32)) = _sqlite3NameFromToken(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pIndexedBy)
			libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(1), 1, 0x2)
			/* No collision on union u2 */
		}
	}
}

// C documentation
//
//	/*
//	** While a SrcList can in general represent multiple tables and subqueries
//	** (as in the FROM clause of a SELECT statement) in this case it contains
//	** the name of a single table, as one might find in an INSERT, DELETE,
//	** or UPDATE statement.  Look up that table in the symbol table and
//	** return a pointer.  Set an error message and return NULL if the table
//	** name is not found or if any other error occurs.
//	**
//	** The following fields are initialized appropriate in pSrc:
//	**
//	**    pSrc->a[0].spTab        Pointer to the Table object
//	**    pSrc->a[0].u2.pIBIndex  Pointer to the INDEXED BY index, if there is one
//	**
//	*/
func _sqlite3SrcListLookup(tls *libc.TLS, pParse uintptr, pSrc uintptr) (r uintptr) {
	var pItem, pTab uintptr
	_, _ = pItem, pTab
	pItem = pSrc + 8
	pTab = _sqlite3LocateTableItem(tls, pParse, uint32(0), pItem)
	if (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab != 0 {
		_sqlite3DeleteTable(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, (*TSrcItem)(unsafe.Pointer(pItem)).FpSTab)
	}
	(*TSrcItem)(unsafe.Pointer(pItem)).FpSTab = pTab
	libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(1), 10, 0x400)
	if pTab != 0 {
		(*TTable)(unsafe.Pointer(pTab)).FnTabRef = (*TTable)(unsafe.Pointer(pTab)).FnTabRef + 1
		if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x2>>1) != 0 && _sqlite3IndexedByLookup(tls, pParse, pItem) != 0 {
			pTab = uintptr(0)
		}
	}
	return pTab
}

// C documentation
//
//	/*
//	** Remove a Subquery from a SrcItem.  Return the associated Select object.
//	** The returned Select becomes the responsibility of the caller.
//	*/
func _sqlite3SubqueryDetach(tls *libc.TLS, db uintptr, pItem uintptr) (r uintptr) {
	var pSel uintptr
	_ = pSel
	pSel = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect
	_sqlite3DbFree(tls, db, *(*uintptr)(unsafe.Pointer(pItem + 44)))
	*(*uintptr)(unsafe.Pointer(pItem + 44)) = uintptr(0)
	libc.SetBitFieldPtr32Uint32(pItem+12+4, libc.Uint32FromInt32(0), 2, 0x4)
	return pSel
}

func _sqlite3TableLock(tls *libc.TLS, pParse uintptr, iDb int32, iTab TPgno, isWriteLock Tu8, zName uintptr) {
	if iDb == int32(1) {
		return
	}
	if !(_sqlite3BtreeSharable(tls, (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer((*TParse)(unsafe.Pointer(pParse)).Fdb)).FaDb + uintptr(iDb)*16))).FpBt) != 0) {
		return
	}
	_lockTable(tls, pParse, iDb, iTab, isWriteLock, zName)
}

// C documentation
//
//	/*
//	** Transfer all bindings from the first statement over to the second.
//	*/
func _sqlite3TransferBindings(tls *libc.TLS, pFromStmt uintptr, pToStmt uintptr) (r int32) {
	var i int32
	var pFrom, pTo uintptr
	_, _, _ = i, pFrom, pTo
	pFrom = pFromStmt
	pTo = pToStmt
	Xsqlite3_mutex_enter(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(pTo)).Fdb)).Fmutex)
	i = 0
	for {
		if !(i < int32((*TVdbe)(unsafe.Pointer(pFrom)).FnVar)) {
			break
		}
		_sqlite3VdbeMemMove(tls, (*TVdbe)(unsafe.Pointer(pTo)).FaVar+uintptr(i)*40, (*TVdbe)(unsafe.Pointer(pFrom)).FaVar+uintptr(i)*40)
		goto _1
	_1:
		;
		i = i + 1
	}
	Xsqlite3_mutex_leave(tls, (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(pTo)).Fdb)).Fmutex)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Turn a SELECT statement (that the pSelect parameter points to) into
//	** a trigger step.  Return a pointer to a TriggerStep structure.
//	**
//	** The parser calls this routine when it finds a SELECT statement in
//	** body of a TRIGGER.
//	*/
func _sqlite3TriggerSelectStep(tls *libc.TLS, db uintptr, pSelect uintptr, zStart uintptr, zEnd uintptr) (r uintptr) {
	var pTriggerStep uintptr
	_ = pTriggerStep
	pTriggerStep = _sqlite3DbMallocZero(tls, db, uint64(44))
	if pTriggerStep == uintptr(0) {
		_sqlite3SelectDelete(tls, db, pSelect)
		return uintptr(0)
	}
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Fop = uint8(TK_SELECT)
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FpSelect = pSelect
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).Forconf = uint8(OE_Default)
	(*TTriggerStep)(unsafe.Pointer(pTriggerStep)).FzSpan = _triggerSpanDup(tls, db, zStart, zEnd)
	return pTriggerStep
}

func _sqlite3TriggersExist(tls *libc.TLS, pParse uintptr, pTab uintptr, op int32, pChanges uintptr, pMask uintptr) (r uintptr) {
	if (*TTable)(unsafe.Pointer(pTab)).FpTrigger == uintptr(0) && !(_tempTriggersExist(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb) != 0) || int32(Tbft(*(*uint16)(unsafe.Pointer(pParse + 28))&0x1>>0)) != 0 {
		if pMask != 0 {
			**(**int32)(__ccgo_up(pMask)) = 0
		}
		return uintptr(0)
	}
	return _triggersReallyExist(tls, pParse, pTab, op, pChanges, pMask)
}

// C documentation
//
//	/*
//	** For the index called zIdxName which is found in the database iDb,
//	** unlike that index from its Table then remove the index from
//	** the index hash table and free all memory structures associated
//	** with the index.
//	*/
func _sqlite3UnlinkAndDeleteIndex(tls *libc.TLS, db uintptr, iDb int32, zIdxName uintptr) {
	var p, pHash, pIndex uintptr
	_, _, _ = p, pHash, pIndex
	pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 24
	pIndex = _sqlite3HashInsert(tls, pHash, zIdxName, uintptr(0))
	if pIndex != 0 {
		if (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpIndex == pIndex {
			(*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpIndex = (*TIndex)(unsafe.Pointer(pIndex)).FpNext
		} else {
			/* Justification of ALWAYS();  The index must be on the list of
			 ** indices. */
			p = (*TTable)(unsafe.Pointer((*TIndex)(unsafe.Pointer(pIndex)).FpTable)).FpIndex
			for p != 0 && (*TIndex)(unsafe.Pointer(p)).FpNext != pIndex {
				p = (*TIndex)(unsafe.Pointer(p)).FpNext
			}
			if p != 0 && (*TIndex)(unsafe.Pointer(p)).FpNext == pIndex {
				(*TIndex)(unsafe.Pointer(p)).FpNext = (*TIndex)(unsafe.Pointer(pIndex)).FpNext
			}
		}
		_sqlite3FreeIndex(tls, db, pIndex)
	}
	**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
}

// C documentation
//
//	/*
//	** Unlink the given table from the hash tables and the delete the
//	** table structure with all its indices and foreign keys.
//	*/
func _sqlite3UnlinkAndDeleteTable(tls *libc.TLS, db uintptr, iDb int32, zTabName uintptr) {
	var p, pDb uintptr
	_, _ = p, pDb
	/* Zero-length table names are allowed */
	pDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16
	p = _sqlite3HashInsert(tls, (*TDb)(unsafe.Pointer(pDb)).FpSchema+8, zTabName, uintptr(0))
	_sqlite3DeleteTable(tls, db, p)
	**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
}

// C documentation
//
//	/*
//	** Remove a trigger from the hash tables of the sqlite* pointer.
//	*/
func _sqlite3UnlinkAndDeleteTrigger(tls *libc.TLS, db uintptr, iDb int32, zName uintptr) {
	var pHash, pTab, pTrigger, pp uintptr
	_, _, _, _ = pHash, pTab, pTrigger, pp
	pHash = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(iDb)*16))).FpSchema + 40
	pTrigger = _sqlite3HashInsert(tls, pHash, zName, uintptr(0))
	if pTrigger != 0 {
		if (*TTrigger)(unsafe.Pointer(pTrigger)).FpSchema == (*TTrigger)(unsafe.Pointer(pTrigger)).FpTabSchema {
			pTab = _tableOfTrigger(tls, pTrigger)
			if pTab != 0 {
				pp = pTab + 56
				for {
					if !(**(**uintptr)(__ccgo_up(pp)) != 0) {
						break
					}
					if **(**uintptr)(__ccgo_up(pp)) == pTrigger {
						**(**uintptr)(__ccgo_up(pp)) = (*TTrigger)(unsafe.Pointer(**(**uintptr)(__ccgo_up(pp)))).FpNext
						break
					}
					goto _1
				_1:
					;
					pp = **(**uintptr)(__ccgo_up(pp)) + 32
				}
			}
		}
		_sqlite3DeleteTrigger(tls, db, pTrigger)
		**(**Tu32)(__ccgo_up(db + 24)) |= uint32(DBFLAG_SchemaChange)
	}
}

// C documentation
//
//	/*
//	** Create a new Upsert object.
//	*/
func _sqlite3UpsertNew(tls *libc.TLS, db uintptr, pTarget uintptr, pTargetWhere uintptr, pSet uintptr, pWhere uintptr, pNext uintptr) (r uintptr) {
	var pNew uintptr
	_ = pNew
	pNew = _sqlite3DbMallocZero(tls, db, uint64(48))
	if pNew == uintptr(0) {
		_sqlite3ExprListDelete(tls, db, pTarget)
		_sqlite3ExprDelete(tls, db, pTargetWhere)
		_sqlite3ExprListDelete(tls, db, pSet)
		_sqlite3ExprDelete(tls, db, pWhere)
		_sqlite3UpsertDelete(tls, db, pNext)
		return uintptr(0)
	} else {
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertTarget = pTarget
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertTargetWhere = pTargetWhere
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertSet = pSet
		(*TUpsert)(unsafe.Pointer(pNew)).FpUpsertWhere = pWhere
		(*TUpsert)(unsafe.Pointer(pNew)).FisDoUpdate = libc.BoolUint8(pSet != uintptr(0))
		(*TUpsert)(unsafe.Pointer(pNew)).FpNextUpsert = pNext
	}
	return pNew
}

// C documentation
//
//	/*
//	** Convert a UTF-16 string in the native encoding into a UTF-8 string.
//	** Memory to hold the UTF-8 string is obtained from sqlite3_malloc and must
//	** be freed by the calling function.
//	**
//	** NULL is returned if there is an allocation error.
//	*/
func _sqlite3Utf16to8(tls *libc.TLS, db uintptr, z uintptr, nByte int32, enc Tu8) (r uintptr) {
	bp := tls.Alloc(48)
	defer tls.Free(48)
	var _ /* m at bp+0 */ TMem
	libc.Xmemset(tls, bp, 0, uint32(40))
	(**(**TMem)(__ccgo_up(bp))).Fdb = db
	_sqlite3VdbeMemSetStr(tls, bp, z, int64(nByte), enc, libc.UintptrFromInt32(0))
	_sqlite3VdbeChangeEncoding(tls, bp, int32(SQLITE_UTF8))
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		_sqlite3VdbeMemRelease(tls, bp)
		(**(**TMem)(__ccgo_up(bp))).Fz = uintptr(0)
	}
	return (**(**TMem)(__ccgo_up(bp))).Fz
}

// C documentation
//
//	/*
//	** The VACUUM command is used to clean up the database,
//	** collapse free space, etc.  It is modelled after the VACUUM command
//	** in PostgreSQL.  The VACUUM command works as follows:
//	**
//	**   (1)  Create a new transient database file
//	**   (2)  Copy all content from the database being vacuumed into
//	**        the new transient database file
//	**   (3)  Copy content from the transient database back into the
//	**        original database.
//	**
//	** The transient database requires temporary disk space approximately
//	** equal to the size of the original database.  The copy operation of
//	** step (3) requires additional temporary disk space approximately equal
//	** to the size of the original database for the rollback journal.
//	** Hence, temporary disk space that is approximately 2x the size of the
//	** original database is required.  Every page of the database is written
//	** approximately 3 times:  Once for step (2) and twice for step (3).
//	** Two writes per page are required in step (3) because the original
//	** database content must be written into the rollback journal prior to
//	** overwriting the database with the vacuumed content.
//	**
//	** Only 1x temporary space and only 1x writes would be required if
//	** the copy of step (3) were replaced by deleting the original database
//	** and renaming the transient database as the original.  But that will
//	** not work if other processes are attached to the original database.
//	** And a power loss in between deleting the original and renaming the
//	** transient would cause the database file to appear to be deleted
//	** following reboot.
//	*/
func _sqlite3Vacuum(tls *libc.TLS, pParse uintptr, _pNm uintptr, pInto uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _pNm
	var iDb, iIntoReg, v1 int32
	var v, v2 uintptr
	_, _, _, _, _ = iDb, iIntoReg, v, v1, v2
	v = _sqlite3GetVdbe(tls, pParse)
	iDb = 0
	if v == uintptr(0) {
		goto build_vacuum_end
	}
	if (*TParse)(unsafe.Pointer(pParse)).FnErr != 0 {
		goto build_vacuum_end
	}
	if **(**uintptr)(__ccgo_up(bp)) != 0 {
		/* Default behavior:  Report an error if the argument to VACUUM is
		 ** not recognized */
		iDb = _sqlite3TwoPartName(tls, pParse, **(**uintptr)(__ccgo_up(bp)), **(**uintptr)(__ccgo_up(bp)), bp)
		if iDb < 0 {
			goto build_vacuum_end
		}
	}
	if iDb != int32(1) {
		iIntoReg = 0
		if pInto != 0 && _sqlite3ResolveSelfReference(tls, pParse, uintptr(0), 0, pInto, uintptr(0)) == 0 {
			v2 = pParse + 48
			*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) + 1
			v1 = *(*int32)(unsafe.Pointer(v2))
			iIntoReg = v1
			_sqlite3ExprCode(tls, pParse, pInto, iIntoReg)
		}
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Vacuum), iDb, iIntoReg)
		_sqlite3VdbeUsesBtree(tls, v, iDb)
	}
	goto build_vacuum_end
build_vacuum_end:
	;
	_sqlite3ExprDelete(tls, (*TParse)(unsafe.Pointer(pParse)).Fdb, pInto)
	return
}

// C documentation
//
//	/*
//	** Create a new sqlite3_value object.
//	*/
func _sqlite3ValueNew(tls *libc.TLS, db uintptr) (r uintptr) {
	var p uintptr
	_ = p
	p = _sqlite3DbMallocZero(tls, db, uint64(40))
	if p != 0 {
		(*TMem)(unsafe.Pointer(p)).Fflags = uint16(MEM_Null)
		(*TMem)(unsafe.Pointer(p)).Fdb = db
	}
	return p
}

// C documentation
//
//	/*
//	** Add an opcode that includes the p4 value with a P4_INT64 or
//	** P4_REAL type.
//	*/
func _sqlite3VdbeAddOp4Dup8(tls *libc.TLS, p uintptr, op int32, p1 int32, p2 int32, p3 int32, zP4 uintptr, p4type int32) (r int32) {
	var p4copy uintptr
	_ = p4copy
	p4copy = _sqlite3DbMallocRawNN(tls, _sqlite3VdbeDb(tls, p), uint64(8))
	if p4copy != 0 {
		libc.Xmemcpy(tls, p4copy, zP4, uint32(8))
	}
	return _sqlite3VdbeAddOp4(tls, p, op, p1, p2, p3, p4copy, p4type)
}

// C documentation
//
//	/*
//	** Change the P4 operand of the most recently coded instruction
//	** to the value defined by the arguments.  This is a high-speed
//	** version of sqlite3VdbeChangeP4().
//	**
//	** The P4 operand must not have been previously defined.  And the new
//	** P4 must not be P4_INT32.  Use sqlite3VdbeChangeP4() in either of
//	** those cases.
//	*/
func _sqlite3VdbeAppendP4(tls *libc.TLS, p uintptr, pP4 uintptr, n int32) {
	var pOp uintptr
	_ = pOp
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		_freeP4(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, n, pP4)
	} else {
		pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))*20
		(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = int8(n)
		*(*uintptr)(unsafe.Pointer(pOp + 16)) = pP4
	}
}

func _sqlite3VdbeChangeP4(tls *libc.TLS, p uintptr, addr int32, _zP4 uintptr, n int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*uintptr)(unsafe.Pointer(bp)) = _zP4
	var db, pOp uintptr
	_, _ = db, pOp
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	if (*Tsqlite3)(unsafe.Pointer(db)).FmallocFailed != 0 {
		if n != -int32(12) {
			_freeP4(tls, db, n, **(**uintptr)(__ccgo_up(bp)))
		}
		return
	}
	if addr < 0 {
		addr = (*TVdbe)(unsafe.Pointer(p)).FnOp - int32(1)
	}
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*20
	if n >= 0 || (*TOp)(unsafe.Pointer(pOp)).Fp4type != 0 {
		_vdbeChangeP4Full(tls, p, pOp, **(**uintptr)(__ccgo_up(bp)), n)
		return
	}
	if n == -int32(3) {
		/* Note: this cast is safe, because the origin data point was an int
		 ** that was cast to a (const char *). */
		*(*int32)(unsafe.Pointer(pOp + 16)) = int32(**(**uintptr)(__ccgo_up(bp)))
		(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(-libc.Int32FromInt32(3))
	} else {
		if **(**uintptr)(__ccgo_up(bp)) != uintptr(0) {
			*(*uintptr)(unsafe.Pointer(pOp + 16)) = **(**uintptr)(__ccgo_up(bp))
			(*TOp)(unsafe.Pointer(pOp)).Fp4type = int8(n)
			if n == -int32(12) {
				_sqlite3VtabLock(tls, **(**uintptr)(__ccgo_up(bp)))
			}
		}
	}
}

func _sqlite3VdbeChangeP5(tls *libc.TLS, p uintptr, p5 Tu16) {
	if (*TVdbe)(unsafe.Pointer(p)).FnOp > 0 {
		(**(**TOp)(__ccgo_up((*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr((*TVdbe)(unsafe.Pointer(p)).FnOp-int32(1))*20))).Fp5 = p5
	}
}

// C documentation
//
//	/*
//	** Change the opcode at addr into OP_Noop
//	*/
func _sqlite3VdbeChangeToNoop(tls *libc.TLS, p uintptr, addr int32) (r int32) {
	var pOp uintptr
	_ = pOp
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return 0
	}
	pOp = (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*20
	_freeP4(tls, (*TVdbe)(unsafe.Pointer(p)).Fdb, int32((*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type), *(*uintptr)(unsafe.Pointer(pOp + 16)))
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fp4type = P4_NOTUSED
	*(*uintptr)(unsafe.Pointer(pOp + 16)) = uintptr(0)
	(*TVdbeOp)(unsafe.Pointer(pOp)).Fopcode = uint8(OP_Noop)
	return int32(1)
}

// C documentation
//
//	/*
//	** Check to ensure that the cursor is valid.  Restore the cursor
//	** if need be.  Return any I/O error from the restore operation.
//	*/
func _sqlite3VdbeCursorRestore(tls *libc.TLS, p uintptr) (r int32) {
	if _sqlite3BtreeCursorHasMoved(tls, *(*uintptr)(unsafe.Pointer(p + 36))) != 0 {
		return _sqlite3VdbeHandleMovedCursor(tls, p)
	}
	return SQLITE_OK
}

/*
** The following functions:
**
** sqlite3VdbeSerialType()
** sqlite3VdbeSerialTypeLen()
** sqlite3VdbeSerialLen()
** sqlite3VdbeSerialPut()  <--- in-lined into OP_MakeRecord as of 2022-04-02
** sqlite3VdbeSerialGet()
**
** encapsulate the code that serializes values for storage in SQLite
** data and index records. Each serialized value consists of a
** 'serial-type' and a blob of data. The serial type is an 8-byte unsigned
** integer, stored as a varint.
**
** In an SQLite index record, the serial type is stored directly before
** the blob of data that it corresponds to. In a table record, all serial
** types are stored at the start of the record, and the blobs of data at
** the end. Hence these functions allow the caller to handle the
** serial-type and data blob separately.
**
** The following table describes the various storage classes for data:
**
**   serial type        bytes of data      type
**   --------------     ---------------    ---------------
**      0                     0            NULL
**      1                     1            signed integer
**      2                     2            signed integer
**      3                     3            signed integer
**      4                     4            signed integer
**      5                     6            signed integer
**      6                     8            signed integer
**      7                     8            IEEE float
**      8                     0            Integer constant 0
**      9                     0            Integer constant 1
**     10,11                               reserved for expansion
**    N>=12 and even       (N-12)/2        BLOB
**    N>=13 and odd        (N-13)/2        text
**
** The 8 and 9 types were added in 3.3.0, file format 4.  Prior versions
** of SQLite will not understand those serial types.
 */

// C documentation
//
//	/*
//	** If SQLite is compiled to support shared-cache mode and to be threadsafe,
//	** this routine obtains the mutex associated with each BtShared structure
//	** that may be accessed by the VM passed as an argument. In doing so it also
//	** sets the BtShared.db member of each of the BtShared structures, ensuring
//	** that the correct busy-handler callback is invoked if required.
//	**
//	** If SQLite is not threadsafe but does support shared-cache mode, then
//	** sqlite3BtreeEnter() is invoked to set the BtShared.db variables
//	** of all of BtShared structures accessible via the database handle
//	** associated with the VM.
//	**
//	** If SQLite is not threadsafe and does not support shared-cache mode, this
//	** function is a no-op.
//	**
//	** The p->btreeMask field is a bitmask of all btrees that the prepared
//	** statement p will ever use.  Let N be the number of bits in p->btreeMask
//	** corresponding to btrees that use shared cache.  Then the runtime of
//	** this routine is N*N.  But as N is rarely more than 1, this should not
//	** be a problem.
//	*/
func _sqlite3VdbeEnter(tls *libc.TLS, p uintptr) {
	var aDb, db uintptr
	var i, nDb int32
	_, _, _, _ = aDb, db, i, nDb
	if (*TVdbe)(unsafe.Pointer(p)).FlockMask == uint32(0) {
		return
	} /* The common case */
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	aDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
	nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
	i = 0
	for {
		if !(i < nDb) {
			break
		}
		if i != int32(1) && (*TVdbe)(unsafe.Pointer(p)).FlockMask&(libc.Uint32FromInt32(1)<<i) != uint32(0) && (**(**TDb)(__ccgo_up(aDb + uintptr(i)*16))).FpBt != uintptr(0) {
			_sqlite3BtreeEnter(tls, (**(**TDb)(__ccgo_up(aDb + uintptr(i)*16))).FpBt)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** The cursor "p" has a pending seek operation that has not yet been
//	** carried out.  Seek the cursor now.  If an error occurs, return
//	** the appropriate error code.
//	*/
func _sqlite3VdbeFinishMoveto(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* res at bp+0 */ int32
	_ = rc
	rc = _sqlite3BtreeTableMoveto(tls, *(*uintptr)(unsafe.Pointer(p + 36)), (*TVdbeCursor)(unsafe.Pointer(p)).FmovetoTarget, 0, bp)
	if rc != 0 {
		return rc
	}
	if **(**int32)(__ccgo_up(bp)) != 0 {
		return _sqlite3CorruptError(tls, int32(91561))
	}
	(*TVdbeCursor)(unsafe.Pointer(p)).FdeferredMoveto = uint8(0)
	(*TVdbeCursor)(unsafe.Pointer(p)).FcacheStatus = uint32(CACHE_STALE)
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Return the opcode for a given address.  The address must be non-negative.
//	** See sqlite3VdbeGetLastOp() to get the most recently added opcode.
//	**
//	** If a memory allocation error has occurred prior to the calling of this
//	** routine, then a pointer to a dummy VdbeOp will be returned.  That opcode
//	** is readable but not writable, though it is cast to a writable value.
//	** The return of a dummy opcode allows the call to continue functioning
//	** after an OOM fault without having to check to see if the return from
//	** this routine is a valid pointer.  But because the dummy.opcode is 0,
//	** dummy will never be written to.  This is verified by code inspection and
//	** by running with Valgrind.
//	*/
func _sqlite3VdbeGetOp(tls *libc.TLS, p uintptr, addr int32) (r uintptr) {
	if (*Tsqlite3)(unsafe.Pointer((*TVdbe)(unsafe.Pointer(p)).Fdb)).FmallocFailed != 0 {
		return uintptr(unsafe.Pointer(&_dummy))
	} else {
		return (*TVdbe)(unsafe.Pointer(p)).FaOp + uintptr(addr)*20
	}
	return r
}

// C documentation
//
//	/*
//	** Something has moved cursor "p" out of place.  Maybe the row it was
//	** pointed to was deleted out from under it.  Or maybe the btree was
//	** rebalanced.  Whatever the cause, try to restore "p" to the place it
//	** is supposed to be pointing.  If the row was deleted out from under the
//	** cursor, set the cursor to point to a NULL row.
//	*/
func _sqlite3VdbeHandleMovedCursor(tls *libc.TLS, p uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* isDifferentRow at bp+0 */ int32
	_ = rc
	rc = _sqlite3BtreeCursorRestore(tls, *(*uintptr)(unsafe.Pointer(p + 36)), bp)
	(*TVdbeCursor)(unsafe.Pointer(p)).FcacheStatus = uint32(CACHE_STALE)
	if **(**int32)(__ccgo_up(bp)) != 0 {
		(*TVdbeCursor)(unsafe.Pointer(p)).FnullRow = uint8(1)
	}
	return rc
}

// C documentation
//
//	/*
//	** Create a new symbolic label for an instruction that has yet to be
//	** coded.  The symbolic label is really just a negative number.  The
//	** label can be used as the P2 value of an operation.  Later, when
//	** the label is resolved to a specific address, the VDBE will scan
//	** through its operation list and change all values of P2 which match
//	** the label into the resolved address.
//	**
//	** The VDBE knows that a P2 value is a label because labels are
//	** always negative and P2 values are suppose to be non-negative.
//	** Hence, a negative P2 value is a label that has yet to be resolved.
//	** (Later:) This is only true for opcodes that have the OPFLG_JUMP
//	** property.
//	**
//	** Variable usage notes:
//	**
//	**     Parse.aLabel[x]     Stores the address that the x-th label resolves
//	**                         into.  For testing (SQLITE_DEBUG), unresolved
//	**                         labels stores -1, but that is not required.
//	**     Parse.nLabelAlloc   Number of slots allocated to Parse.aLabel[]
//	**     Parse.nLabel        The *negative* of the number of labels that have
//	**                         been issued.  The negative is stored because
//	**                         that gives a performance improvement over storing
//	**                         the equivalent positive value.
//	*/
func _sqlite3VdbeMakeLabel(tls *libc.TLS, pParse uintptr) (r int32) {
	var v1 int32
	var v2 uintptr
	_, _ = v1, v2
	v2 = pParse + 60
	*(*int32)(unsafe.Pointer(v2)) = *(*int32)(unsafe.Pointer(v2)) - 1
	v1 = *(*int32)(unsafe.Pointer(v2))
	return v1
}

// C documentation
//
//	/*
//	** Memory cell pAccum contains the context of an aggregate function.
//	** This routine calls the xValue method for that function and stores
//	** the results in memory cell pMem.
//	**
//	** SQLITE_ERROR is returned if xValue() reports an error. SQLITE_OK
//	** otherwise.
//	*/
func _sqlite3VdbeMemAggValue(tls *libc.TLS, pAccum uintptr, pOut uintptr, pFunc uintptr) (r int32) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* ctx at bp+0 */ Tsqlite3_context
	libc.Xmemset(tls, bp, 0, uint32(28))
	_sqlite3VdbeMemSetNull(tls, pOut)
	(**(**Tsqlite3_context)(__ccgo_up(bp))).FpOut = pOut
	(**(**Tsqlite3_context)(__ccgo_up(bp))).FpMem = pAccum
	(**(**Tsqlite3_context)(__ccgo_up(bp))).FpFunc = pFunc
	(**(**Tsqlite3_context)(__ccgo_up(bp))).Fenc = (*Tsqlite3)(unsafe.Pointer((*TMem)(unsafe.Pointer(pAccum)).Fdb)).Fenc
	(*(*func(*libc.TLS, uintptr))(unsafe.Pointer(&struct{ uintptr }{(*TFuncDef)(unsafe.Pointer(pFunc)).FxValue})))(tls, bp)
	return (**(**Tsqlite3_context)(__ccgo_up(bp))).FisError
}

// C documentation
//
//	/*
//	** Change the pMem->zMalloc allocation to be at least szNew bytes.
//	** If pMem->zMalloc already meets or exceeds the requested size, this
//	** routine is a no-op.
//	**
//	** Any prior string or blob content in the pMem object may be discarded.
//	** The pMem->xDel destructor is called, if it exists.  Though MEM_Str
//	** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, MEM_IntReal,
//	** and MEM_Null values are preserved.
//	**
//	** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
//	** if unable to complete the resizing.
//	*/
func _sqlite3VdbeMemClearAndResize(tls *libc.TLS, pMem uintptr, szNew int32) (r int32) {
	var v1 uintptr
	_ = v1
	if (*TMem)(unsafe.Pointer(pMem)).FszMalloc < szNew {
		return _sqlite3VdbeMemGrow(tls, pMem, szNew, 0)
	}
	(*TMem)(unsafe.Pointer(pMem)).Fz = (*TMem)(unsafe.Pointer(pMem)).FzMalloc
	v1 = pMem + 16
	*(*Tu16)(unsafe.Pointer(v1)) = Tu16(int32(*(*Tu16)(unsafe.Pointer(v1))) & (libc.Int32FromInt32(MEM_Null) | libc.Int32FromInt32(MEM_Int) | libc.Int32FromInt32(MEM_Real) | libc.Int32FromInt32(MEM_IntReal)))
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Transfer the contents of pFrom to pTo. Any existing value in pTo is
//	** freed. If pFrom contains ephemeral data, a copy is made.
//	**
//	** pFrom contains an SQL NULL when this routine returns.
//	*/
func _sqlite3VdbeMemMove(tls *libc.TLS, pTo uintptr, pFrom uintptr) {
	_sqlite3VdbeMemRelease(tls, pTo)
	libc.Xmemcpy(tls, pTo, pFrom, uint32(40))
	(*TMem)(unsafe.Pointer(pFrom)).Fflags = uint16(MEM_Null)
	(*TMem)(unsafe.Pointer(pFrom)).FszMalloc = 0
}

// C documentation
//
//	/*
//	** Advance to the next element in the sorter.  Return value:
//	**
//	**    SQLITE_OK     success
//	**    SQLITE_DONE   end of data
//	**    otherwise     some kind of error.
//	*/
func _sqlite3VdbeSorterNext(tls *libc.TLS, db uintptr, pCsr uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pFree, pSorter uintptr
	var rc, v1 int32
	var _ /* res at bp+0 */ int32
	_, _, _, _ = pFree, pSorter, rc, v1 /* Return code */
	pSorter = *(*uintptr)(unsafe.Pointer(pCsr + 36))
	if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUsePMA != 0 {
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).FbUseThreads != 0 {
			rc = _vdbePmaReaderNext(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader)
			if rc == SQLITE_OK && (*TPmaReader)(unsafe.Pointer((*TVdbeSorter)(unsafe.Pointer(pSorter)).FpReader)).FpFd == uintptr(0) {
				rc = int32(SQLITE_DONE)
			}
		} else {
			/*if( !pSorter->bUseThreads )*/
			**(**int32)(__ccgo_up(bp)) = 0
			rc = _vdbeMergeEngineStep(tls, (*TVdbeSorter)(unsafe.Pointer(pSorter)).FpMerger, bp)
			if rc == SQLITE_OK && **(**int32)(__ccgo_up(bp)) != 0 {
				rc = int32(SQLITE_DONE)
			}
		}
	} else {
		pFree = (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList
		(*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList = *(*uintptr)(unsafe.Pointer(pFree + 4))
		*(*uintptr)(unsafe.Pointer(pFree + 4)) = uintptr(0)
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FaMemory == uintptr(0) {
			_vdbeSorterRecordFree(tls, db, pFree)
		}
		if (*TVdbeSorter)(unsafe.Pointer(pSorter)).Flist.FpList != 0 {
			v1 = SQLITE_OK
		} else {
			v1 = int32(SQLITE_DONE)
		}
		rc = v1
	}
	return rc
}

// C documentation
//
//	/*
//	** If the virtual table pVtab supports the transaction interface
//	** (xBegin/xRollback/xCommit and optionally xSync) and a transaction is
//	** not currently open, invoke the xBegin method now.
//	**
//	** If the xBegin call is successful, place the sqlite3_vtab pointer
//	** in the sqlite3.aVTrans array.
//	*/
func _sqlite3VtabBegin(tls *libc.TLS, db uintptr, pVTab uintptr) (r int32) {
	var i, iSvpt, rc int32
	var pModule uintptr
	_, _, _, _ = i, iSvpt, pModule, rc
	rc = SQLITE_OK
	/* Special case: If db->aVTrans is NULL and db->nVTrans is greater
	 ** than zero, then this function is being called from within a
	 ** virtual module xSync() callback. It is illegal to write to
	 ** virtual module tables in this case, so return SQLITE_LOCKED.
	 */
	if (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans > 0 && (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans == uintptr(0) {
		return int32(SQLITE_LOCKED)
	}
	if !(pVTab != 0) {
		return SQLITE_OK
	}
	pModule = (*Tsqlite3_vtab)(unsafe.Pointer((*TVTable)(unsafe.Pointer(pVTab)).FpVtab)).FpModule
	if (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxBegin != 0 {
		/* If pVtab is already in the aVTrans array, return early */
		i = 0
		for {
			if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) {
				break
			}
			if **(**uintptr)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaVTrans + uintptr(i)*4)) == pVTab {
				return SQLITE_OK
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		/* Invoke the xBegin method. If successful, add the vtab to the
		 ** sqlite3.aVTrans[] array. */
		rc = _growVTrans(tls, db)
		if rc == SQLITE_OK {
			rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxBegin})))(tls, (*TVTable)(unsafe.Pointer(pVTab)).FpVtab)
			if rc == SQLITE_OK {
				iSvpt = (*Tsqlite3)(unsafe.Pointer(db)).FnStatement + (*Tsqlite3)(unsafe.Pointer(db)).FnSavepoint
				_addToVTrans(tls, db, pVTab)
				if iSvpt != 0 && (*Tsqlite3_module)(unsafe.Pointer(pModule)).FxSavepoint != 0 {
					(*TVTable)(unsafe.Pointer(pVTab)).FiSavepoint = iSvpt
					rc = (*(*func(*libc.TLS, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*Tsqlite3_module)(unsafe.Pointer(pModule)).FxSavepoint})))(tls, (*TVTable)(unsafe.Pointer(pVTab)).FpVtab, iSvpt-int32(1))
				}
			}
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Clear any and all virtual-table information from the Table record.
//	** This routine is called, for example, just before deleting the Table
//	** record.
//	**
//	** Since it is a virtual-table, the Table structure contains a pointer
//	** to the head of a linked list of VTable structures. Each VTable
//	** structure is associated with a single sqlite3* user of the schema.
//	** The reference count of the VTable structure associated with database
//	** connection db is decremented immediately (which may lead to the
//	** structure being xDisconnected and free). Any other VTable structures
//	** in the list are moved to the sqlite3.pDisconnect list of the associated
//	** database connection.
//	*/
func _sqlite3VtabClear(tls *libc.TLS, db uintptr, p uintptr) {
	var i int32
	_ = i
	if (*Tsqlite3)(unsafe.Pointer(db)).FpnBytesFreed == uintptr(0) {
		_vtabDisconnectAll(tls, uintptr(0), p)
	}
	if (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(p + 44))).FazArg != 0 {
		i = 0
		for {
			if !(i < (*(*struct {
				FnArg  int32
				FazArg uintptr
				Fp     uintptr
			})(unsafe.Pointer(p + 44))).FnArg) {
				break
			}
			if i != int32(1) {
				_sqlite3DbFree(tls, db, **(**uintptr)(__ccgo_up((*(*struct {
					FnArg  int32
					FazArg uintptr
					Fp     uintptr
				})(unsafe.Pointer(p + 44))).FazArg + uintptr(i)*4)))
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		_sqlite3DbFree(tls, db, (*(*struct {
			FnArg  int32
			FazArg uintptr
			Fp     uintptr
		})(unsafe.Pointer(p + 44))).FazArg)
	}
}

// C documentation
//
//	/*
//	** Table *p is a virtual table. This function removes the VTable object
//	** for table *p associated with database connection db from the linked
//	** list in p->pVTab. It also decrements the VTable ref count. This is
//	** used when closing database connection db to free all of its VTable
//	** objects without disturbing the rest of the Schema object (which may
//	** be being used by other shared-cache connections).
//	*/
func _sqlite3VtabDisconnect(tls *libc.TLS, db uintptr, p uintptr) {
	var pVTab, ppVTab uintptr
	_, _ = pVTab, ppVTab
	ppVTab = p + 44 + 8
	for {
		if !(**(**uintptr)(__ccgo_up(ppVTab)) != 0) {
			break
		}
		if (*TVTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(ppVTab)))).Fdb == db {
			pVTab = **(**uintptr)(__ccgo_up(ppVTab))
			**(**uintptr)(__ccgo_up(ppVTab)) = (*TVTable)(unsafe.Pointer(pVTab)).FpNext
			_sqlite3VtabUnlock(tls, pVTab)
			break
		}
		goto _1
	_1:
		;
		ppVTab = **(**uintptr)(__ccgo_up(ppVTab)) + 24
	}
}

// C documentation
//
//	/*
//	** Erase the eponymous virtual table instance associated with
//	** virtual table module pMod, if it exists.
//	*/
func _sqlite3VtabEponymousTableClear(tls *libc.TLS, db uintptr, pMod uintptr) {
	var pTab uintptr
	_ = pTab
	pTab = (*TModule)(unsafe.Pointer(pMod)).FpEpoTab
	if pTab != uintptr(0) {
		/* Mark the table as Ephemeral prior to deleting it, so that the
		 ** sqlite3DeleteTable() routine will know that it is not stored in
		 ** the schema. */
		**(**Tu32)(__ccgo_up(pTab + 28)) |= uint32(TF_Ephemeral)
		_sqlite3DeleteTable(tls, db, pTab)
		(*TModule)(unsafe.Pointer(pMod)).FpEpoTab = uintptr(0)
	}
}

// C documentation
//
//	/*
//	** Invoke the xSync method of all virtual tables in the sqlite3.aVTrans
//	** array. Return the error code for the first error that occurs, or
//	** SQLITE_OK if all xSync operations are successful.
//	**
//	** If an error message is available, leave it in p->zErrMsg.
//	*/
func _sqlite3VtabSync(tls *libc.TLS, db uintptr, p uintptr) (r int32) {
	var aVTrans, pVtab, x, v2 uintptr
	var i, rc int32
	var v3 bool
	_, _, _, _, _, _, _ = aVTrans, i, pVtab, rc, x, v2, v3
	rc = SQLITE_OK
	aVTrans = (*Tsqlite3)(unsafe.Pointer(db)).FaVTrans
	(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = uintptr(0)
	i = 0
	for {
		if !(rc == SQLITE_OK && i < (*Tsqlite3)(unsafe.Pointer(db)).FnVTrans) {
			break
		}
		pVtab = (*TVTable)(unsafe.Pointer(**(**uintptr)(__ccgo_up(aVTrans + uintptr(i)*4)))).FpVtab
		if v3 = pVtab != 0; v3 {
			v2 = (*Tsqlite3_module)(unsafe.Pointer((*Tsqlite3_vtab)(unsafe.Pointer(pVtab)).FpModule)).FxSync
			x = v2
		}
		if v3 && v2 != uintptr(0) {
			rc = (*(*func(*libc.TLS, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{x})))(tls, pVtab)
			_sqlite3VtabImportErrmsg(tls, p, pVtab)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FaVTrans = aVTrans
	return rc
}

// C documentation
//
//	/*
//	** This function starts a write transaction on the WAL.
//	**
//	** A read transaction must have already been started by a prior call
//	** to sqlite3WalBeginReadTransaction().
//	**
//	** If another thread or process has written into the database since
//	** the read transaction was started, then it is not possible for this
//	** thread to write as doing so would cause a fork.  So this routine
//	** returns SQLITE_BUSY in that case and no write transaction is started.
//	**
//	** There can only be a single writer active at a time.
//	*/
func _sqlite3WalBeginWriteTransaction(tls *libc.TLS, pWal uintptr) (r int32) {
	var rc int32
	_ = rc
	/* Cannot start a write transaction without first holding a read
	 ** transaction. */
	if (*TWal)(unsafe.Pointer(pWal)).FreadOnly != 0 {
		return int32(SQLITE_READONLY)
	}
	/* Only one writer allowed at a time.  Get the write lock.  Return
	 ** SQLITE_BUSY if unable.
	 */
	rc = _walLockExclusive(tls, pWal, WAL_WRITE_LOCK, int32(1))
	if rc != 0 {
		return rc
	}
	(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(1)
	/* If another connection has written to the database file since the
	 ** time the read transaction on this connection was started, then
	 ** the write is disallowed.
	 */
	if libc.Xmemcmp(tls, pWal+52, _walIndexHdr(tls, pWal), uint32(48)) != 0 {
		rc = libc.Int32FromInt32(SQLITE_BUSY) | libc.Int32FromInt32(2)<<libc.Int32FromInt32(8)
	}
	if rc != SQLITE_OK {
		_walUnlockExclusive(tls, pWal, WAL_WRITE_LOCK, int32(1))
		(*TWal)(unsafe.Pointer(pWal)).FwriteLock = uint8(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** The sqlite3_wal_hook() callback registered by sqlite3_wal_autocheckpoint().
//	** Invoke sqlite3_wal_checkpoint if the number of frames in the log file
//	** is greater than sqlite3.pWalArg cast to an integer (the value configured by
//	** wal_autocheckpoint()).
//	*/
func _sqlite3WalDefaultHook(tls *libc.TLS, pClientData uintptr, db uintptr, zDb uintptr, nFrame int32) (r int32) {
	if nFrame >= int32(pClientData) {
		_sqlite3BeginBenignMalloc(tls)
		Xsqlite3_wal_checkpoint(tls, db, zDb)
		_sqlite3EndBenignMalloc(tls)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Argument aWalData must point to an array of WAL_SAVEPOINT_NDATA u32
//	** values. This function populates the array with values required to
//	** "rollback" the write position of the WAL handle back to the current
//	** point in the event of a savepoint rollback (via WalSavepointUndo()).
//	*/
func _sqlite3WalSavepoint(tls *libc.TLS, pWal uintptr, aWalData uintptr) {
	**(**Tu32)(__ccgo_up(aWalData)) = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
	**(**Tu32)(__ccgo_up(aWalData + 1*4)) = **(**Tu32)(__ccgo_up(pWal + 52 + 24))
	**(**Tu32)(__ccgo_up(aWalData + 2*4)) = **(**Tu32)(__ccgo_up(pWal + 52 + 24 + 1*4))
	**(**Tu32)(__ccgo_up(aWalData + 3*4)) = (*TWal)(unsafe.Pointer(pWal)).FnCkpt
}

// C documentation
//
//	/*
//	** Move the write position of the WAL back to the point identified by
//	** the values in the aWalData[] array. aWalData must point to an array
//	** of WAL_SAVEPOINT_NDATA u32 values that has been previously populated
//	** by a call to WalSavepoint().
//	*/
func _sqlite3WalSavepointUndo(tls *libc.TLS, pWal uintptr, aWalData uintptr) (r int32) {
	var rc int32
	_ = rc
	rc = SQLITE_OK
	if **(**Tu32)(__ccgo_up(aWalData + 3*4)) != (*TWal)(unsafe.Pointer(pWal)).FnCkpt {
		/* This savepoint was opened immediately after the write-transaction
		 ** was started. Right after that, the writer decided to wrap around
		 ** to the start of the log. Update the savepoint values to match.
		 */
		**(**Tu32)(__ccgo_up(aWalData)) = uint32(0)
		**(**Tu32)(__ccgo_up(aWalData + 3*4)) = (*TWal)(unsafe.Pointer(pWal)).FnCkpt
	}
	if **(**Tu32)(__ccgo_up(aWalData)) < (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
		(*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame = **(**Tu32)(__ccgo_up(aWalData))
		**(**Tu32)(__ccgo_up(pWal + 52 + 24)) = **(**Tu32)(__ccgo_up(aWalData + 1*4))
		**(**Tu32)(__ccgo_up(pWal + 52 + 24 + 1*4)) = **(**Tu32)(__ccgo_up(aWalData + 2*4))
		_walCleanupHash(tls, pWal)
		if (*TWal)(unsafe.Pointer(pWal)).FiReCksum > (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
			(*TWal)(unsafe.Pointer(pWal)).FiReCksum = uint32(0)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** The caller currently has a read transaction open on the database.
//	** This function takes a SHARED lock on the CHECKPOINTER slot and then
//	** checks if the snapshot passed as the second argument is still
//	** available. If so, SQLITE_OK is returned.
//	**
//	** If the snapshot is not available, SQLITE_ERROR is returned. Or, if
//	** the CHECKPOINTER lock cannot be obtained, SQLITE_BUSY. If any error
//	** occurs (any value other than SQLITE_OK is returned), the CHECKPOINTER
//	** lock is released before returning.
//	*/
func _sqlite3WalSnapshotCheck(tls *libc.TLS, pWal uintptr, pSnapshot uintptr) (r int32) {
	var pNew uintptr
	var rc int32
	_, _ = pNew, rc
	rc = _walLockShared(tls, pWal, int32(WAL_CKPT_LOCK))
	if rc == SQLITE_OK {
		pNew = pSnapshot
		if libc.Xmemcmp(tls, pNew+32, pWal+52+32, uint32(8)) != 0 || (*TWalIndexHdr)(unsafe.Pointer(pNew)).FmxFrame < (*TWalCkptInfo)(unsafe.Pointer(_walCkptInfo(tls, pWal))).FnBackfillAttempted {
			rc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
			_walUnlockShared(tls, pWal, int32(WAL_CKPT_LOCK))
		}
	}
	return rc
}

// C documentation
//
//	/* Create a snapshot object.  The content of a snapshot is opaque to
//	** every other subsystem, so the WAL module can put whatever it needs
//	** in the object.
//	*/
func _sqlite3WalSnapshotGet(tls *libc.TLS, pWal uintptr, ppSnapshot uintptr) (r int32) {
	var pRet uintptr
	var rc int32
	_, _ = pRet, rc
	rc = SQLITE_OK
	if libc.Xmemcmp(tls, pWal+52+24, uintptr(unsafe.Pointer(&_aZero)), uint32(16)) == 0 {
		**(**uintptr)(__ccgo_up(ppSnapshot)) = uintptr(0)
		return int32(SQLITE_ERROR)
	}
	pRet = Xsqlite3_malloc(tls, int32(48))
	if pRet == uintptr(0) {
		rc = int32(SQLITE_NOMEM)
	} else {
		libc.Xmemcpy(tls, pRet, pWal+52, uint32(48))
		**(**uintptr)(__ccgo_up(ppSnapshot)) = pRet
	}
	return rc
}

// C documentation
//
//	/*
//	** If any data has been written (but not committed) to the log file, this
//	** function moves the write-pointer back to the start of the transaction.
//	**
//	** Additionally, the callback function is invoked for each frame written
//	** to the WAL since the start of the transaction. If the callback returns
//	** other than SQLITE_OK, it is not invoked again and the error code is
//	** returned to the caller.
//	**
//	** Otherwise, if the callback function does not return an error, this
//	** function returns SQLITE_OK.
//	*/
func _sqlite3WalUndo(tls *libc.TLS, pWal uintptr, __ccgo_fp_xUndo uintptr, pUndoCtx uintptr) (r int32) {
	var iFrame, iMax TPgno
	var rc int32
	_, _, _ = iFrame, iMax, rc
	rc = SQLITE_OK
	if (*TWal)(unsafe.Pointer(pWal)).FwriteLock != 0 {
		iMax = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame
		/* Restore the clients cache of the wal-index header to the state it
		 ** was in before the client began writing to the database.
		 */
		libc.Xmemcpy(tls, pWal+52, _walIndexHdr(tls, pWal), uint32(48))
		iFrame = (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame + uint32(1)
		for {
			if !(rc == SQLITE_OK && iFrame <= iMax) {
				break
			}
			/* This call cannot fail. Unless the page for which the page number
			 ** is passed as the second argument is (a) in the cache and
			 ** (b) has an outstanding reference, then xUndo is either a no-op
			 ** (if (a) is false) or simply expels the page from the cache (if (b)
			 ** is false).
			 **
			 ** If the upper layer is doing a rollback, it is guaranteed that there
			 ** are no outstanding references to any page other than page 1. And
			 ** page 1 is never written to the log until the transaction is
			 ** committed. As a result, the call to xUndo may not fail.
			 */
			rc = (*(*func(*libc.TLS, uintptr, TPgno) int32)(unsafe.Pointer(&struct{ uintptr }{__ccgo_fp_xUndo})))(tls, pUndoCtx, _walFramePgno(tls, pWal, iFrame))
			goto _1
		_1:
			;
			iFrame = iFrame + 1
		}
		if iMax != (*TWal)(unsafe.Pointer(pWal)).Fhdr.FmxFrame {
			_walCleanupHash(tls, pWal)
		}
		(*TWal)(unsafe.Pointer(pWal)).FiReCksum = uint32(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Call sqlite3WalkExpr() for every expression in list p or until
//	** an abort request is seen.
//	*/
func _sqlite3WalkExprList(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var i int32
	var pItem uintptr
	_, _ = i, pItem
	if p != 0 {
		i = (*TExprList)(unsafe.Pointer(p)).FnExpr
		pItem = p + 8
		for {
			if !(i > 0) {
				break
			}
			if _sqlite3WalkExpr(tls, pWalker, (*TExprList_item)(unsafe.Pointer(pItem)).FpExpr) != 0 {
				return int32(WRC_Abort)
			}
			goto _1
		_1:
			;
			i = i - 1
			pItem += 20
		}
	}
	return WRC_Continue
}

// C documentation
//
//	/*
//	** Walk the parse trees associated with all subqueries in the
//	** FROM clause of SELECT statement p.  Do not invoke the select
//	** callback on p, but do invoke it on each FROM clause subquery
//	** and on any subqueries further down in the tree.  Return
//	** WRC_Abort or WRC_Continue;
//	*/
func _sqlite3WalkSelectFrom(tls *libc.TLS, pWalker uintptr, p uintptr) (r int32) {
	var i int32
	var pItem, pSrc uintptr
	_, _, _ = i, pItem, pSrc
	pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
	if pSrc != 0 {
		i = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc
		pItem = pSrc + 8
		for {
			if !(i > 0) {
				break
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0 && _sqlite3WalkSelect(tls, pWalker, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect) != 0 {
				return int32(WRC_Abort)
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x8>>3) != 0 && _sqlite3WalkExprList(tls, pWalker, *(*uintptr)(unsafe.Pointer(pItem + 32))) != 0 {
				return int32(WRC_Abort)
			}
			goto _1
		_1:
			;
			i = i - 1
			pItem += 48
		}
	}
	return WRC_Continue
}

func _sqlite3WhereExprListUsage(tls *libc.TLS, pMaskSet uintptr, pList uintptr) (r TBitmask) {
	var i int32
	var mask TBitmask
	_, _ = i, mask
	mask = uint64(0)
	if pList != 0 {
		i = 0
		for {
			if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
				break
			}
			mask = mask | _sqlite3WhereExprUsage(tls, pMaskSet, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr)
			goto _1
		_1:
			;
			i = i + 1
		}
	}
	return mask
}

// C documentation
//
//	/*
//	** If the WHERE_GROUPBY flag is set in the mask passed to sqlite3WhereBegin(),
//	** the planner assumes that the specified pOrderBy list is actually a GROUP
//	** BY clause - and so any order that groups rows as required satisfies the
//	** request.
//	**
//	** Normally, in this case it is not possible for the caller to determine
//	** whether or not the rows are really being delivered in sorted order, or
//	** just in some other order that provides the required grouping. However,
//	** if the WHERE_SORTBYGROUP flag is also passed to sqlite3WhereBegin(), then
//	** this function may be called on the returned WhereInfo object. It returns
//	** true if the rows really will be sorted in the specified order, or false
//	** otherwise.
//	**
//	** For example, assuming:
//	**
//	**   CREATE INDEX i1 ON t1(x, Y);
//	**
//	** then
//	**
//	**   SELECT * FROM t1 GROUP BY x,y ORDER BY x,y;   -- IsSorted()==1
//	**   SELECT * FROM t1 GROUP BY y,x ORDER BY y,x;   -- IsSorted()==0
//	*/
func _sqlite3WhereIsSorted(tls *libc.TLS, pWInfo uintptr) (r int32) {
	return int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 48)) & 0x8 >> 3))
}

// C documentation
//
//	/*
//	** Return TRUE if the WHERE loop uses the OP_DeferredSeek opcode to move
//	** the data cursor to the row selected by the index cursor.
//	*/
func _sqlite3WhereUsesDeferredSeek(tls *libc.TLS, pWInfo uintptr) (r int32) {
	return int32(uint32(*(*uint8)(unsafe.Pointer(pWInfo + 48)) & 0x1 >> 0))
}

// C documentation
//
//	/*
//	** Allocate and return a duplicate of the Window object indicated by the
//	** third argument. Set the Window.pOwner field of the new object to
//	** pOwner.
//	*/
func _sqlite3WindowDup(tls *libc.TLS, db uintptr, pOwner uintptr, p uintptr) (r uintptr) {
	var pNew uintptr
	_ = pNew
	pNew = uintptr(0)
	if p != 0 {
		pNew = _sqlite3DbMallocZero(tls, db, uint64(100))
		if pNew != 0 {
			(*TWindow)(unsafe.Pointer(pNew)).FzName = _sqlite3DbStrDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FzName)
			(*TWindow)(unsafe.Pointer(pNew)).FzBase = _sqlite3DbStrDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FzBase)
			(*TWindow)(unsafe.Pointer(pNew)).FpFilter = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpFilter, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpWFunc = (*TWindow)(unsafe.Pointer(p)).FpWFunc
			(*TWindow)(unsafe.Pointer(pNew)).FpPartition = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpPartition, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpOrderBy = _sqlite3ExprListDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpOrderBy, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FeFrmType = (*TWindow)(unsafe.Pointer(p)).FeFrmType
			(*TWindow)(unsafe.Pointer(pNew)).FeEnd = (*TWindow)(unsafe.Pointer(p)).FeEnd
			(*TWindow)(unsafe.Pointer(pNew)).FeStart = (*TWindow)(unsafe.Pointer(p)).FeStart
			(*TWindow)(unsafe.Pointer(pNew)).FeExclude = (*TWindow)(unsafe.Pointer(p)).FeExclude
			(*TWindow)(unsafe.Pointer(pNew)).FregResult = (*TWindow)(unsafe.Pointer(p)).FregResult
			(*TWindow)(unsafe.Pointer(pNew)).FregAccum = (*TWindow)(unsafe.Pointer(p)).FregAccum
			(*TWindow)(unsafe.Pointer(pNew)).FiArgCol = (*TWindow)(unsafe.Pointer(p)).FiArgCol
			(*TWindow)(unsafe.Pointer(pNew)).FiEphCsr = (*TWindow)(unsafe.Pointer(p)).FiEphCsr
			(*TWindow)(unsafe.Pointer(pNew)).FbExprArgs = (*TWindow)(unsafe.Pointer(p)).FbExprArgs
			(*TWindow)(unsafe.Pointer(pNew)).FpStart = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpStart, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpEnd = _sqlite3ExprDup(tls, db, (*TWindow)(unsafe.Pointer(p)).FpEnd, 0)
			(*TWindow)(unsafe.Pointer(pNew)).FpOwner = pOwner
			(*TWindow)(unsafe.Pointer(pNew)).FbImplicitFrame = (*TWindow)(unsafe.Pointer(p)).FbImplicitFrame
		}
	}
	return pNew
}

// C documentation
//
//	/*
//	** Possibly link window pWin into the list at pSel->pWin (window functions
//	** to be processed as part of SELECT statement pSel). The window is linked
//	** in if either (a) there are no other windows already linked to this
//	** SELECT, or (b) the windows already linked use a compatible window frame.
//	*/
func _sqlite3WindowLink(tls *libc.TLS, pSel uintptr, pWin uintptr) {
	if pSel != 0 {
		if uintptr(0) == (*TSelect)(unsafe.Pointer(pSel)).FpWin || 0 == _sqlite3WindowCompare(tls, uintptr(0), (*TSelect)(unsafe.Pointer(pSel)).FpWin, pWin, 0) {
			(*TWindow)(unsafe.Pointer(pWin)).FpNextWin = (*TSelect)(unsafe.Pointer(pSel)).FpWin
			if (*TSelect)(unsafe.Pointer(pSel)).FpWin != 0 {
				(*TWindow)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpWin)).FppThis = pWin + 36
			}
			(*TSelect)(unsafe.Pointer(pSel)).FpWin = pWin
			(*TWindow)(unsafe.Pointer(pWin)).FppThis = pSel + 60
		} else {
			if _sqlite3ExprListCompare(tls, (*TWindow)(unsafe.Pointer(pWin)).FpPartition, (*TWindow)(unsafe.Pointer((*TSelect)(unsafe.Pointer(pSel)).FpWin)).FpPartition, -int32(1)) != 0 {
				**(**Tu32)(__ccgo_up(pSel + 4)) |= uint32(SF_MultiPart)
			}
		}
	}
}

// C documentation
//
//	/*
//	** Return a copy of the linked list of Window objects passed as the
//	** second argument.
//	*/
func _sqlite3WindowListDup(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pWin, pp uintptr
	var _ /* pRet at bp+0 */ uintptr
	_, _ = pWin, pp
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pp = bp
	pWin = p
	for {
		if !(pWin != 0) {
			break
		}
		**(**uintptr)(__ccgo_up(pp)) = _sqlite3WindowDup(tls, db, uintptr(0), pWin)
		if **(**uintptr)(__ccgo_up(pp)) == uintptr(0) {
			break
		}
		pp = **(**uintptr)(__ccgo_up(pp)) + 36
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
	return **(**uintptr)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Free the contents of the With object passed as the second argument.
//	*/
func _sqlite3WithDelete(tls *libc.TLS, db uintptr, pWith uintptr) {
	var i int32
	_ = i
	if pWith != 0 {
		i = 0
		for {
			if !(i < (*TWith)(unsafe.Pointer(pWith)).FnCte) {
				break
			}
			_cteClear(tls, db, pWith+12+uintptr(i)*24)
			goto _1
		_1:
			;
			i = i + 1
		}
		_sqlite3DbFree(tls, db, pWith)
	}
}

// C documentation
//
//	/*
//	** Assign new cursor numbers to each of the items in pSrc. For each
//	** new cursor number assigned, set an entry in the aCsrMap[] array
//	** to map the old cursor number to the new:
//	**
//	**     aCsrMap[iOld+1] = iNew;
//	**
//	** The array is guaranteed by the caller to be large enough for all
//	** existing cursor numbers in pSrc.  aCsrMap[0] is the array size.
//	**
//	** If pSrc contains any sub-selects, call this routine recursively
//	** on the FROM clause of each such sub-select, with iExcept set to -1.
//	*/
func _srclistRenumberCursors(tls *libc.TLS, pParse uintptr, aCsrMap uintptr, pSrc uintptr, iExcept int32) {
	var i, v2 int32
	var p, pItem, v3 uintptr
	_, _, _, _, _ = i, p, pItem, v2, v3
	i = 0
	pItem = pSrc + 8
	for {
		if !(i < (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc) {
			break
		}
		if i != iExcept {
			if !(int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x80>>7) != 0) || **(**int32)(__ccgo_up(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4)) == 0 {
				v3 = pParse + 44
				v2 = *(*int32)(unsafe.Pointer(v3))
				*(*int32)(unsafe.Pointer(v3)) = *(*int32)(unsafe.Pointer(v3)) + 1
				**(**int32)(__ccgo_up(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4)) = v2
			}
			(*TSrcItem)(unsafe.Pointer(pItem)).FiCursor = **(**int32)(__ccgo_up(aCsrMap + uintptr((*TSrcItem)(unsafe.Pointer(pItem)).FiCursor+int32(1))*4))
			if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0 {
				p = (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect
				for {
					if !(p != 0) {
						break
					}
					_srclistRenumberCursors(tls, pParse, aCsrMap, (*TSelect)(unsafe.Pointer(p)).FpSrc, -int32(1))
					goto _4
				_4:
					;
					p = (*TSelect)(unsafe.Pointer(p)).FpPrior
				}
			}
		}
		goto _1
	_1:
		;
		i = i + 1
		pItem += 48
	}
}

func _statClearCells(tls *libc.TLS, p uintptr) {
	var i int32
	_ = i
	if (*TStatPage)(unsafe.Pointer(p)).FaCell != 0 {
		i = 0
		for {
			if !(i < (*TStatPage)(unsafe.Pointer(p)).FnCell) {
				break
			}
			Xsqlite3_free(tls, (**(**TStatCell)(__ccgo_up((*TStatPage)(unsafe.Pointer(p)).FaCell + uintptr(i)*24))).FaOvfl)
			goto _1
		_1:
			;
			i = i + 1
		}
		Xsqlite3_free(tls, (*TStatPage)(unsafe.Pointer(p)).FaCell)
	}
	(*TStatPage)(unsafe.Pointer(p)).FnCell = 0
	(*TStatPage)(unsafe.Pointer(p)).FaCell = uintptr(0)
}

func _statClearPage(tls *libc.TLS, p uintptr) {
	var aPg uintptr
	_ = aPg
	aPg = (*TStatPage)(unsafe.Pointer(p)).FaPg
	_statClearCells(tls, p)
	Xsqlite3_free(tls, (*TStatPage)(unsafe.Pointer(p)).FzPath)
	libc.Xmemset(tls, p, 0, uint32(40))
	(*TStatPage)(unsafe.Pointer(p)).FaPg = aPg
}

// C documentation
//
//	/*
//	** Open a new DBSTAT cursor.
//	*/
func _statOpen(tls *libc.TLS, pVTab uintptr, ppCursor uintptr) (r int32) {
	var pCsr, pTab uintptr
	_, _ = pCsr, pTab
	pTab = pVTab
	pCsr = Xsqlite3_malloc64(tls, uint64(1360))
	if pCsr == uintptr(0) {
		return int32(SQLITE_NOMEM)
	} else {
		libc.Xmemset(tls, pCsr, 0, uint32(1360))
		(*TStatCursor)(unsafe.Pointer(pCsr)).Fbase.FpVtab = pVTab
		(*TStatCursor)(unsafe.Pointer(pCsr)).FiDb = (*TStatTable)(unsafe.Pointer(pTab)).FiDb
	}
	**(**uintptr)(__ccgo_up(ppCursor)) = pCsr
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Finish off a string by making sure it is zero-terminated.
//	** Return a pointer to the resulting string.  Return a NULL
//	** pointer if any kind of error was encountered.
//	*/
func _strAccumFinishRealloc(tls *libc.TLS, p uintptr) (r uintptr) {
	var zText, v1 uintptr
	_, _ = zText, v1
	zText = _sqlite3DbMallocRaw(tls, (*TStrAccum)(unsafe.Pointer(p)).Fdb, uint64(1)+uint64((*TStrAccum)(unsafe.Pointer(p)).FnChar))
	if zText != 0 {
		libc.Xmemcpy(tls, zText, (*TStrAccum)(unsafe.Pointer(p)).FzText, (*TStrAccum)(unsafe.Pointer(p)).FnChar+uint32(1))
		v1 = p + 21
		*(*Tu8)(unsafe.Pointer(v1)) = Tu8(int32(*(*Tu8)(unsafe.Pointer(v1))) | libc.Int32FromInt32(SQLITE_PRINTF_MALLOCED))
	} else {
		_sqlite3StrAccumSetError(tls, p, uint8(SQLITE_NOMEM))
	}
	(*TStrAccum)(unsafe.Pointer(p)).FzText = zText
	return zText
}

// C documentation
//
//	/*
//	** Return true if it is necessary to write page *pPg into the sub-journal.
//	** A page needs to be written into the sub-journal if there exists one
//	** or more open savepoints for which:
//	**
//	**   * The page-number is less than or equal to PagerSavepoint.nOrig, and
//	**   * The bit corresponding to the page-number is not set in
//	**     PagerSavepoint.pInSavepoint.
//	*/
func _subjRequiresPage(tls *libc.TLS, pPg uintptr) (r int32) {
	var i int32
	var p, pPager uintptr
	var pgno TPgno
	_, _, _, _ = i, p, pPager, pgno
	pPager = (*TPgHdr)(unsafe.Pointer(pPg)).FpPager
	pgno = (*TPgHdr)(unsafe.Pointer(pPg)).Fpgno
	i = 0
	for {
		if !(i < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
			break
		}
		p = (*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(i)*48
		if (*TPagerSavepoint)(unsafe.Pointer(p)).FnOrig >= pgno && 0 == _sqlite3BitvecTestNotNull(tls, (*TPagerSavepoint)(unsafe.Pointer(p)).FpInSavepoint, pgno) {
			i = i + int32(1)
			for {
				if !(i < (*TPager)(unsafe.Pointer(pPager)).FnSavepoint) {
					break
				}
				(**(**TPagerSavepoint)(__ccgo_up((*TPager)(unsafe.Pointer(pPager)).FaSavepoint + uintptr(i)*48))).FbTruncateOnRelease = 0
				goto _2
			_2:
				;
				i = i + 1
			}
			return int32(1)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return 0
}

func _substExprList(tls *libc.TLS, pSubst uintptr, pList uintptr) {
	var i int32
	_ = i
	if pList == uintptr(0) {
		return
	}
	i = 0
	for {
		if !(i < (*TExprList)(unsafe.Pointer(pList)).FnExpr) {
			break
		}
		(*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr = _substExpr(tls, pSubst, (*(*TExprList_item)(unsafe.Pointer(pList + 8 + uintptr(i)*20))).FpExpr)
		goto _1
	_1:
		;
		i = i + 1
	}
}

func _substSelect(tls *libc.TLS, pSubst uintptr, p uintptr, doPrior int32) {
	var i int32
	var pItem, pSrc, v1 uintptr
	var v2 bool
	_, _, _, _, _ = i, pItem, pSrc, v1, v2
	if !(p != 0) {
		return
	}
	(*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth = (*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth + 1
	for {
		_substExprList(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpEList)
		_substExprList(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpGroupBy)
		_substExprList(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpOrderBy)
		(*TSelect)(unsafe.Pointer(p)).FpHaving = _substExpr(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpHaving)
		(*TSelect)(unsafe.Pointer(p)).FpWhere = _substExpr(tls, pSubst, (*TSelect)(unsafe.Pointer(p)).FpWhere)
		pSrc = (*TSelect)(unsafe.Pointer(p)).FpSrc
		i = (*TSrcList)(unsafe.Pointer(pSrc)).FnSrc
		pItem = pSrc + 8
		for {
			if !(i > 0) {
				break
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x4>>2) != 0 {
				_substSelect(tls, pSubst, (*TSubquery)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(pItem + 44)))).FpSelect, int32(1))
			}
			if int32(*(*uint32)(unsafe.Pointer(pItem + 12 + 4))&0x8>>3) != 0 {
				_substExprList(tls, pSubst, *(*uintptr)(unsafe.Pointer(pItem + 32)))
			}
			goto _4
		_4:
			;
			i = i - 1
			pItem += 48
		}
		goto _3
	_3:
		;
		if v2 = doPrior != 0; v2 {
			v1 = (*TSelect)(unsafe.Pointer(p)).FpPrior
			p = v1
		}
		if !(v2 && v1 != uintptr(0)) {
			break
		}
	}
	(*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth = (*TSubstContext)(unsafe.Pointer(pSubst)).FnSelDepth - 1
}

// C documentation
//
//	/*
//	** This routine is called if the collation factory fails to deliver a
//	** collation function in the best encoding but there may be other versions
//	** of this collation function (for other text encodings) available. Use one
//	** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
//	** possible.
//	*/
func _synthCollSeq(tls *libc.TLS, db uintptr, pColl uintptr) (r int32) {
	var i int32
	var pColl2, z uintptr
	_, _, _ = i, pColl2, z
	z = (*TCollSeq)(unsafe.Pointer(pColl)).FzName
	i = 0
	for {
		if !(i < int32(3)) {
			break
		}
		pColl2 = _sqlite3FindCollSeq(tls, db, _aEnc[i], z, 0)
		if (*TCollSeq)(unsafe.Pointer(pColl2)).FxCmp != uintptr(0) {
			libc.Xmemcpy(tls, pColl, pColl2, uint32(20))
			(*TCollSeq)(unsafe.Pointer(pColl)).FxDel = uintptr(0) /* Do not copy the destructor */
			return SQLITE_OK
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	return int32(SQLITE_ERROR)
}

// C documentation
//
//	/*
//	** Return true if any TEMP triggers exist
//	*/
func _tempTriggersExist(tls *libc.TLS, db uintptr) (r int32) {
	if (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema == uintptr(0) {
		return 0
	}
	if (*THash)(unsafe.Pointer((**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + 1*16))).FpSchema+40)).Ffirst == uintptr(0) {
		return 0
	}
	return int32(1)
}

// C documentation
//
//	/*
//	** Return term iTerm of the WhereClause passed as the first argument. Terms
//	** are numbered from 0 upwards, starting with the terms in pWC->a[], then
//	** those in pWC->pOuter->a[] (if any), and so on.
//	*/
func _termFromWhereClause(tls *libc.TLS, pWC uintptr, iTerm int32) (r uintptr) {
	var p uintptr
	_ = p
	p = pWC
	for {
		if !(p != 0) {
			break
		}
		if iTerm < (*TWhereClause)(unsafe.Pointer(p)).FnTerm {
			return (*TWhereClause)(unsafe.Pointer(p)).Fa + uintptr(iTerm)*48
		}
		iTerm = iTerm - (*TWhereClause)(unsafe.Pointer(p)).FnTerm
		goto _1
	_1:
		;
		p = (*TWhereClause)(unsafe.Pointer(p)).FpOuter
	}
	return uintptr(0)
}

// C documentation
//
//	/*
//	** Unmap all tokens in the IdList object passed as the second argument.
//	*/
func _unmapColumnIdlistNames(tls *libc.TLS, pParse uintptr, pIdList uintptr) {
	var ii int32
	_ = ii
	ii = 0
	for {
		if !(ii < (*TIdList)(unsafe.Pointer(pIdList)).FnId) {
			break
		}
		_sqlite3RenameTokenRemap(tls, pParse, uintptr(0), (*(*TIdList_item)(unsafe.Pointer(pIdList + 4 + uintptr(ii)*4))).FzName)
		goto _1
	_1:
		;
		ii = ii + 1
	}
}

// C documentation
//
//	/*
//	** If the Vdbe passed as the first argument opened a statement-transaction,
//	** close it now. Argument eOp must be either SAVEPOINT_ROLLBACK or
//	** SAVEPOINT_RELEASE. If it is SAVEPOINT_ROLLBACK, then the statement
//	** transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the
//	** statement transaction is committed.
//	**
//	** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned.
//	** Otherwise SQLITE_OK.
//	*/
func _vdbeCloseStatement(tls *libc.TLS, p uintptr, eOp int32) (r int32) {
	var db, pBt uintptr
	var i, iSavepoint, rc, rc2 int32
	_, _, _, _, _, _ = db, i, iSavepoint, pBt, rc, rc2
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	rc = SQLITE_OK
	iSavepoint = (*TVdbe)(unsafe.Pointer(p)).FiStatement - int32(1)
	i = 0
	for {
		if !(i < (*Tsqlite3)(unsafe.Pointer(db)).FnDb) {
			break
		}
		rc2 = SQLITE_OK
		pBt = (**(**TDb)(__ccgo_up((*Tsqlite3)(unsafe.Pointer(db)).FaDb + uintptr(i)*16))).FpBt
		if pBt != 0 {
			if eOp == int32(SAVEPOINT_ROLLBACK) {
				rc2 = _sqlite3BtreeSavepoint(tls, pBt, int32(SAVEPOINT_ROLLBACK), iSavepoint)
			}
			if rc2 == SQLITE_OK {
				rc2 = _sqlite3BtreeSavepoint(tls, pBt, int32(SAVEPOINT_RELEASE), iSavepoint)
			}
			if rc == SQLITE_OK {
				rc = rc2
			}
		}
		goto _1
	_1:
		;
		i = i + 1
	}
	(*Tsqlite3)(unsafe.Pointer(db)).FnStatement = (*Tsqlite3)(unsafe.Pointer(db)).FnStatement - 1
	(*TVdbe)(unsafe.Pointer(p)).FiStatement = 0
	if rc == SQLITE_OK {
		if eOp == int32(SAVEPOINT_ROLLBACK) {
			rc = _sqlite3VtabSavepoint(tls, db, int32(SAVEPOINT_ROLLBACK), iSavepoint)
		}
		if rc == SQLITE_OK {
			rc = _sqlite3VtabSavepoint(tls, db, int32(SAVEPOINT_RELEASE), iSavepoint)
		}
	}
	/* If the statement transaction is being rolled back, also restore the
	 ** database handles deferred constraint counter to the value it had when
	 ** the statement transaction was opened.  */
	if eOp == int32(SAVEPOINT_ROLLBACK) {
		(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredCons = (*TVdbe)(unsafe.Pointer(p)).FnStmtDefCons
		(*Tsqlite3)(unsafe.Pointer(db)).FnDeferredImmCons = (*TVdbe)(unsafe.Pointer(p)).FnStmtDefImmCons
	}
	return rc
}

// C documentation
//
//	/*
//	** Both *pMem1 and *pMem2 contain string values. Compare the two values
//	** using the collation sequence pColl. As usual, return a negative , zero
//	** or positive value if *pMem1 is less than, equal to or greater than
//	** *pMem2, respectively. Similar in spirit to "rc = (*pMem1) - (*pMem2);".
//	*/
func _vdbeCompareMemStringWithEncodingChange(tls *libc.TLS, pMem1 uintptr, pMem2 uintptr, pColl uintptr, prcErr uintptr) (r int32) {
	bp := tls.Alloc(80)
	defer tls.Free(80)
	var rc int32
	var v1, v2 uintptr
	var _ /* c1 at bp+0 */ TMem
	var _ /* c2 at bp+40 */ TMem
	_, _, _ = rc, v1, v2
	_sqlite3VdbeMemInit(tls, bp, (*TMem)(unsafe.Pointer(pMem1)).Fdb, uint16(MEM_Null))
	_sqlite3VdbeMemInit(tls, bp+40, (*TMem)(unsafe.Pointer(pMem1)).Fdb, uint16(MEM_Null))
	_sqlite3VdbeMemShallowCopy(tls, bp, pMem1, int32(MEM_Ephem))
	_sqlite3VdbeMemShallowCopy(tls, bp+40, pMem2, int32(MEM_Ephem))
	v1 = _sqlite3ValueText(tls, bp, (*TCollSeq)(unsafe.Pointer(pColl)).Fenc)
	v2 = _sqlite3ValueText(tls, bp+40, (*TCollSeq)(unsafe.Pointer(pColl)).Fenc)
	if v1 == uintptr(0) || v2 == uintptr(0) {
		if prcErr != 0 {
			**(**Tu8)(__ccgo_up(prcErr)) = uint8(SQLITE_NOMEM)
		}
		rc = 0
	} else {
		rc = (*(*func(*libc.TLS, uintptr, int32, uintptr, int32, uintptr) int32)(unsafe.Pointer(&struct{ uintptr }{(*TCollSeq)(unsafe.Pointer(pColl)).FxCmp})))(tls, (*TCollSeq)(unsafe.Pointer(pColl)).FpUser, (**(**TMem)(__ccgo_up(bp))).Fn, v1, (**(**TMem)(__ccgo_up(bp + 40))).Fn, v2)
	}
	_sqlite3VdbeMemReleaseMalloc(tls, bp)
	_sqlite3VdbeMemReleaseMalloc(tls, bp+40)
	return rc
}

// C documentation
//
//	/*
//	** Free the space allocated for aOp and any p4 values allocated for the
//	** opcodes contained within. If aOp is not NULL it is assumed to contain
//	** nOp entries.
//	*/
func _vdbeFreeOpArray(tls *libc.TLS, db uintptr, aOp uintptr, nOp int32) {
	var pOp uintptr
	_ = pOp
	if aOp != 0 {
		pOp = aOp + uintptr(nOp-int32(1))*20
		for int32(1) != 0 { /* Exit via break */
			if int32((*TOp)(unsafe.Pointer(pOp)).Fp4type) <= -int32(7) {
				_freeP4(tls, db, int32((*TOp)(unsafe.Pointer(pOp)).Fp4type), *(*uintptr)(unsafe.Pointer(pOp + 16)))
			}
			if pOp == aOp {
				break
			}
			pOp -= 20
		}
		_sqlite3DbNNFreeNN(tls, db, aOp)
	}
}

// C documentation
//
//	/*
//	** If the second argument is not NULL, release any allocations associated
//	** with the memory cells in the p->aMem[] array. Also free the UnpackedRecord
//	** structure itself, using sqlite3DbFree().
//	**
//	** This function is used to free UnpackedRecord structures allocated by
//	** the vdbeUnpackRecord() function found in vdbeapi.c.
//	*/
func _vdbeFreeUnpacked(tls *libc.TLS, db uintptr, nField int32, p uintptr) {
	var i int32
	var pMem uintptr
	_, _ = i, pMem
	if p != 0 {
		i = 0
		for {
			if !(i < nField) {
				break
			}
			pMem = (*TUnpackedRecord)(unsafe.Pointer(p)).FaMem + uintptr(i)*40
			if (*TMem)(unsafe.Pointer(pMem)).FzMalloc != 0 {
				_sqlite3VdbeMemReleaseMalloc(tls, pMem)
			}
			goto _1
		_1:
			;
			i = i + 1
		}
		_sqlite3DbNNFreeNN(tls, db, p)
	}
}

// C documentation
//
//	/*
//	** The main routine for background threads that populate aFile[1] of
//	** multi-threaded IncrMerger objects.
//	*/
func _vdbeIncrPopulateThread(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pIncr, pRet uintptr
	_, _ = pIncr, pRet
	pIncr = pCtx
	pRet = uintptr(_vdbeIncrPopulate(tls, pIncr))
	(*TSortSubtask)(unsafe.Pointer((*TIncrMerger)(unsafe.Pointer(pIncr)).FpTask)).FbDone = int32(1)
	return pRet
}

// C documentation
//
//	/*
//	** Unlock all of the btrees previously locked by a call to sqlite3VdbeEnter().
//	*/
func _vdbeLeave(tls *libc.TLS, p uintptr) {
	var aDb, db uintptr
	var i, nDb int32
	_, _, _, _ = aDb, db, i, nDb
	db = (*TVdbe)(unsafe.Pointer(p)).Fdb
	aDb = (*Tsqlite3)(unsafe.Pointer(db)).FaDb
	nDb = (*Tsqlite3)(unsafe.Pointer(db)).FnDb
	i = 0
	for {
		if !(i < nDb) {
			break
		}
		if i != int32(1) && (*TVdbe)(unsafe.Pointer(p)).FlockMask&(libc.Uint32FromInt32(1)<<i) != uint32(0) && (**(**TDb)(__ccgo_up(aDb + uintptr(i)*16))).FpBt != uintptr(0) {
			_sqlite3BtreeLeave(tls, (**(**TDb)(__ccgo_up(aDb + uintptr(i)*16))).FpBt)
		}
		goto _1
	_1:
		;
		i = i + 1
	}
}

// C documentation
//
//	/*
//	** The main routine for vdbePmaReaderIncrMergeInit() operations run in
//	** background threads.
//	*/
func _vdbePmaReaderBgIncrInit(tls *libc.TLS, pCtx uintptr) (r uintptr) {
	var pReader, pRet uintptr
	_, _ = pReader, pRet
	pReader = pCtx
	pRet = uintptr(_vdbePmaReaderIncrMergeInit(tls, pReader, int32(INCRINIT_TASK)))
	(*TSortSubtask)(unsafe.Pointer((*TIncrMerger)(unsafe.Pointer((*TPmaReader)(unsafe.Pointer(pReader)).FpIncr)).FpTask)).FbDone = int32(1)
	return pRet
}

// C documentation
//
//	/*
//	** The first argument is a file-handle open on a temporary file. The file
//	** is guaranteed to be nByte bytes or smaller in size. This function
//	** attempts to extend the file to nByte bytes in size and to ensure that
//	** the VFS has memory mapped it.
//	**
//	** Whether or not the file does end up memory mapped of course depends on
//	** the specific VFS implementation.
//	*/
func _vdbeSorterExtendFile(tls *libc.TLS, db uintptr, pFd uintptr, _nByte Ti64) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	*(*Ti64)(unsafe.Pointer(bp)) = _nByte
	var _ /* chunksize at bp+12 */ int32
	var _ /* p at bp+8 */ uintptr
	if **(**Ti64)(__ccgo_up(bp)) <= int64((*Tsqlite3)(unsafe.Pointer(db)).FnMaxSorterMmap) && (*Tsqlite3_io_methods)(unsafe.Pointer((*Tsqlite3_file)(unsafe.Pointer(pFd)).FpMethods)).FiVersion >= int32(3) {
		**(**uintptr)(__ccgo_up(bp + 8)) = uintptr(0)
		**(**int32)(__ccgo_up(bp + 12)) = libc.Int32FromInt32(4) * libc.Int32FromInt32(1024)
		_sqlite3OsFileControlHint(tls, pFd, int32(SQLITE_FCNTL_CHUNK_SIZE), bp+12)
		_sqlite3OsFileControlHint(tls, pFd, int32(SQLITE_FCNTL_SIZE_HINT), bp)
		_sqlite3OsFetch(tls, pFd, 0, int32(**(**Ti64)(__ccgo_up(bp))), bp+8)
		if **(**uintptr)(__ccgo_up(bp + 8)) != 0 {
			_sqlite3OsUnfetch(tls, pFd, 0, **(**uintptr)(__ccgo_up(bp + 8)))
		}
	}
}

// C documentation
//
//	/*
//	** Join thread pTask->thread.
//	*/
func _vdbeSorterJoinThread(tls *libc.TLS, pTask uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var rc int32
	var _ /* pRet at bp+0 */ uintptr
	_ = rc
	rc = SQLITE_OK
	if (*TSortSubtask)(unsafe.Pointer(pTask)).FpThread != 0 {
		**(**uintptr)(__ccgo_up(bp)) = uintptr(libc.Int32FromInt32(SQLITE_ERROR))
		_sqlite3ThreadJoin(tls, (*TSortSubtask)(unsafe.Pointer(pTask)).FpThread, bp)
		rc = int32(**(**uintptr)(__ccgo_up(bp)))
		(*TSortSubtask)(unsafe.Pointer(pTask)).FbDone = 0
		(*TSortSubtask)(unsafe.Pointer(pTask)).FpThread = uintptr(0)
	}
	return rc
}

// C documentation
//
//	/*
//	** Merge the two sorted lists p1 and p2 into a single list.
//	*/
func _vdbeSorterMerge(tls *libc.TLS, pTask uintptr, p1 uintptr, p2 uintptr) (r uintptr) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var pp uintptr
	var res int32
	var _ /* bCached at bp+4 */ int32
	var _ /* pFinal at bp+0 */ uintptr
	_, _ = pp, res
	**(**uintptr)(__ccgo_up(bp)) = uintptr(0)
	pp = bp
	**(**int32)(__ccgo_up(bp + 4)) = 0
	for {
		res = (*(*func(*libc.TLS, uintptr, uintptr, uintptr, int32, uintptr, int32) int32)(unsafe.Pointer(&struct{ uintptr }{(*TSortSubtask)(unsafe.Pointer(pTask)).FxCompare})))(tls, pTask, bp+4, p1+libc.UintptrFromInt32(1)*8, (*TSorterRecord)(unsafe.Pointer(p1)).FnVal, p2+libc.UintptrFromInt32(1)*8, (*TSorterRecord)(unsafe.Pointer(p2)).FnVal)
		if res <= 0 {
			**(**uintptr)(__ccgo_up(pp)) = p1
			pp = p1 + 4
			p1 = *(*uintptr)(unsafe.Pointer(p1 + 4))
			if p1 == uintptr(0) {
				**(**uintptr)(__ccgo_up(pp)) = p2
				break
			}
		} else {
			**(**uintptr)(__ccgo_up(pp)) = p2
			pp = p2 + 4
			p2 = *(*uintptr)(unsafe.Pointer(p2 + 4))
			**(**int32)(__ccgo_up(bp + 4)) = 0
			if p2 == uintptr(0) {
				**(**uintptr)(__ccgo_up(pp)) = p1
				break
			}
		}
		goto _1
	_1:
	}
	return **(**uintptr)(__ccgo_up(bp))
}

// C documentation
//
//	/*
//	** Free the list of sorted records starting at pRecord.
//	*/
func _vdbeSorterRecordFree(tls *libc.TLS, db uintptr, pRecord uintptr) {
	var p, pNext uintptr
	_, _ = p, pNext
	p = pRecord
	for {
		if !(p != 0) {
			break
		}
		pNext = *(*uintptr)(unsafe.Pointer(p + 4))
		_sqlite3DbFree(tls, db, p)
		goto _1
	_1:
		;
		p = pNext
	}
}

// C documentation
//
//	/*
//	** Table p is a virtual table. This function moves all elements in the
//	** p->u.vtab.p list to the sqlite3.pDisconnect lists of their associated
//	** database connections to be disconnected at the next opportunity.
//	** Except, if argument db is not NULL, then the entry associated with
//	** connection db is left in the p->u.vtab.p list.
//	*/
func _vtabDisconnectAll(tls *libc.TLS, db uintptr, p uintptr) (r uintptr) {
	var db2, pNext, pRet, pVTable uintptr
	_, _, _, _ = db2, pNext, pRet, pVTable
	pRet = uintptr(0)
	pVTable = (*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(p + 44))).Fp
	(*(*struct {
		FnArg  int32
		FazArg uintptr
		Fp     uintptr
	})(unsafe.Pointer(p + 44))).Fp = uintptr(0)
	/* Assert that the mutex (if any) associated with the BtShared database
	 ** that contains table p is held by the caller. See header comments
	 ** above function sqlite3VtabUnlockList() for an explanation of why
	 ** this makes it safe to access the sqlite3.pDisconnect list of any
	 ** database connection that may have an entry in the p->u.vtab.p list.
	 */
	for pVTable != 0 {
		db2 = (*TVTable)(unsafe.Pointer(pVTable)).Fdb
		pNext = (*TVTable)(unsafe.Pointer(pVTable)).FpNext
		if db2 == db {
			pRet = pVTable
			(*(*struct {
				FnArg  int32
				FazArg uintptr
				Fp     uintptr
			})(unsafe.Pointer(p + 44))).Fp = pRet
			(*TVTable)(unsafe.Pointer(pRet)).FpNext = uintptr(0)
		} else {
			(*TVTable)(unsafe.Pointer(pVTable)).FpNext = (*Tsqlite3)(unsafe.Pointer(db2)).FpDisconnect
			(*Tsqlite3)(unsafe.Pointer(db2)).FpDisconnect = pVTable
		}
		pVTable = pNext
	}
	return pRet
}

// C documentation
//
//	/*
//	** This function does the work of sqlite3WalBeginReadTransaction() (see
//	** below). That function simply calls this one inside an SEH_TRY{...} block.
//	*/
func _walBeginReadTransaction(tls *libc.TLS, pWal uintptr, pChanged uintptr) (r int32) {
	bp := tls.Alloc(16)
	defer tls.Free(16)
	var bChanged, ckptLock, rc int32
	var pInfo, pSnapshot uintptr
	var _ /* cnt at bp+0 */ int32
	_, _, _, _, _ = bChanged, ckptLock, pInfo, pSnapshot, rc /* Return code */
	**(**int32)(__ccgo_up(bp)) = 0                           /* Number of TryBeginRead attempts */
	ckptLock = 0
	bChanged = 0
	pSnapshot = (*TWal)(unsafe.Pointer(pWal)).FpSnapshot
	if pSnapshot != 0 {
		if libc.Xmemcmp(tls, pSnapshot, pWal+52, uint32(48)) != 0 {
			bChanged = int32(1)
		}
		/* It is possible that there is a checkpointer thread running
		 ** concurrent with this code. If this is the case, it may be that the
		 ** checkpointer has already determined that it will checkpoint
		 ** snapshot X, where X is later in the wal file than pSnapshot, but
		 ** has not yet set the pInfo->nBackfillAttempted variable to indicate
		 ** its intent. To avoid the race condition this leads to, ensure that
		 ** there is no checkpointer process by taking a shared CKPT lock
		 ** before checking pInfo->nBackfillAttempted.  */
		rc = _walLockShared(tls, pWal, int32(WAL_CKPT_LOCK))
		if rc != SQLITE_OK {
			return rc
		}
		ckptLock = int32(1)
	}
	for cond := true; cond; cond = rc == -int32(1) {
		rc = _walTryBeginRead(tls, pWal, pChanged, 0, bp)
	}
	if rc == SQLITE_OK {
		if pSnapshot != 0 && libc.Xmemcmp(tls, pSnapshot, pWal+52, uint32(48)) != 0 {
			/* At this point the client has a lock on an aReadMark[] slot holding
			 ** a value equal to or smaller than pSnapshot->mxFrame, but pWal->hdr
			 ** is populated with the wal-index header corresponding to the head
			 ** of the wal file. Verify that pSnapshot is still valid before
			 ** continuing.  Reasons why pSnapshot might no longer be valid:
			 **
			 **    (1)  The WAL file has been reset since the snapshot was taken.
			 **         In this case, the salt will have changed.
			 **
			 **    (2)  A checkpoint as been attempted that wrote frames past
			 **         pSnapshot->mxFrame into the database file.  Note that the
			 **         checkpoint need not have completed for this to cause problems.
			 */
			pInfo = _walCkptInfo(tls, pWal)
			/* Check that the wal file has not been wrapped. Assuming that it has
			 ** not, also check that no checkpointer has attempted to checkpoint any
			 ** frames beyond pSnapshot->mxFrame. If either of these conditions are
			 ** true, return SQLITE_ERROR_SNAPSHOT. Otherwise, overwrite pWal->hdr
			 ** with *pSnapshot and set *pChanged as appropriate for opening the
			 ** snapshot.  */
			if !(libc.Xmemcmp(tls, pSnapshot+32, pWal+52+32, uint32(8)) != 0) && (*TWalIndexHdr)(unsafe.Pointer(pSnapshot)).FmxFrame >= (*TWalCkptInfo)(unsafe.Pointer(pInfo)).FnBackfillAttempted {
				libc.Xmemcpy(tls, pWal+52, pSnapshot, uint32(48))
				**(**int32)(__ccgo_up(pChanged)) = bChanged
			} else {
				rc = libc.Int32FromInt32(SQLITE_ERROR) | libc.Int32FromInt32(3)<<libc.Int32FromInt32(8)
			}
			/* A client using a non-current snapshot may not ignore any frames
			 ** from the start of the wal file. This is because, for a system
			 ** where (minFrame < iSnapshot < maxFrame), a checkpointer may
			 ** have omitted to checkpoint a frame earlier than minFrame in
			 ** the file because there exists a frame after iSnapshot that
			 ** is the same database page.  */
			(*TWal)(unsafe.Pointer(pWal)).FminFrame = uint32(1)
			if rc != SQLITE_OK {
				_sqlite3WalEndReadTransaction(tls, pWal)
			}
		}
	}
	/* Release the shared CKPT lock obtained above. */
	if ckptLock != 0 {
		_walUnlockShared(tls, pWal, int32(WAL_CKPT_LOCK))
	}
	return rc
}

// C documentation
//
//	/*
//	** Return a pointer to the WalCkptInfo structure in the wal-index.
//	*/
func _walCkptInfo(tls *libc.TLS, pWal uintptr) (r uintptr) {
	return **(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData)) + uintptr(libc.Uint32FromInt64(48)/libc.Uint32FromInt32(2))*4
}

// C documentation
//
//	/*
//	** Return the page number associated with frame iFrame in this WAL.
//	*/
func _walFramePgno(tls *libc.TLS, pWal uintptr, iFrame Tu32) (r Tu32) {
	var iHash int32
	_ = iHash
	iHash = _walFramePage(tls, iFrame)
	if iHash == 0 {
		return **(**Tu32)(__ccgo_up(**(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData)) + uintptr((libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4)+iFrame-uint32(1))*4))
	}
	return **(**Tu32)(__ccgo_up(**(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iHash)*4)) + uintptr((iFrame-uint32(1)-(libc.Uint32FromInt32(HASHTABLE_NPAGE)-(libc.Uint32FromInt64(48)*libc.Uint32FromInt32(2)+libc.Uint32FromInt64(40))/libc.Uint32FromInt64(4)))%uint32(HASHTABLE_NPAGE))*4))
}

func _walIndexPage(tls *libc.TLS, pWal uintptr, iPage int32, ppPage uintptr) (r int32) {
	var v1 uintptr
	var v2 bool
	_, _ = v1, v2
	if v2 = (*TWal)(unsafe.Pointer(pWal)).FnWiData <= iPage; !v2 {
		v1 = **(**uintptr)(__ccgo_up((*TWal)(unsafe.Pointer(pWal)).FapWiData + uintptr(iPage)*4))
		**(**uintptr)(__ccgo_up(ppPage)) = v1
	}
	if v2 || v1 == uintptr(0) {
		return _walIndexPageRealloc(tls, pWal, iPage, ppPage)
	}
	return SQLITE_OK
}

// C documentation
//
//	/*
//	** Insert or replace a WhereLoop entry using the template supplied.
//	**
//	** An existing WhereLoop entry might be overwritten if the new template
//	** is better and has fewer dependencies.  Or the template will be ignored
//	** and no insert will occur if an existing WhereLoop is faster and has
//	** fewer dependencies than the template.  Otherwise a new WhereLoop is
//	** added based on the template.
//	**
//	** If pBuilder->pOrSet is not NULL then we care about only the
//	** prerequisites and rRun and nOut costs of the N best loops.  That
//	** information is gathered in the pBuilder->pOrSet object.  This special
//	** processing mode is used only for OR clause processing.
//	**
//	** When accumulating multiple loops (when pBuilder->pOrSet is NULL) we
//	** still might overwrite similar loops with the new template if the
//	** new template is better.  Loops may be overwritten if the following
//	** conditions are met:
//	**
//	**    (1)  They have the same iTab.
//	**    (2)  They have the same iSortIdx.
//	**    (3)  The template has same or fewer dependencies than the current loop
//	**    (4)  The template has the same or lower cost than the current loop
//	*/
func _whereLoopInsert(tls *libc.TLS, pBuilder uintptr, pTemplate uintptr) (r int32) {
	var db, p, pIndex, pToDel, pWInfo, ppPrev, ppTail, v1 uintptr
	var rc int32
	_, _, _, _, _, _, _, _, _ = db, p, pIndex, pToDel, pWInfo, ppPrev, ppTail, rc, v1
	pWInfo = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpWInfo
	db = (*TParse)(unsafe.Pointer((*TWhereInfo)(unsafe.Pointer(pWInfo)).FpParse)).Fdb
	/* Stop the search once we hit the query planner search limit */
	if (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit == uint32(0) {
		if (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != 0 {
			(*TWhereOrSet)(unsafe.Pointer((*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet)).Fn = uint16(0)
		}
		return int32(SQLITE_DONE)
	}
	(*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit = (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FiPlanLimit - 1
	_whereLoopAdjustCost(tls, (*TWhereInfo)(unsafe.Pointer(pWInfo)).FpLoops, pTemplate)
	/* If pBuilder->pOrSet is defined, then only keep track of the costs
	 ** and prereqs.
	 */
	if (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet != uintptr(0) {
		if (*TWhereLoop)(unsafe.Pointer(pTemplate)).FnLTerm != 0 {
			_whereOrInsert(tls, (*TWhereLoopBuilder)(unsafe.Pointer(pBuilder)).FpOrSet, (*TWhereLoop)(unsafe.Pointer(pTemplate)).Fprereq, (*TWhereLoop)(unsafe.Pointer(pTemplate)).FrRun, (*TWhereLoop)(unsafe.Pointer(pTemplate)).FnOut)
		}
		return SQLITE_OK
	}
	/* Look for an existing WhereLoop to replace with pTemplate
	 */
	ppPrev = _whereLoopFindLesser(tls, pWInfo+60, pTemplate)
	if ppPrev == uintptr(0) {
		/* There already exists a WhereLoop on the list that is better
		 ** than pTemplate, so just ignore pTemplate */
		return SQLITE_OK
	} else {
		p = **(**uintptr)(__ccgo_up(ppPrev))
	}
	/* If we reach this point it means that either p[] should be overwritten
	 ** with pTemplate[] if p[] exists, or if p==NULL then allocate a new
	 ** WhereLoop and insert it.
	 */
	if p == uintptr(0) {
		/* Allocate a new WhereLoop to add to the end of the list */
		v1 = _sqlite3DbMallocRawNN(tls, db, uint64(72))
		p = v1
		**(**uintptr)(__ccgo_up(ppPrev)) = v1
		if p == uintptr(0) {
			return int32(SQLITE_NOMEM)
		}
		_whereLoopInit(tls, p)
		(*TWhereLoop)(unsafe.Pointer(p)).FpNextLoop = uintptr(0)
	} else {
		/* We will be overwriting WhereLoop p[].  But before we do, first
		 ** go through the rest of the list and delete any other entries besides
		 ** p[] that are also supplanted by pTemplate */
		ppTail = p + 56
		for **(**uintptr)(__ccgo_up(ppTail)) != 0 {
			ppTail = _whereLoopFindLesser(tls, ppTail, pTemplate)
			if ppTail == uintptr(0) {
				break
			}
			pToDel = **(**uintptr)(__ccgo_up(ppTail))
			if pToDel == uintptr(0) {
				break
			}
			**(**uintptr)(__ccgo_up(ppTail)) = (*TWhereLoop)(unsafe.Pointer(pToDel)).FpNextLoop
			_whereLoopDelete(tls, db, pToDel)
		}
	}
	rc = _whereLoopXfer(tls, db, p, pTemplate)
	if (*TWhereLoop)(unsafe.Pointer(p)).FwsFlags&uint32(WHERE_VIRTUALTABLE) == uint32(0) {
		pIndex = (*(*struct {
			FnEq          Tu16
			FnBtm         Tu16
			FnTop         Tu16
			FnDistinctCol Tu16
			FpIndex       uintptr
			FpOrderBy     uintptr
		})(unsafe.Pointer(p + 24))).FpIndex
		if pIndex != 0 && int32(uint32(*(*uint16)(unsafe.Pointer(pIndex + 56))&0x3>>0)) == int32(SQLITE_IDXTYPE_IPK) {
			(*(*struct {
				FnEq          Tu16
				FnBtm         Tu16
				FnTop         Tu16
				FnDistinctCol Tu16
				FpIndex       uintptr
				FpOrderBy     uintptr
			})(unsafe.Pointer(p + 24))).FpIndex = uintptr(0)
		}
	}
	return rc
}

// C documentation
//
//	/*
//	** Return the number of arguments passed to the window-function associated
//	** with the object passed as the only argument to this function.
//	*/
func _windowArgCount(tls *libc.TLS, pWin uintptr) (r int32) {
	var pList uintptr
	var v1 int32
	_, _ = pList, v1
	pList = *(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20))
	if pList != 0 {
		v1 = (*TExprList)(unsafe.Pointer(pList)).FnExpr
	} else {
		v1 = 0
	}
	return v1
}

// C documentation
//
//	/*
//	** Generate code to set the accumulator register for each window function
//	** in the linked list passed as the second argument to NULL. And perform
//	** any equivalent initialization required by any built-in window functions
//	** in the list.
//	*/
func _windowInitAccum(tls *libc.TLS, pParse uintptr, pMWin uintptr) (r int32) {
	var nArg, regArg, v2 int32
	var pFunc, pWin, v uintptr
	_, _, _, _, _, _ = nArg, pFunc, pWin, regArg, v, v2
	v = _sqlite3GetVdbe(tls, pParse)
	nArg = 0
	pWin = pMWin
	for {
		if !(pWin != 0) {
			break
		}
		pFunc = (*TWindow)(unsafe.Pointer(pWin)).FpWFunc
		_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregAccum)
		if nArg > _windowArgCount(tls, pWin) {
			v2 = nArg
		} else {
			v2 = _windowArgCount(tls, pWin)
		}
		nArg = v2
		if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid == 0 {
			if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_first_valueName)) {
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pWin)).FregApp)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1))
			}
			if (*TFuncDef)(unsafe.Pointer(pFunc)).FfuncFlags&uint32(SQLITE_FUNC_MINMAX) != 0 && (*TWindow)(unsafe.Pointer(pWin)).FcsrApp != 0 {
				_sqlite3VdbeAddOp1(tls, v, int32(OP_ResetSorter), (*TWindow)(unsafe.Pointer(pWin)).FcsrApp)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), 0, (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1))
			}
		}
		goto _1
	_1:
		;
		pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
	}
	regArg = (*TParse)(unsafe.Pointer(pParse)).FnMem + int32(1)
	**(**int32)(__ccgo_up(pParse + 48)) += nArg
	return regArg
}

// C documentation
//
//	/*
//	** Remove any Window objects owned by the expression pExpr from the
//	** Select.pWin list of Select object pSelect.
//	*/
func _windowRemoveExprFromSelect(tls *libc.TLS, pSelect uintptr, pExpr uintptr) {
	bp := tls.Alloc(32)
	defer tls.Free(32)
	var _ /* sWalker at bp+0 */ TWalker
	if (*TSelect)(unsafe.Pointer(pSelect)).FpWin != 0 {
		libc.Xmemset(tls, bp, 0, uint32(28))
		(**(**TWalker)(__ccgo_up(bp))).FxExprCallback = __ccgo_fp(_resolveRemoveWindowsCb)
		*(*uintptr)(unsafe.Pointer(bp + 24)) = pSelect
		_sqlite3WalkExpr(tls, bp, pExpr)
	}
}

// C documentation
//
//	/*
//	** Invoke the sub-routine at regGosub (generated by code in select.c) to
//	** return the current row of Window.iEphCsr. If all window functions are
//	** aggregate window functions that use the standard API, a single
//	** OP_Gosub instruction is all that this routine generates. Extra VM code
//	** for per-row processing is only generated for the following built-in window
//	** functions:
//	**
//	**   nth_value()
//	**   first_value()
//	**   lag()
//	**   lead()
//	*/
func _windowReturnOneRow(tls *libc.TLS, p uintptr) {
	var csr, csr1, iEph, lbl, lbl1, nArg, op, tmpReg, tmpReg1, tmpReg2, val, v2 int32
	var pFunc, pMWin, pParse, pWin, v uintptr
	_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ = csr, csr1, iEph, lbl, lbl1, nArg, op, pFunc, pMWin, pParse, pWin, tmpReg, tmpReg1, tmpReg2, v, val, v2
	pMWin = (*TWindowCodeArg)(unsafe.Pointer(p)).FpMWin
	v = (*TWindowCodeArg)(unsafe.Pointer(p)).FpVdbe
	if (*TWindow)(unsafe.Pointer(pMWin)).FregStartRowid != 0 {
		_windowFullScan(tls, p)
	} else {
		pParse = (*TWindowCodeArg)(unsafe.Pointer(p)).FpParse
		pWin = pMWin
		for {
			if !(pWin != 0) {
				break
			}
			pFunc = (*TWindow)(unsafe.Pointer(pWin)).FpWFunc
			if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_first_valueName)) {
				csr = (*TWindow)(unsafe.Pointer(pWin)).FcsrApp
				lbl = _sqlite3VdbeMakeLabel(tls, pParse)
				tmpReg = _sqlite3GetTempReg(tls, pParse)
				_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
				if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_nth_valueName)) {
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+int32(1), tmpReg)
					_windowCheckValue(tls, pParse, tmpReg, int32(2))
				} else {
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Integer), int32(1), tmpReg)
				}
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Add), tmpReg, (*TWindow)(unsafe.Pointer(pWin)).FregApp, tmpReg)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Gt), (*TWindow)(unsafe.Pointer(pWin)).FregApp+int32(1), lbl, tmpReg)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), csr, 0, tmpReg)
				_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csr, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
				_sqlite3VdbeResolveLabel(tls, v, lbl)
				_sqlite3ReleaseTempReg(tls, pParse, tmpReg)
			} else {
				if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_leadName)) || (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_lagName)) {
					nArg = (*TExprList)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer((*TWindow)(unsafe.Pointer(pWin)).FpOwner + 20)))).FnExpr
					csr1 = (*TWindow)(unsafe.Pointer(pWin)).FcsrApp
					lbl1 = _sqlite3VdbeMakeLabel(tls, pParse)
					tmpReg1 = _sqlite3GetTempReg(tls, pParse)
					iEph = (*TWindow)(unsafe.Pointer(pMWin)).FiEphCsr
					if nArg < int32(3) {
						_sqlite3VdbeAddOp2(tls, v, int32(OP_Null), 0, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					} else {
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+int32(2), (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					}
					_sqlite3VdbeAddOp2(tls, v, int32(OP_Rowid), iEph, tmpReg1)
					if nArg < int32(2) {
						if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_leadName)) {
							v2 = int32(1)
						} else {
							v2 = -int32(1)
						}
						val = v2
						_sqlite3VdbeAddOp2(tls, v, int32(OP_AddImm), tmpReg1, val)
					} else {
						if (*TFuncDef)(unsafe.Pointer(pFunc)).FzName == uintptr(unsafe.Pointer(&_leadName)) {
							v2 = int32(OP_Add)
						} else {
							v2 = int32(OP_Subtract)
						}
						op = v2
						tmpReg2 = _sqlite3GetTempReg(tls, pParse)
						_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), iEph, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol+int32(1), tmpReg2)
						_sqlite3VdbeAddOp3(tls, v, op, tmpReg2, tmpReg1, tmpReg1)
						_sqlite3ReleaseTempReg(tls, pParse, tmpReg2)
					}
					_sqlite3VdbeAddOp3(tls, v, int32(OP_SeekRowid), csr1, lbl1, tmpReg1)
					_sqlite3VdbeAddOp3(tls, v, int32(OP_Column), csr1, (*TWindow)(unsafe.Pointer(pWin)).FiArgCol, (*TWindow)(unsafe.Pointer(pWin)).FregResult)
					_sqlite3VdbeResolveLabel(tls, v, lbl1)
					_sqlite3ReleaseTempReg(tls, pParse, tmpReg1)
				}
			}
			goto _1
		_1:
			;
			pWin = (*TWindow)(unsafe.Pointer(pWin)).FpNextWin
		}
	}
	_sqlite3VdbeAddOp2(tls, v, int32(OP_Gosub), (*TWindowCodeArg)(unsafe.Pointer(p)).FregGosub, (*TWindowCodeArg)(unsafe.Pointer(p)).FaddrGosub)
}

// C documentation
//
//	/*
//	** Pop the parser's stack once.
//	**
//	** If there is a destructor routine associated with the token which
//	** is popped from the stack, then call it.
//	*/
func _yy_pop_parser_stack(tls *libc.TLS, pParser uintptr) {
	var yytos, v1, v2 uintptr
	_, _, _ = yytos, v1, v2
	v2 = pParser
	v1 = *(*uintptr)(unsafe.Pointer(v2))
	*(*uintptr)(unsafe.Pointer(v2)) -= 12
	yytos = v1
	_yy_destructor(tls, pParser, (*TyyStackEntry)(unsafe.Pointer(yytos)).Fmajor, yytos+4)
}

func init() {
	p := unsafe.Pointer(&_aFunc)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_geopolyAreaFunc)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_geopolyBlobFunc)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_geopolyJsonFunc)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_geopolySvgFunc)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_geopolyWithinFunc)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_geopolyContainsPointFunc)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_geopolyOverlapFunc)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_geopolyDebugFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_geopolyBBoxFunc)
	*(*uintptr)(unsafe.Add(p, 108)) = __ccgo_fp(_geopolyXformFunc)
	*(*uintptr)(unsafe.Add(p, 120)) = __ccgo_fp(_geopolyRegularFunc)
	*(*uintptr)(unsafe.Add(p, 132)) = __ccgo_fp(_geopolyCcwFunc)
}

func init() {
	p := unsafe.Pointer(&_attach_func)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_attachFunc)
}

func init() {
	p := unsafe.Pointer(&_rbuvfs_io_methods1)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_rbuVfsClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_rbuVfsRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_rbuVfsWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rbuVfsTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rbuVfsSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rbuVfsFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rbuVfsLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rbuVfsUnlock)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rbuVfsCheckReservedLock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rbuVfsFileControl)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rbuVfsSectorSize)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rbuVfsDeviceCharacteristics)
}

func init() {
	p := unsafe.Pointer(&_dbstat_module)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_statConnect)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_statConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_statBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_statDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_statOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_statClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_statFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_statNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_statEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_statColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_statRowid)
}

/************** End of dbstat.c **********************************************/
/************** Begin file dbpage.c ******************************************/
/*
** 2017-10-11
**
** 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.
**
******************************************************************************
**
** This file contains an implementation of the "sqlite_dbpage" virtual table.
**
** The sqlite_dbpage virtual table is used to read or write whole raw
** pages of the database file.  The pager interface is used so that
** uncommitted changes and changes recorded in the WAL file are correctly
** retrieved.
**
** Usage example:
**
**    SELECT data FROM sqlite_dbpage('aux1') WHERE pgno=123;
**
** This is an eponymous virtual table so it does not need to be created before
** use.  The optional argument to the sqlite_dbpage() table name is the
** schema for the database file that is to be read.  The default schema is
** "main".
**
** The data field of sqlite_dbpage table can be updated.  The new
** value must be a BLOB which is the correct page size, otherwise the
** update fails.  INSERT operations also work, and operate as if they
** where REPLACE.  The size of the database can be extended by INSERT-ing
** new pages on the end.
**
** Rows may not be deleted.  However, doing an INSERT to page number N
** with NULL page data causes the N-th page and all subsequent pages to be
** deleted and the database to be truncated.
 */

/* #include "sqliteInt.h"   ** Requires access to internal data structures ** */

func init() {
	p := unsafe.Pointer(&_aJsonFunc)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_jsonArrayFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_jsonArrayFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_jsonArrayLengthFunc)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_jsonArrayLengthFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_jsonErrorFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(_jsonExtractFunc)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 616)) = __ccgo_fp(_jsonObjectFunc)
	*(*uintptr)(unsafe.Add(p, 656)) = __ccgo_fp(_jsonObjectFunc)
	*(*uintptr)(unsafe.Add(p, 696)) = __ccgo_fp(_jsonPatchFunc)
	*(*uintptr)(unsafe.Add(p, 736)) = __ccgo_fp(_jsonPatchFunc)
	*(*uintptr)(unsafe.Add(p, 776)) = __ccgo_fp(_jsonPrettyFunc)
	*(*uintptr)(unsafe.Add(p, 816)) = __ccgo_fp(_jsonPrettyFunc)
	*(*uintptr)(unsafe.Add(p, 856)) = __ccgo_fp(_jsonQuoteFunc)
	*(*uintptr)(unsafe.Add(p, 896)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 936)) = __ccgo_fp(_jsonRemoveFunc)
	*(*uintptr)(unsafe.Add(p, 976)) = __ccgo_fp(_jsonReplaceFunc)
	*(*uintptr)(unsafe.Add(p, 1016)) = __ccgo_fp(_jsonReplaceFunc)
	*(*uintptr)(unsafe.Add(p, 1056)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 1096)) = __ccgo_fp(_jsonSetFunc)
	*(*uintptr)(unsafe.Add(p, 1136)) = __ccgo_fp(_jsonTypeFunc)
	*(*uintptr)(unsafe.Add(p, 1176)) = __ccgo_fp(_jsonTypeFunc)
	*(*uintptr)(unsafe.Add(p, 1216)) = __ccgo_fp(_jsonValidFunc)
	*(*uintptr)(unsafe.Add(p, 1256)) = __ccgo_fp(_jsonValidFunc)
	*(*uintptr)(unsafe.Add(p, 1296)) = __ccgo_fp(_jsonArrayStep)
	*(*uintptr)(unsafe.Add(p, 1300)) = __ccgo_fp(_jsonArrayFinal)
	*(*uintptr)(unsafe.Add(p, 1304)) = __ccgo_fp(_jsonArrayValue)
	*(*uintptr)(unsafe.Add(p, 1308)) = __ccgo_fp(_jsonGroupInverse)
	*(*uintptr)(unsafe.Add(p, 1336)) = __ccgo_fp(_jsonArrayStep)
	*(*uintptr)(unsafe.Add(p, 1340)) = __ccgo_fp(_jsonArrayFinal)
	*(*uintptr)(unsafe.Add(p, 1344)) = __ccgo_fp(_jsonArrayValue)
	*(*uintptr)(unsafe.Add(p, 1348)) = __ccgo_fp(_jsonGroupInverse)
	*(*uintptr)(unsafe.Add(p, 1376)) = __ccgo_fp(_jsonObjectStep)
	*(*uintptr)(unsafe.Add(p, 1380)) = __ccgo_fp(_jsonObjectFinal)
	*(*uintptr)(unsafe.Add(p, 1384)) = __ccgo_fp(_jsonObjectValue)
	*(*uintptr)(unsafe.Add(p, 1388)) = __ccgo_fp(_jsonGroupInverse)
	*(*uintptr)(unsafe.Add(p, 1416)) = __ccgo_fp(_jsonObjectStep)
	*(*uintptr)(unsafe.Add(p, 1420)) = __ccgo_fp(_jsonObjectFinal)
	*(*uintptr)(unsafe.Add(p, 1424)) = __ccgo_fp(_jsonObjectValue)
	*(*uintptr)(unsafe.Add(p, 1428)) = __ccgo_fp(_jsonGroupInverse)
}

func init() {
	p := unsafe.Pointer(&_memdb_vfs)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_memdbOpen)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_memdbAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_memdbFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_memdbDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_memdbDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_memdbDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_memdbDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_memdbRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_memdbSleep)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_memdbGetLastError)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_memdbCurrentTimeInt64)
}

func init() {
	p := unsafe.Pointer(&_rbuvfs_io_methods)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_rbuVfsClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_rbuVfsRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_rbuVfsWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rbuVfsTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rbuVfsSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rbuVfsFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rbuVfsLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rbuVfsUnlock)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rbuVfsCheckReservedLock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rbuVfsFileControl)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rbuVfsSectorSize)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rbuVfsDeviceCharacteristics)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_rbuVfsShmMap)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rbuVfsShmLock)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rbuVfsShmBarrier)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rbuVfsShmUnmap)
}

func init() {
	p := unsafe.Pointer(&_dbpage_module)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_dbpageConnect)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_dbpageConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_dbpageBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_dbpageDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_dbpageDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_dbpageOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_dbpageClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_dbpageFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_dbpageNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_dbpageEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_dbpageColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_dbpageRowid)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_dbpageUpdate)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_dbpageBegin)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_dbpageSync)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_dbpageRollbackTo)
}

/************** End of dbpage.c **********************************************/
/************** Begin file carray.c ******************************************/
/*
** 2016-06-29
**
** 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.
**
*************************************************************************
**
** This file implements a table-valued-function that
** returns the values in a C-language array.
** Examples:
**
**      SELECT * FROM carray($ptr,5)
**
** The query above returns 5 integers contained in a C-language array
** at the address $ptr.  $ptr is a pointer to the array of integers.
** The pointer value must be assigned to $ptr using the
** sqlite3_bind_pointer() interface with a pointer type of "carray".
** For example:
**
**    static int aX[] = { 53, 9, 17, 2231, 4, 99 };
**    int i = sqlite3_bind_parameter_index(pStmt, "$ptr");
**    sqlite3_bind_pointer(pStmt, i, aX, "carray", 0);
**
** There is an optional third parameter to determine the datatype of
** the C-language array.  Allowed values of the third parameter are
** 'int32', 'int64', 'double', 'char*', 'struct iovec'.  Example:
**
**      SELECT * FROM carray($ptr,10,'char*');
**
** The default value of the third parameter is 'int32'.
**
** HOW IT WORKS
**
** The carray "function" is really a virtual table with the
** following schema:
**
**     CREATE TABLE carray(
**       value,
**       pointer HIDDEN,
**       count HIDDEN,
**       ctype TEXT HIDDEN
**     );
**
** If the hidden columns "pointer" and "count" are unconstrained, then
** the virtual table has no rows.  Otherwise, the virtual table interprets
** the integer value of "pointer" as a pointer to the array and "count"
** as the number of elements in the array.  The virtual table steps through
** the array, element by element.
 */

/************** End of carray.c **********************************************/
/************** Begin file sqlite3session.c **********************************/

/* #include "sqlite3session.h" */
/* #include <assert.h> */
/* #include <string.h> */

func init() {
	p := unsafe.Pointer(&_sqlite3BuiltinExtensions)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_sqlite3Fts5Init)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_sqlite3RtreeInit)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_sqlite3DbpageRegister)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_sqlite3DbstatRegister)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_sqlite3TestExtInit)
}

func init() {
	p := unsafe.Pointer(&_sqlite3Apis)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(Xsqlite3_aggregate_context)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(Xsqlite3_aggregate_count)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(Xsqlite3_bind_blob)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(Xsqlite3_bind_double)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(Xsqlite3_bind_int)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(Xsqlite3_bind_int64)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(Xsqlite3_bind_null)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(Xsqlite3_bind_parameter_count)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(Xsqlite3_bind_parameter_index)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(Xsqlite3_bind_parameter_name)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(Xsqlite3_bind_text)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(Xsqlite3_bind_text16)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(Xsqlite3_bind_value)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(Xsqlite3_busy_handler)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(Xsqlite3_busy_timeout)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(Xsqlite3_changes)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(Xsqlite3_close)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(Xsqlite3_collation_needed)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(Xsqlite3_collation_needed16)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(Xsqlite3_column_blob)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(Xsqlite3_column_bytes)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(Xsqlite3_column_bytes16)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(Xsqlite3_column_count)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(Xsqlite3_column_database_name)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(Xsqlite3_column_database_name16)
	*(*uintptr)(unsafe.Add(p, 100)) = __ccgo_fp(Xsqlite3_column_decltype)
	*(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(Xsqlite3_column_decltype16)
	*(*uintptr)(unsafe.Add(p, 108)) = __ccgo_fp(Xsqlite3_column_double)
	*(*uintptr)(unsafe.Add(p, 112)) = __ccgo_fp(Xsqlite3_column_int)
	*(*uintptr)(unsafe.Add(p, 116)) = __ccgo_fp(Xsqlite3_column_int64)
	*(*uintptr)(unsafe.Add(p, 120)) = __ccgo_fp(Xsqlite3_column_name)
	*(*uintptr)(unsafe.Add(p, 124)) = __ccgo_fp(Xsqlite3_column_name16)
	*(*uintptr)(unsafe.Add(p, 128)) = __ccgo_fp(Xsqlite3_column_origin_name)
	*(*uintptr)(unsafe.Add(p, 132)) = __ccgo_fp(Xsqlite3_column_origin_name16)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(Xsqlite3_column_table_name)
	*(*uintptr)(unsafe.Add(p, 140)) = __ccgo_fp(Xsqlite3_column_table_name16)
	*(*uintptr)(unsafe.Add(p, 144)) = __ccgo_fp(Xsqlite3_column_text)
	*(*uintptr)(unsafe.Add(p, 148)) = __ccgo_fp(Xsqlite3_column_text16)
	*(*uintptr)(unsafe.Add(p, 152)) = __ccgo_fp(Xsqlite3_column_type)
	*(*uintptr)(unsafe.Add(p, 156)) = __ccgo_fp(Xsqlite3_column_value)
	*(*uintptr)(unsafe.Add(p, 160)) = __ccgo_fp(Xsqlite3_commit_hook)
	*(*uintptr)(unsafe.Add(p, 164)) = __ccgo_fp(Xsqlite3_complete)
	*(*uintptr)(unsafe.Add(p, 168)) = __ccgo_fp(Xsqlite3_complete16)
	*(*uintptr)(unsafe.Add(p, 172)) = __ccgo_fp(Xsqlite3_create_collation)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(Xsqlite3_create_collation16)
	*(*uintptr)(unsafe.Add(p, 180)) = __ccgo_fp(Xsqlite3_create_function)
	*(*uintptr)(unsafe.Add(p, 184)) = __ccgo_fp(Xsqlite3_create_function16)
	*(*uintptr)(unsafe.Add(p, 188)) = __ccgo_fp(Xsqlite3_create_module)
	*(*uintptr)(unsafe.Add(p, 192)) = __ccgo_fp(Xsqlite3_data_count)
	*(*uintptr)(unsafe.Add(p, 196)) = __ccgo_fp(Xsqlite3_db_handle)
	*(*uintptr)(unsafe.Add(p, 200)) = __ccgo_fp(Xsqlite3_declare_vtab)
	*(*uintptr)(unsafe.Add(p, 204)) = __ccgo_fp(Xsqlite3_enable_shared_cache)
	*(*uintptr)(unsafe.Add(p, 208)) = __ccgo_fp(Xsqlite3_errcode)
	*(*uintptr)(unsafe.Add(p, 212)) = __ccgo_fp(Xsqlite3_errmsg)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(Xsqlite3_errmsg16)
	*(*uintptr)(unsafe.Add(p, 220)) = __ccgo_fp(Xsqlite3_exec)
	*(*uintptr)(unsafe.Add(p, 224)) = __ccgo_fp(Xsqlite3_expired)
	*(*uintptr)(unsafe.Add(p, 228)) = __ccgo_fp(Xsqlite3_finalize)
	*(*uintptr)(unsafe.Add(p, 232)) = __ccgo_fp(Xsqlite3_free)
	*(*uintptr)(unsafe.Add(p, 236)) = __ccgo_fp(Xsqlite3_free_table)
	*(*uintptr)(unsafe.Add(p, 240)) = __ccgo_fp(Xsqlite3_get_autocommit)
	*(*uintptr)(unsafe.Add(p, 244)) = __ccgo_fp(Xsqlite3_get_auxdata)
	*(*uintptr)(unsafe.Add(p, 248)) = __ccgo_fp(Xsqlite3_get_table)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(Xsqlite3_interrupt)
	*(*uintptr)(unsafe.Add(p, 260)) = __ccgo_fp(Xsqlite3_last_insert_rowid)
	*(*uintptr)(unsafe.Add(p, 264)) = __ccgo_fp(Xsqlite3_libversion)
	*(*uintptr)(unsafe.Add(p, 268)) = __ccgo_fp(Xsqlite3_libversion_number)
	*(*uintptr)(unsafe.Add(p, 272)) = __ccgo_fp(Xsqlite3_malloc)
	*(*uintptr)(unsafe.Add(p, 276)) = __ccgo_fp(Xsqlite3_mprintf)
	*(*uintptr)(unsafe.Add(p, 280)) = __ccgo_fp(Xsqlite3_open)
	*(*uintptr)(unsafe.Add(p, 284)) = __ccgo_fp(Xsqlite3_open16)
	*(*uintptr)(unsafe.Add(p, 288)) = __ccgo_fp(Xsqlite3_prepare)
	*(*uintptr)(unsafe.Add(p, 292)) = __ccgo_fp(Xsqlite3_prepare16)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(Xsqlite3_profile)
	*(*uintptr)(unsafe.Add(p, 300)) = __ccgo_fp(Xsqlite3_progress_handler)
	*(*uintptr)(unsafe.Add(p, 304)) = __ccgo_fp(Xsqlite3_realloc)
	*(*uintptr)(unsafe.Add(p, 308)) = __ccgo_fp(Xsqlite3_reset)
	*(*uintptr)(unsafe.Add(p, 312)) = __ccgo_fp(Xsqlite3_result_blob)
	*(*uintptr)(unsafe.Add(p, 316)) = __ccgo_fp(Xsqlite3_result_double)
	*(*uintptr)(unsafe.Add(p, 320)) = __ccgo_fp(Xsqlite3_result_error)
	*(*uintptr)(unsafe.Add(p, 324)) = __ccgo_fp(Xsqlite3_result_error16)
	*(*uintptr)(unsafe.Add(p, 328)) = __ccgo_fp(Xsqlite3_result_int)
	*(*uintptr)(unsafe.Add(p, 332)) = __ccgo_fp(Xsqlite3_result_int64)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(Xsqlite3_result_null)
	*(*uintptr)(unsafe.Add(p, 340)) = __ccgo_fp(Xsqlite3_result_text)
	*(*uintptr)(unsafe.Add(p, 344)) = __ccgo_fp(Xsqlite3_result_text16)
	*(*uintptr)(unsafe.Add(p, 348)) = __ccgo_fp(Xsqlite3_result_text16be)
	*(*uintptr)(unsafe.Add(p, 352)) = __ccgo_fp(Xsqlite3_result_text16le)
	*(*uintptr)(unsafe.Add(p, 356)) = __ccgo_fp(Xsqlite3_result_value)
	*(*uintptr)(unsafe.Add(p, 360)) = __ccgo_fp(Xsqlite3_rollback_hook)
	*(*uintptr)(unsafe.Add(p, 364)) = __ccgo_fp(Xsqlite3_set_authorizer)
	*(*uintptr)(unsafe.Add(p, 368)) = __ccgo_fp(Xsqlite3_set_auxdata)
	*(*uintptr)(unsafe.Add(p, 372)) = __ccgo_fp(Xsqlite3_snprintf)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(Xsqlite3_step)
	*(*uintptr)(unsafe.Add(p, 380)) = __ccgo_fp(Xsqlite3_table_column_metadata)
	*(*uintptr)(unsafe.Add(p, 384)) = __ccgo_fp(Xsqlite3_thread_cleanup)
	*(*uintptr)(unsafe.Add(p, 388)) = __ccgo_fp(Xsqlite3_total_changes)
	*(*uintptr)(unsafe.Add(p, 392)) = __ccgo_fp(Xsqlite3_trace)
	*(*uintptr)(unsafe.Add(p, 396)) = __ccgo_fp(Xsqlite3_transfer_bindings)
	*(*uintptr)(unsafe.Add(p, 400)) = __ccgo_fp(Xsqlite3_update_hook)
	*(*uintptr)(unsafe.Add(p, 404)) = __ccgo_fp(Xsqlite3_user_data)
	*(*uintptr)(unsafe.Add(p, 408)) = __ccgo_fp(Xsqlite3_value_blob)
	*(*uintptr)(unsafe.Add(p, 412)) = __ccgo_fp(Xsqlite3_value_bytes)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(Xsqlite3_value_bytes16)
	*(*uintptr)(unsafe.Add(p, 420)) = __ccgo_fp(Xsqlite3_value_double)
	*(*uintptr)(unsafe.Add(p, 424)) = __ccgo_fp(Xsqlite3_value_int)
	*(*uintptr)(unsafe.Add(p, 428)) = __ccgo_fp(Xsqlite3_value_int64)
	*(*uintptr)(unsafe.Add(p, 432)) = __ccgo_fp(Xsqlite3_value_numeric_type)
	*(*uintptr)(unsafe.Add(p, 436)) = __ccgo_fp(Xsqlite3_value_text)
	*(*uintptr)(unsafe.Add(p, 440)) = __ccgo_fp(Xsqlite3_value_text16)
	*(*uintptr)(unsafe.Add(p, 444)) = __ccgo_fp(Xsqlite3_value_text16be)
	*(*uintptr)(unsafe.Add(p, 448)) = __ccgo_fp(Xsqlite3_value_text16le)
	*(*uintptr)(unsafe.Add(p, 452)) = __ccgo_fp(Xsqlite3_value_type)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(Xsqlite3_vmprintf)
	*(*uintptr)(unsafe.Add(p, 460)) = __ccgo_fp(Xsqlite3_overload_function)
	*(*uintptr)(unsafe.Add(p, 464)) = __ccgo_fp(Xsqlite3_prepare_v2)
	*(*uintptr)(unsafe.Add(p, 468)) = __ccgo_fp(Xsqlite3_prepare16_v2)
	*(*uintptr)(unsafe.Add(p, 472)) = __ccgo_fp(Xsqlite3_clear_bindings)
	*(*uintptr)(unsafe.Add(p, 476)) = __ccgo_fp(Xsqlite3_create_module_v2)
	*(*uintptr)(unsafe.Add(p, 480)) = __ccgo_fp(Xsqlite3_bind_zeroblob)
	*(*uintptr)(unsafe.Add(p, 484)) = __ccgo_fp(Xsqlite3_blob_bytes)
	*(*uintptr)(unsafe.Add(p, 488)) = __ccgo_fp(Xsqlite3_blob_close)
	*(*uintptr)(unsafe.Add(p, 492)) = __ccgo_fp(Xsqlite3_blob_open)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(Xsqlite3_blob_read)
	*(*uintptr)(unsafe.Add(p, 500)) = __ccgo_fp(Xsqlite3_blob_write)
	*(*uintptr)(unsafe.Add(p, 504)) = __ccgo_fp(Xsqlite3_create_collation_v2)
	*(*uintptr)(unsafe.Add(p, 508)) = __ccgo_fp(Xsqlite3_file_control)
	*(*uintptr)(unsafe.Add(p, 512)) = __ccgo_fp(Xsqlite3_memory_highwater)
	*(*uintptr)(unsafe.Add(p, 516)) = __ccgo_fp(Xsqlite3_memory_used)
	*(*uintptr)(unsafe.Add(p, 520)) = __ccgo_fp(Xsqlite3_mutex_alloc)
	*(*uintptr)(unsafe.Add(p, 524)) = __ccgo_fp(Xsqlite3_mutex_enter)
	*(*uintptr)(unsafe.Add(p, 528)) = __ccgo_fp(Xsqlite3_mutex_free)
	*(*uintptr)(unsafe.Add(p, 532)) = __ccgo_fp(Xsqlite3_mutex_leave)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(Xsqlite3_mutex_try)
	*(*uintptr)(unsafe.Add(p, 540)) = __ccgo_fp(Xsqlite3_open_v2)
	*(*uintptr)(unsafe.Add(p, 544)) = __ccgo_fp(Xsqlite3_release_memory)
	*(*uintptr)(unsafe.Add(p, 548)) = __ccgo_fp(Xsqlite3_result_error_nomem)
	*(*uintptr)(unsafe.Add(p, 552)) = __ccgo_fp(Xsqlite3_result_error_toobig)
	*(*uintptr)(unsafe.Add(p, 556)) = __ccgo_fp(Xsqlite3_sleep)
	*(*uintptr)(unsafe.Add(p, 560)) = __ccgo_fp(Xsqlite3_soft_heap_limit)
	*(*uintptr)(unsafe.Add(p, 564)) = __ccgo_fp(Xsqlite3_vfs_find)
	*(*uintptr)(unsafe.Add(p, 568)) = __ccgo_fp(Xsqlite3_vfs_register)
	*(*uintptr)(unsafe.Add(p, 572)) = __ccgo_fp(Xsqlite3_vfs_unregister)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(Xsqlite3_threadsafe)
	*(*uintptr)(unsafe.Add(p, 580)) = __ccgo_fp(Xsqlite3_result_zeroblob)
	*(*uintptr)(unsafe.Add(p, 584)) = __ccgo_fp(Xsqlite3_result_error_code)
	*(*uintptr)(unsafe.Add(p, 588)) = __ccgo_fp(Xsqlite3_test_control)
	*(*uintptr)(unsafe.Add(p, 592)) = __ccgo_fp(Xsqlite3_randomness)
	*(*uintptr)(unsafe.Add(p, 596)) = __ccgo_fp(Xsqlite3_context_db_handle)
	*(*uintptr)(unsafe.Add(p, 600)) = __ccgo_fp(Xsqlite3_extended_result_codes)
	*(*uintptr)(unsafe.Add(p, 604)) = __ccgo_fp(Xsqlite3_limit)
	*(*uintptr)(unsafe.Add(p, 608)) = __ccgo_fp(Xsqlite3_next_stmt)
	*(*uintptr)(unsafe.Add(p, 612)) = __ccgo_fp(Xsqlite3_sql)
	*(*uintptr)(unsafe.Add(p, 616)) = __ccgo_fp(Xsqlite3_status)
	*(*uintptr)(unsafe.Add(p, 620)) = __ccgo_fp(Xsqlite3_backup_finish)
	*(*uintptr)(unsafe.Add(p, 624)) = __ccgo_fp(Xsqlite3_backup_init)
	*(*uintptr)(unsafe.Add(p, 628)) = __ccgo_fp(Xsqlite3_backup_pagecount)
	*(*uintptr)(unsafe.Add(p, 632)) = __ccgo_fp(Xsqlite3_backup_remaining)
	*(*uintptr)(unsafe.Add(p, 636)) = __ccgo_fp(Xsqlite3_backup_step)
	*(*uintptr)(unsafe.Add(p, 640)) = __ccgo_fp(Xsqlite3_compileoption_get)
	*(*uintptr)(unsafe.Add(p, 644)) = __ccgo_fp(Xsqlite3_compileoption_used)
	*(*uintptr)(unsafe.Add(p, 648)) = __ccgo_fp(Xsqlite3_create_function_v2)
	*(*uintptr)(unsafe.Add(p, 652)) = __ccgo_fp(Xsqlite3_db_config)
	*(*uintptr)(unsafe.Add(p, 656)) = __ccgo_fp(Xsqlite3_db_mutex)
	*(*uintptr)(unsafe.Add(p, 660)) = __ccgo_fp(Xsqlite3_db_status)
	*(*uintptr)(unsafe.Add(p, 664)) = __ccgo_fp(Xsqlite3_extended_errcode)
	*(*uintptr)(unsafe.Add(p, 668)) = __ccgo_fp(Xsqlite3_log)
	*(*uintptr)(unsafe.Add(p, 672)) = __ccgo_fp(Xsqlite3_soft_heap_limit64)
	*(*uintptr)(unsafe.Add(p, 676)) = __ccgo_fp(Xsqlite3_sourceid)
	*(*uintptr)(unsafe.Add(p, 680)) = __ccgo_fp(Xsqlite3_stmt_status)
	*(*uintptr)(unsafe.Add(p, 684)) = __ccgo_fp(Xsqlite3_strnicmp)
	*(*uintptr)(unsafe.Add(p, 688)) = __ccgo_fp(Xsqlite3_unlock_notify)
	*(*uintptr)(unsafe.Add(p, 692)) = __ccgo_fp(Xsqlite3_wal_autocheckpoint)
	*(*uintptr)(unsafe.Add(p, 696)) = __ccgo_fp(Xsqlite3_wal_checkpoint)
	*(*uintptr)(unsafe.Add(p, 700)) = __ccgo_fp(Xsqlite3_wal_hook)
	*(*uintptr)(unsafe.Add(p, 704)) = __ccgo_fp(Xsqlite3_blob_reopen)
	*(*uintptr)(unsafe.Add(p, 708)) = __ccgo_fp(Xsqlite3_vtab_config)
	*(*uintptr)(unsafe.Add(p, 712)) = __ccgo_fp(Xsqlite3_vtab_on_conflict)
	*(*uintptr)(unsafe.Add(p, 716)) = __ccgo_fp(Xsqlite3_close_v2)
	*(*uintptr)(unsafe.Add(p, 720)) = __ccgo_fp(Xsqlite3_db_filename)
	*(*uintptr)(unsafe.Add(p, 724)) = __ccgo_fp(Xsqlite3_db_readonly)
	*(*uintptr)(unsafe.Add(p, 728)) = __ccgo_fp(Xsqlite3_db_release_memory)
	*(*uintptr)(unsafe.Add(p, 732)) = __ccgo_fp(Xsqlite3_errstr)
	*(*uintptr)(unsafe.Add(p, 736)) = __ccgo_fp(Xsqlite3_stmt_busy)
	*(*uintptr)(unsafe.Add(p, 740)) = __ccgo_fp(Xsqlite3_stmt_readonly)
	*(*uintptr)(unsafe.Add(p, 744)) = __ccgo_fp(Xsqlite3_stricmp)
	*(*uintptr)(unsafe.Add(p, 748)) = __ccgo_fp(Xsqlite3_uri_boolean)
	*(*uintptr)(unsafe.Add(p, 752)) = __ccgo_fp(Xsqlite3_uri_int64)
	*(*uintptr)(unsafe.Add(p, 756)) = __ccgo_fp(Xsqlite3_uri_parameter)
	*(*uintptr)(unsafe.Add(p, 760)) = __ccgo_fp(Xsqlite3_vsnprintf)
	*(*uintptr)(unsafe.Add(p, 764)) = __ccgo_fp(Xsqlite3_wal_checkpoint_v2)
	*(*uintptr)(unsafe.Add(p, 768)) = __ccgo_fp(Xsqlite3_auto_extension)
	*(*uintptr)(unsafe.Add(p, 772)) = __ccgo_fp(Xsqlite3_bind_blob64)
	*(*uintptr)(unsafe.Add(p, 776)) = __ccgo_fp(Xsqlite3_bind_text64)
	*(*uintptr)(unsafe.Add(p, 780)) = __ccgo_fp(Xsqlite3_cancel_auto_extension)
	*(*uintptr)(unsafe.Add(p, 784)) = __ccgo_fp(Xsqlite3_load_extension)
	*(*uintptr)(unsafe.Add(p, 788)) = __ccgo_fp(Xsqlite3_malloc64)
	*(*uintptr)(unsafe.Add(p, 792)) = __ccgo_fp(Xsqlite3_msize)
	*(*uintptr)(unsafe.Add(p, 796)) = __ccgo_fp(Xsqlite3_realloc64)
	*(*uintptr)(unsafe.Add(p, 800)) = __ccgo_fp(Xsqlite3_reset_auto_extension)
	*(*uintptr)(unsafe.Add(p, 804)) = __ccgo_fp(Xsqlite3_result_blob64)
	*(*uintptr)(unsafe.Add(p, 808)) = __ccgo_fp(Xsqlite3_result_text64)
	*(*uintptr)(unsafe.Add(p, 812)) = __ccgo_fp(Xsqlite3_strglob)
	*(*uintptr)(unsafe.Add(p, 816)) = __ccgo_fp(Xsqlite3_value_dup)
	*(*uintptr)(unsafe.Add(p, 820)) = __ccgo_fp(Xsqlite3_value_free)
	*(*uintptr)(unsafe.Add(p, 824)) = __ccgo_fp(Xsqlite3_result_zeroblob64)
	*(*uintptr)(unsafe.Add(p, 828)) = __ccgo_fp(Xsqlite3_bind_zeroblob64)
	*(*uintptr)(unsafe.Add(p, 832)) = __ccgo_fp(Xsqlite3_value_subtype)
	*(*uintptr)(unsafe.Add(p, 836)) = __ccgo_fp(Xsqlite3_result_subtype)
	*(*uintptr)(unsafe.Add(p, 840)) = __ccgo_fp(Xsqlite3_status64)
	*(*uintptr)(unsafe.Add(p, 844)) = __ccgo_fp(Xsqlite3_strlike)
	*(*uintptr)(unsafe.Add(p, 848)) = __ccgo_fp(Xsqlite3_db_cacheflush)
	*(*uintptr)(unsafe.Add(p, 852)) = __ccgo_fp(Xsqlite3_system_errno)
	*(*uintptr)(unsafe.Add(p, 856)) = __ccgo_fp(Xsqlite3_trace_v2)
	*(*uintptr)(unsafe.Add(p, 860)) = __ccgo_fp(Xsqlite3_expanded_sql)
	*(*uintptr)(unsafe.Add(p, 864)) = __ccgo_fp(Xsqlite3_set_last_insert_rowid)
	*(*uintptr)(unsafe.Add(p, 868)) = __ccgo_fp(Xsqlite3_prepare_v3)
	*(*uintptr)(unsafe.Add(p, 872)) = __ccgo_fp(Xsqlite3_prepare16_v3)
	*(*uintptr)(unsafe.Add(p, 876)) = __ccgo_fp(Xsqlite3_bind_pointer)
	*(*uintptr)(unsafe.Add(p, 880)) = __ccgo_fp(Xsqlite3_result_pointer)
	*(*uintptr)(unsafe.Add(p, 884)) = __ccgo_fp(Xsqlite3_value_pointer)
	*(*uintptr)(unsafe.Add(p, 888)) = __ccgo_fp(Xsqlite3_vtab_nochange)
	*(*uintptr)(unsafe.Add(p, 892)) = __ccgo_fp(Xsqlite3_value_nochange)
	*(*uintptr)(unsafe.Add(p, 896)) = __ccgo_fp(Xsqlite3_vtab_collation)
	*(*uintptr)(unsafe.Add(p, 900)) = __ccgo_fp(Xsqlite3_keyword_count)
	*(*uintptr)(unsafe.Add(p, 904)) = __ccgo_fp(Xsqlite3_keyword_name)
	*(*uintptr)(unsafe.Add(p, 908)) = __ccgo_fp(Xsqlite3_keyword_check)
	*(*uintptr)(unsafe.Add(p, 912)) = __ccgo_fp(Xsqlite3_str_new)
	*(*uintptr)(unsafe.Add(p, 916)) = __ccgo_fp(Xsqlite3_str_finish)
	*(*uintptr)(unsafe.Add(p, 920)) = __ccgo_fp(Xsqlite3_str_appendf)
	*(*uintptr)(unsafe.Add(p, 924)) = __ccgo_fp(Xsqlite3_str_vappendf)
	*(*uintptr)(unsafe.Add(p, 928)) = __ccgo_fp(Xsqlite3_str_append)
	*(*uintptr)(unsafe.Add(p, 932)) = __ccgo_fp(Xsqlite3_str_appendall)
	*(*uintptr)(unsafe.Add(p, 936)) = __ccgo_fp(Xsqlite3_str_appendchar)
	*(*uintptr)(unsafe.Add(p, 940)) = __ccgo_fp(Xsqlite3_str_reset)
	*(*uintptr)(unsafe.Add(p, 944)) = __ccgo_fp(Xsqlite3_str_errcode)
	*(*uintptr)(unsafe.Add(p, 948)) = __ccgo_fp(Xsqlite3_str_length)
	*(*uintptr)(unsafe.Add(p, 952)) = __ccgo_fp(Xsqlite3_str_value)
	*(*uintptr)(unsafe.Add(p, 956)) = __ccgo_fp(Xsqlite3_create_window_function)
	*(*uintptr)(unsafe.Add(p, 964)) = __ccgo_fp(Xsqlite3_stmt_isexplain)
	*(*uintptr)(unsafe.Add(p, 968)) = __ccgo_fp(Xsqlite3_value_frombind)
	*(*uintptr)(unsafe.Add(p, 972)) = __ccgo_fp(Xsqlite3_drop_modules)
	*(*uintptr)(unsafe.Add(p, 976)) = __ccgo_fp(Xsqlite3_hard_heap_limit64)
	*(*uintptr)(unsafe.Add(p, 980)) = __ccgo_fp(Xsqlite3_uri_key)
	*(*uintptr)(unsafe.Add(p, 984)) = __ccgo_fp(Xsqlite3_filename_database)
	*(*uintptr)(unsafe.Add(p, 988)) = __ccgo_fp(Xsqlite3_filename_journal)
	*(*uintptr)(unsafe.Add(p, 992)) = __ccgo_fp(Xsqlite3_filename_wal)
	*(*uintptr)(unsafe.Add(p, 996)) = __ccgo_fp(Xsqlite3_create_filename)
	*(*uintptr)(unsafe.Add(p, 1000)) = __ccgo_fp(Xsqlite3_free_filename)
	*(*uintptr)(unsafe.Add(p, 1004)) = __ccgo_fp(Xsqlite3_database_file_object)
	*(*uintptr)(unsafe.Add(p, 1008)) = __ccgo_fp(Xsqlite3_txn_state)
	*(*uintptr)(unsafe.Add(p, 1012)) = __ccgo_fp(Xsqlite3_changes64)
	*(*uintptr)(unsafe.Add(p, 1016)) = __ccgo_fp(Xsqlite3_total_changes64)
	*(*uintptr)(unsafe.Add(p, 1020)) = __ccgo_fp(Xsqlite3_autovacuum_pages)
	*(*uintptr)(unsafe.Add(p, 1024)) = __ccgo_fp(Xsqlite3_error_offset)
	*(*uintptr)(unsafe.Add(p, 1028)) = __ccgo_fp(Xsqlite3_vtab_rhs_value)
	*(*uintptr)(unsafe.Add(p, 1032)) = __ccgo_fp(Xsqlite3_vtab_distinct)
	*(*uintptr)(unsafe.Add(p, 1036)) = __ccgo_fp(Xsqlite3_vtab_in)
	*(*uintptr)(unsafe.Add(p, 1040)) = __ccgo_fp(Xsqlite3_vtab_in_first)
	*(*uintptr)(unsafe.Add(p, 1044)) = __ccgo_fp(Xsqlite3_vtab_in_next)
	*(*uintptr)(unsafe.Add(p, 1048)) = __ccgo_fp(Xsqlite3_deserialize)
	*(*uintptr)(unsafe.Add(p, 1052)) = __ccgo_fp(Xsqlite3_serialize)
	*(*uintptr)(unsafe.Add(p, 1056)) = __ccgo_fp(Xsqlite3_db_name)
	*(*uintptr)(unsafe.Add(p, 1060)) = __ccgo_fp(Xsqlite3_value_encoding)
	*(*uintptr)(unsafe.Add(p, 1064)) = __ccgo_fp(Xsqlite3_is_interrupted)
	*(*uintptr)(unsafe.Add(p, 1068)) = __ccgo_fp(Xsqlite3_stmt_explain)
	*(*uintptr)(unsafe.Add(p, 1072)) = __ccgo_fp(Xsqlite3_get_clientdata)
	*(*uintptr)(unsafe.Add(p, 1076)) = __ccgo_fp(Xsqlite3_set_clientdata)
	*(*uintptr)(unsafe.Add(p, 1080)) = __ccgo_fp(Xsqlite3_setlk_timeout)
	*(*uintptr)(unsafe.Add(p, 1084)) = __ccgo_fp(Xsqlite3_set_errmsg)
	*(*uintptr)(unsafe.Add(p, 1088)) = __ccgo_fp(Xsqlite3_db_status64)
	*(*uintptr)(unsafe.Add(p, 1092)) = __ccgo_fp(Xsqlite3_str_truncate)
	*(*uintptr)(unsafe.Add(p, 1096)) = __ccgo_fp(Xsqlite3_str_free)
}

/* True if x is the directory separator character
 */

func init() {
	p := unsafe.Pointer(&_MemJournalMethods)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_memjrnlClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_memjrnlRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_memjrnlWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_memjrnlTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_memjrnlSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_memjrnlFileSize)
}

func init() {
	p := unsafe.Pointer(&_aDateTimeFuncs)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_juliandayFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_unixepochFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_dateFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_timeFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_datetimeFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_strftimeFunc)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_timediffFunc)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_ctimeFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_ctimestampFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_cdateFunc)
}

/************** End of date.c ************************************************/
/************** Begin file os.c **********************************************/
/*
** 2005 November 29
**
** 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.
**
******************************************************************************
**
** This file contains OS interface code that is common to all
** architectures.
 */
/* #include "sqliteInt.h" */

/*
** If we compile with the SQLITE_TEST macro set, then the following block
** of code will give us the ability to simulate a disk I/O error.  This
** is used for testing the I/O recovery logic.
 */

/*
** When testing, also keep a count of the number of open files.
 */

/*
** The default SQLite sqlite3_vfs implementations do not allocate
** memory (actually, os_unix.c allocates a small amount of memory
** from within OsOpen()), but some third-party implementations may.
** So we test the effects of a malloc() failing and the sqlite3OsXXX()
** function returning SQLITE_IOERR_NOMEM using the DO_OS_MALLOC_TEST macro.
**
** The following functions are instrumented for malloc() failure
** testing:
**
**     sqlite3OsRead()
**     sqlite3OsWrite()
**     sqlite3OsSync()
**     sqlite3OsFileSize()
**     sqlite3OsLock()
**     sqlite3OsCheckReservedLock()
**     sqlite3OsFileControl()
**     sqlite3OsShmMap()
**     sqlite3OsOpen()
**     sqlite3OsDelete()
**     sqlite3OsAccess()
**     sqlite3OsFullPathname()
**
 */

func init() {
	p := unsafe.Pointer(&_vfs_template)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rbuVfsOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rbuVfsDelete)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rbuVfsAccess)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rbuVfsFullPathname)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rbuVfsDlOpen)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rbuVfsDlError)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rbuVfsDlSym)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_rbuVfsDlClose)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rbuVfsRandomness)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rbuVfsSleep)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rbuVfsCurrentTime)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_rbuVfsGetLastError)
}

func init() {
	p := unsafe.Pointer(&_detach_func)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_detachFunc)
}

func init() {
	p := unsafe.Pointer(&_aAlterTableFuncs)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_renameColumnFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_renameTableFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_renameTableTest)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_dropColumnFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_renameQuotefixFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_dropConstraintFunc)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_failConstraintFunc)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_addConstraintFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_findConstraintFunc)
}

/************** End of alter.c ***********************************************/
/************** Begin file analyze.c *****************************************/
/*
** 2005-07-08
**
** 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.
**
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
** The ANALYZE command gather statistics about the content of tables
** and indices.  These statistics are made available to the query planner
** to help it make better decisions about how to perform queries.
**
** The following system tables are or have been supported:
**
**    CREATE TABLE sqlite_stat1(tbl, idx, stat);
**    CREATE TABLE sqlite_stat2(tbl, idx, sampleno, sample);
**    CREATE TABLE sqlite_stat3(tbl, idx, nEq, nLt, nDLt, sample);
**    CREATE TABLE sqlite_stat4(tbl, idx, nEq, nLt, nDLt, sample);
**
** Additional tables might be added in future releases of SQLite.
** The sqlite_stat2 table is not created or used unless the SQLite version
** is between 3.6.18 and 3.7.8, inclusive, and unless SQLite is compiled
** with SQLITE_ENABLE_STAT2.  The sqlite_stat2 table is deprecated.
** The sqlite_stat2 table is superseded by sqlite_stat3, which is only
** created and used by SQLite versions 3.7.9 through 3.29.0 when
** SQLITE_ENABLE_STAT3 defined.  The functionality of sqlite_stat3
** is a superset of sqlite_stat2 and is also now deprecated.  The
** sqlite_stat4 is an enhanced version of sqlite_stat3 and is only
** available when compiled with SQLITE_ENABLE_STAT4 and in SQLite
** versions 3.8.1 and later.  STAT4 is the only variant that is still
** supported.
**
** For most applications, sqlite_stat1 provides all the statistics required
** for the query planner to make good choices.
**
** Format of sqlite_stat1:
**
** There is normally one row per index, with the index identified by the
** name in the idx column.  The tbl column is the name of the table to
** which the index belongs.  In each such row, the stat column will be
** a string consisting of a list of integers.  The first integer in this
** list is the number of rows in the index.  (This is the same as the
** number of rows in the table, except for partial indices.)  The second
** integer is the average number of rows in the index that have the same
** value in the first column of the index.  The third integer is the average
** number of rows in the index that have the same value for the first two
** columns.  The N-th integer (for N>1) is the average number of rows in
** the index which have the same value for the first N-1 columns.  For
** a K-column index, there will be K+1 integers in the stat column.  If
** the index is unique, then the last integer will be 1.
**
** The list of integers in the stat column can optionally be followed
** by the keyword "unordered".  The "unordered" keyword, if it is present,
** must be separated from the last integer by a single space.  If the
** "unordered" keyword is present, then the query planner assumes that
** the index is unordered and will not use the index for a range query.
**
** If the sqlite_stat1.idx column is NULL, then the sqlite_stat1.stat
** column contains a single integer which is the (estimated) number of
** rows in the table identified by sqlite_stat1.tbl.
**
** Format of sqlite_stat2:
**
** The sqlite_stat2 is only created and is only used if SQLite is compiled
** with SQLITE_ENABLE_STAT2 and if the SQLite version number is between
** 3.6.18 and 3.7.8.  The "stat2" table contains additional information
** about the distribution of keys within an index.  The index is identified by
** the "idx" column and the "tbl" column is the name of the table to which
** the index belongs.  There are usually 10 rows in the sqlite_stat2
** table for each index.
**
** The sqlite_stat2 entries for an index that have sampleno between 0 and 9
** inclusive are samples of the left-most key value in the index taken at
** evenly spaced points along the index.  Let the number of samples be S
** (10 in the standard build) and let C be the number of rows in the index.
** Then the sampled rows are given by:
**
**     rownumber = (i*C*2 + C)/(S*2)
**
** For i between 0 and S-1.  Conceptually, the index space is divided into
** S uniform buckets and the samples are the middle row from each bucket.
**
** The format for sqlite_stat2 is recorded here for legacy reference.  This
** version of SQLite does not support sqlite_stat2.  It neither reads nor
** writes the sqlite_stat2 table.  This version of SQLite only supports
** sqlite_stat3.
**
** Format for sqlite_stat3:
**
** The sqlite_stat3 format is a subset of sqlite_stat4.  Hence, the
** sqlite_stat4 format will be described first.  Further information
** about sqlite_stat3 follows the sqlite_stat4 description.
**
** Format for sqlite_stat4:
**
** As with sqlite_stat2, the sqlite_stat4 table contains histogram data
** to aid the query planner in choosing good indices based on the values
** that indexed columns are compared against in the WHERE clauses of
** queries.
**
** The sqlite_stat4 table contains multiple entries for each index.
** The idx column names the index and the tbl column is the table of the
** index.  If the idx and tbl columns are the same, then the sample is
** of the INTEGER PRIMARY KEY.  The sample column is a blob which is the
** binary encoding of a key from the index.  The nEq column is a
** list of integers.  The first integer is the approximate number
** of entries in the index whose left-most column exactly matches
** the left-most column of the sample.  The second integer in nEq
** is the approximate number of entries in the index where the
** first two columns match the first two columns of the sample.
** And so forth.  nLt is another list of integers that show the approximate
** number of entries that are strictly less than the sample.  The first
** integer in nLt contains the number of entries in the index where the
** left-most column is less than the left-most column of the sample.
** The K-th integer in the nLt entry is the number of index entries
** where the first K columns are less than the first K columns of the
** sample.  The nDLt column is like nLt except that it contains the
** number of distinct entries in the index that are less than the
** sample.
**
** There can be an arbitrary number of sqlite_stat4 entries per index.
** The ANALYZE command will typically generate sqlite_stat4 tables
** that contain between 10 and 40 samples which are distributed across
** the key space, though not uniformly, and which include samples with
** large nEq values.
**
** Format for sqlite_stat3 redux:
**
** The sqlite_stat3 table is like sqlite_stat4 except that it only
** looks at the left-most column of the index.  The sqlite_stat3.sample
** column contains the actual value of the left-most column instead
** of a blob encoding of the complete index key as is found in
** sqlite_stat4.sample.  The nEq, nLt, and nDLt entries of sqlite_stat3
** all contain just a single integer which is the same as the first
** integer in the equivalent columns in sqlite_stat4.
 */
/* #include "sqliteInt.h" */

func init() {
	p := unsafe.Pointer(&_geopolyModule)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_geopolyCreate)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_geopolyConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_geopolyBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rtreeDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rtreeDestroy)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rtreeOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rtreeClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_geopolyFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rtreeNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rtreeEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_geopolyColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rtreeRowid)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_geopolyUpdate)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rtreeBeginTransaction)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_geopolyFindFunction)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_rtreeRename)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_rtreeSavepoint)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_rtreeShadowName)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_rtreeIntegrity)
}

func init() {
	p := unsafe.Pointer(&_aBuiltinFunc)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_soundexFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_loadExt)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_loadExt)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_compileoptionusedFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_compileoptiongetFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 616)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 656)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 696)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 736)) = __ccgo_fp(_trimFunc)
	*(*uintptr)(unsafe.Add(p, 776)) = __ccgo_fp(_minmaxFunc)
	*(*uintptr)(unsafe.Add(p, 816)) = __ccgo_fp(_minmaxStep)
	*(*uintptr)(unsafe.Add(p, 820)) = __ccgo_fp(_minMaxFinalize)
	*(*uintptr)(unsafe.Add(p, 824)) = __ccgo_fp(_minMaxValue)
	*(*uintptr)(unsafe.Add(p, 856)) = __ccgo_fp(_minmaxFunc)
	*(*uintptr)(unsafe.Add(p, 896)) = __ccgo_fp(_minmaxStep)
	*(*uintptr)(unsafe.Add(p, 900)) = __ccgo_fp(_minMaxFinalize)
	*(*uintptr)(unsafe.Add(p, 904)) = __ccgo_fp(_minMaxValue)
	*(*uintptr)(unsafe.Add(p, 936)) = __ccgo_fp(_typeofFunc)
	*(*uintptr)(unsafe.Add(p, 976)) = __ccgo_fp(_subtypeFunc)
	*(*uintptr)(unsafe.Add(p, 1016)) = __ccgo_fp(_lengthFunc)
	*(*uintptr)(unsafe.Add(p, 1056)) = __ccgo_fp(_bytelengthFunc)
	*(*uintptr)(unsafe.Add(p, 1096)) = __ccgo_fp(_instrFunc)
	*(*uintptr)(unsafe.Add(p, 1136)) = __ccgo_fp(_printfFunc)
	*(*uintptr)(unsafe.Add(p, 1176)) = __ccgo_fp(_printfFunc)
	*(*uintptr)(unsafe.Add(p, 1216)) = __ccgo_fp(_unicodeFunc)
	*(*uintptr)(unsafe.Add(p, 1256)) = __ccgo_fp(_charFunc)
	*(*uintptr)(unsafe.Add(p, 1296)) = __ccgo_fp(_absFunc)
	*(*uintptr)(unsafe.Add(p, 1336)) = __ccgo_fp(_roundFunc)
	*(*uintptr)(unsafe.Add(p, 1376)) = __ccgo_fp(_roundFunc)
	*(*uintptr)(unsafe.Add(p, 1416)) = __ccgo_fp(_upperFunc)
	*(*uintptr)(unsafe.Add(p, 1456)) = __ccgo_fp(_lowerFunc)
	*(*uintptr)(unsafe.Add(p, 1496)) = __ccgo_fp(_hexFunc)
	*(*uintptr)(unsafe.Add(p, 1536)) = __ccgo_fp(_unhexFunc)
	*(*uintptr)(unsafe.Add(p, 1576)) = __ccgo_fp(_unhexFunc)
	*(*uintptr)(unsafe.Add(p, 1616)) = __ccgo_fp(_concatFunc)
	*(*uintptr)(unsafe.Add(p, 1656)) = __ccgo_fp(_concatwsFunc)
	*(*uintptr)(unsafe.Add(p, 1696)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 1736)) = __ccgo_fp(_randomFunc)
	*(*uintptr)(unsafe.Add(p, 1776)) = __ccgo_fp(_randomBlob)
	*(*uintptr)(unsafe.Add(p, 1816)) = __ccgo_fp(_nullifFunc)
	*(*uintptr)(unsafe.Add(p, 1856)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 1896)) = __ccgo_fp(_sourceidFunc)
	*(*uintptr)(unsafe.Add(p, 1936)) = __ccgo_fp(_errlogFunc)
	*(*uintptr)(unsafe.Add(p, 1976)) = __ccgo_fp(_unistrFunc)
	*(*uintptr)(unsafe.Add(p, 2016)) = __ccgo_fp(_quoteFunc)
	*(*uintptr)(unsafe.Add(p, 2056)) = __ccgo_fp(_quoteFunc)
	*(*uintptr)(unsafe.Add(p, 2096)) = __ccgo_fp(_last_insert_rowid)
	*(*uintptr)(unsafe.Add(p, 2136)) = __ccgo_fp(_changes)
	*(*uintptr)(unsafe.Add(p, 2176)) = __ccgo_fp(_total_changes)
	*(*uintptr)(unsafe.Add(p, 2216)) = __ccgo_fp(_replaceFunc)
	*(*uintptr)(unsafe.Add(p, 2256)) = __ccgo_fp(_zeroblobFunc)
	*(*uintptr)(unsafe.Add(p, 2296)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2336)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2376)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2416)) = __ccgo_fp(_substrFunc)
	*(*uintptr)(unsafe.Add(p, 2456)) = __ccgo_fp(_sumStep)
	*(*uintptr)(unsafe.Add(p, 2460)) = __ccgo_fp(_sumFinalize)
	*(*uintptr)(unsafe.Add(p, 2464)) = __ccgo_fp(_sumFinalize)
	*(*uintptr)(unsafe.Add(p, 2468)) = __ccgo_fp(_sumInverse)
	*(*uintptr)(unsafe.Add(p, 2496)) = __ccgo_fp(_sumStep)
	*(*uintptr)(unsafe.Add(p, 2500)) = __ccgo_fp(_totalFinalize)
	*(*uintptr)(unsafe.Add(p, 2504)) = __ccgo_fp(_totalFinalize)
	*(*uintptr)(unsafe.Add(p, 2508)) = __ccgo_fp(_sumInverse)
	*(*uintptr)(unsafe.Add(p, 2536)) = __ccgo_fp(_sumStep)
	*(*uintptr)(unsafe.Add(p, 2540)) = __ccgo_fp(_avgFinalize)
	*(*uintptr)(unsafe.Add(p, 2544)) = __ccgo_fp(_avgFinalize)
	*(*uintptr)(unsafe.Add(p, 2548)) = __ccgo_fp(_sumInverse)
	*(*uintptr)(unsafe.Add(p, 2576)) = __ccgo_fp(_countStep)
	*(*uintptr)(unsafe.Add(p, 2580)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2584)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2588)) = __ccgo_fp(_countInverse)
	*(*uintptr)(unsafe.Add(p, 2616)) = __ccgo_fp(_countStep)
	*(*uintptr)(unsafe.Add(p, 2620)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2624)) = __ccgo_fp(_countFinalize)
	*(*uintptr)(unsafe.Add(p, 2628)) = __ccgo_fp(_countInverse)
	*(*uintptr)(unsafe.Add(p, 2656)) = __ccgo_fp(_groupConcatStep)
	*(*uintptr)(unsafe.Add(p, 2660)) = __ccgo_fp(_groupConcatFinalize)
	*(*uintptr)(unsafe.Add(p, 2664)) = __ccgo_fp(_groupConcatValue)
	*(*uintptr)(unsafe.Add(p, 2668)) = __ccgo_fp(_groupConcatInverse)
	*(*uintptr)(unsafe.Add(p, 2696)) = __ccgo_fp(_groupConcatStep)
	*(*uintptr)(unsafe.Add(p, 2700)) = __ccgo_fp(_groupConcatFinalize)
	*(*uintptr)(unsafe.Add(p, 2704)) = __ccgo_fp(_groupConcatValue)
	*(*uintptr)(unsafe.Add(p, 2708)) = __ccgo_fp(_groupConcatInverse)
	*(*uintptr)(unsafe.Add(p, 2736)) = __ccgo_fp(_groupConcatStep)
	*(*uintptr)(unsafe.Add(p, 2740)) = __ccgo_fp(_groupConcatFinalize)
	*(*uintptr)(unsafe.Add(p, 2744)) = __ccgo_fp(_groupConcatValue)
	*(*uintptr)(unsafe.Add(p, 2748)) = __ccgo_fp(_groupConcatInverse)
	*(*uintptr)(unsafe.Add(p, 2776)) = __ccgo_fp(_likeFunc)
	*(*uintptr)(unsafe.Add(p, 2816)) = __ccgo_fp(_likeFunc)
	*(*uintptr)(unsafe.Add(p, 2856)) = __ccgo_fp(_likeFunc)
	*(*uintptr)(unsafe.Add(p, 2888)) = __ccgo_fp(_xCeil)
	*(*uintptr)(unsafe.Add(p, 2896)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 2928)) = __ccgo_fp(_xCeil)
	*(*uintptr)(unsafe.Add(p, 2936)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 2968)) = __ccgo_fp(_xFloor)
	*(*uintptr)(unsafe.Add(p, 2976)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 3008)) = __ccgo_fp(libc.Xtrunc)
	*(*uintptr)(unsafe.Add(p, 3016)) = __ccgo_fp(_ceilingFunc)
	*(*uintptr)(unsafe.Add(p, 3056)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3096)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3136)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3176)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3216)) = __ccgo_fp(_logFunc)
	*(*uintptr)(unsafe.Add(p, 3248)) = __ccgo_fp(libc.Xexp)
	*(*uintptr)(unsafe.Add(p, 3256)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3288)) = __ccgo_fp(libc.Xpow)
	*(*uintptr)(unsafe.Add(p, 3296)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3328)) = __ccgo_fp(libc.Xpow)
	*(*uintptr)(unsafe.Add(p, 3336)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3368)) = __ccgo_fp(libc.Xfmod)
	*(*uintptr)(unsafe.Add(p, 3376)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3408)) = __ccgo_fp(libc.Xacos)
	*(*uintptr)(unsafe.Add(p, 3416)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3448)) = __ccgo_fp(libc.Xasin)
	*(*uintptr)(unsafe.Add(p, 3456)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3488)) = __ccgo_fp(libc.Xatan)
	*(*uintptr)(unsafe.Add(p, 3496)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3528)) = __ccgo_fp(libc.Xatan2)
	*(*uintptr)(unsafe.Add(p, 3536)) = __ccgo_fp(_math2Func)
	*(*uintptr)(unsafe.Add(p, 3568)) = __ccgo_fp(libc.Xcos)
	*(*uintptr)(unsafe.Add(p, 3576)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3608)) = __ccgo_fp(libc.Xsin)
	*(*uintptr)(unsafe.Add(p, 3616)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3648)) = __ccgo_fp(libc.Xtan)
	*(*uintptr)(unsafe.Add(p, 3656)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3688)) = __ccgo_fp(libc.Xcosh)
	*(*uintptr)(unsafe.Add(p, 3696)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3728)) = __ccgo_fp(libc.Xsinh)
	*(*uintptr)(unsafe.Add(p, 3736)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3768)) = __ccgo_fp(libc.Xtanh)
	*(*uintptr)(unsafe.Add(p, 3776)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3808)) = __ccgo_fp(libc.Xacosh)
	*(*uintptr)(unsafe.Add(p, 3816)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3848)) = __ccgo_fp(libc.Xasinh)
	*(*uintptr)(unsafe.Add(p, 3856)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3888)) = __ccgo_fp(libc.Xatanh)
	*(*uintptr)(unsafe.Add(p, 3896)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3928)) = __ccgo_fp(libc.Xsqrt)
	*(*uintptr)(unsafe.Add(p, 3936)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 3968)) = __ccgo_fp(_degToRad)
	*(*uintptr)(unsafe.Add(p, 3976)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4008)) = __ccgo_fp(_radToDeg)
	*(*uintptr)(unsafe.Add(p, 4016)) = __ccgo_fp(_math1Func)
	*(*uintptr)(unsafe.Add(p, 4056)) = __ccgo_fp(_piFunc)
	*(*uintptr)(unsafe.Add(p, 4096)) = __ccgo_fp(_signFunc)
	*(*uintptr)(unsafe.Add(p, 4136)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 4176)) = __ccgo_fp(_versionFunc)
	*(*uintptr)(unsafe.Add(p, 4216)) = __ccgo_fp(_versionFunc)
}

/************** End of func.c ************************************************/
/************** Begin file fkey.c ********************************************/
/*
**
** 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.
**
*************************************************************************
** This file contains code used by the compiler to add foreign key
** support to compiled SQL statements.
 */
/* #include "sqliteInt.h" */

/*
** Deferred and Immediate FKs
** --------------------------
**
** Foreign keys in SQLite come in two flavours: deferred and immediate.
** If an immediate foreign key constraint is violated,
** SQLITE_CONSTRAINT_FOREIGNKEY is returned and the current
** statement transaction rolled back. If a
** deferred foreign key constraint is violated, no action is taken
** immediately. However if the application attempts to commit the
** transaction before fixing the constraint violation, the attempt fails.
**
** Deferred constraints are implemented using a simple counter associated
** with the database handle. The counter is set to zero each time a
** database transaction is opened. Each time a statement is executed
** that causes a foreign key violation, the counter is incremented. Each
** time a statement is executed that removes an existing violation from
** the database, the counter is decremented. When the transaction is
** committed, the commit fails if the current value of the counter is
** greater than zero. This scheme has two big drawbacks:
**
**   * When a commit fails due to a deferred foreign key constraint,
**     there is no way to tell which foreign constraint is not satisfied,
**     or which row it is not satisfied for.
**
**   * If the database contains foreign key violations when the
**     transaction is opened, this may cause the mechanism to malfunction.
**
** Despite these problems, this approach is adopted as it seems simpler
** than the alternatives.
**
** INSERT operations:
**
**   I.1) For each FK for which the table is the child table, search
**        the parent table for a match. If none is found increment the
**        constraint counter.
**
**   I.2) For each FK for which the table is the parent table,
**        search the child table for rows that correspond to the new
**        row in the parent table. Decrement the counter for each row
**        found (as the constraint is now satisfied).
**
** DELETE operations:
**
**   D.1) For each FK for which the table is the child table,
**        search the parent table for a row that corresponds to the
**        deleted row in the child table. If such a row is not found,
**        decrement the counter.
**
**   D.2) For each FK for which the table is the parent table, search
**        the child table for rows that correspond to the deleted row
**        in the parent table. For each found increment the counter.
**
** UPDATE operations:
**
**   An UPDATE command requires that all 4 steps above are taken, but only
**   for FK constraints for which the affected columns are actually
**   modified (values must be compared at runtime).
**
** Note that I.1 and D.1 are very similar operations, as are I.2 and D.2.
** This simplifies the implementation a bit.
**
** For the purposes of immediate FK constraints, the OR REPLACE conflict
** resolution is considered to delete rows before the new row is inserted.
** If a delete caused by OR REPLACE violates an FK constraint, an exception
** is thrown, even if the FK constraint would be satisfied after the new
** row is inserted.
**
** Immediate constraints are usually handled similarly. The only difference
** is that the counter used is stored as part of each individual statement
** object (struct Vdbe). If, after the statement has run, its immediate
** constraint counter is greater than zero,
** it returns SQLITE_CONSTRAINT_FOREIGNKEY
** and the statement transaction is rolled back. An exception is an INSERT
** statement that inserts a single row only (no triggers). In this case,
** instead of using a counter, an exception is thrown immediately if the
** INSERT violates a foreign key constraint. This is necessary as such
** an INSERT does not open a statement transaction.
**
** TODO: How should dropping a table be handled? How should renaming a
** table be handled?
**
**
** Query API Notes
** ---------------
**
** Before coding an UPDATE or DELETE row operation, the code-generator
** for those two operations needs to know whether or not the operation
** requires any FK processing and, if so, which columns of the original
** row are required by the FK processing VDBE code (i.e. if FKs were
** implemented using triggers, which of the old.* columns would be
** accessed). No information is required by the code-generator before
** coding an INSERT operation. The functions used by the UPDATE/DELETE
** generation code to query for this information are:
**
**   sqlite3FkRequired() - Test to see if FK processing is required.
**   sqlite3FkOldmask()  - Query for the set of required old.* columns.
**
**
** Externally accessible module functions
** --------------------------------------
**
**   sqlite3FkCheck()    - Check for foreign key violations.
**   sqlite3FkActions()  - Code triggers for ON UPDATE/ON DELETE actions.
**   sqlite3FkDelete()   - Delete an FKey structure.
 */

/*
** VDBE Calling Convention
** -----------------------
**
** Example:
**
**   For the following INSERT statement:
**
**     CREATE TABLE t1(a, b INTEGER PRIMARY KEY, c);
**     INSERT INTO t1 VALUES(1, 2, 3.1);
**
**   Register (x):        2    (type integer)
**   Register (x+1):      1    (type integer)
**   Register (x+2):      NULL (type NULL)
**   Register (x+3):      3.1  (type real)
 */

func init() {
	p := unsafe.Pointer(&_sMutex)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_noopMutexInit)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_noopMutexEnd)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_noopMutexAlloc)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_noopMutexFree)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_noopMutexEnter)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_noopMutexTry)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_noopMutexLeave)
}

func init() {
	p := unsafe.Pointer(&_sFts5Api)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_fts5ApiUserData)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_fts5ApiColumnCount)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_fts5ApiRowCount)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_fts5ApiColumnTotalSize)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_fts5ApiTokenize)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_fts5ApiPhraseCount)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_fts5ApiPhraseSize)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_fts5ApiInstCount)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_fts5ApiInst)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_fts5ApiRowid)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_fts5ApiColumnText)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_fts5ApiColumnSize)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_fts5ApiQueryPhrase)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_fts5ApiSetAuxdata)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_fts5ApiGetAuxdata)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_fts5ApiPhraseFirst)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_fts5ApiPhraseNext)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_fts5ApiPhraseFirstColumn)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_fts5ApiPhraseNextColumn)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_fts5ApiQueryToken)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_fts5ApiInstToken)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_fts5ApiColumnLocale)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_fts5ApiTokenize_v2)
}

func init() {
	p := unsafe.Pointer(&_defaultMethods)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_sqlite3MemMalloc)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_sqlite3MemFree)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_sqlite3MemRealloc)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_sqlite3MemSize)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_sqlite3MemRoundup)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_sqlite3MemInit)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_sqlite3MemShutdown)
}

/************** End of mem1.c ************************************************/
/************** Begin file mem2.c ********************************************/
/*
** 2007 August 15
**
** 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.
**
*************************************************************************
**
** This file contains low-level memory allocation drivers for when
** SQLite will use the standard C-library malloc/realloc/free interface
** to obtain the memory it needs while adding lots of additional debugging
** information to each allocation in order to help detect and fix memory
** leaks and memory usage errors.
**
** This file contains implementations of the low-level memory allocation
** routines specified in the sqlite3_mem_methods object.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is used only if the
** SQLITE_MEMDEBUG macro is defined
 */

/************** End of mem2.c ************************************************/
/************** Begin file mem3.c ********************************************/
/*
** 2007 October 14
**
** 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.
**
*************************************************************************
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** This version of the memory allocation subsystem omits all
** use of malloc(). The SQLite user supplies a block of memory
** before calling sqlite3_initialize() from which allocations
** are made and returned by the xMalloc() and xRealloc()
** implementations. Once sqlite3_initialize() has been called,
** the amount of memory available to SQLite is fixed and cannot
** be changed.
**
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS3 is defined.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is only built into the library
** SQLITE_ENABLE_MEMSYS3 is defined. Defining this symbol does not
** mean that the library will use a memory-pool by default, just that
** it is available. The mempool allocator is activated by calling
** sqlite3_config().
 */

/************** End of mem3.c ************************************************/
/************** Begin file mem5.c ********************************************/
/*
** 2007 October 14
**
** 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.
**
*************************************************************************
** This file contains the C functions that implement a memory
** allocation subsystem for use by SQLite.
**
** This version of the memory allocation subsystem omits all
** use of malloc(). The application gives SQLite a block of memory
** before calling sqlite3_initialize() from which allocations
** are made and returned by the xMalloc() and xRealloc()
** implementations. Once sqlite3_initialize() has been called,
** the amount of memory available to SQLite is fixed and cannot
** be changed.
**
** This version of the memory allocation subsystem is included
** in the build only if SQLITE_ENABLE_MEMSYS5 is defined.
**
** This memory allocator uses the following algorithm:
**
**   1.  All memory allocation sizes are rounded up to a power of 2.
**
**   2.  If two adjacent free blocks are the halves of a larger block,
**       then the two blocks are coalesced into the single larger block.
**
**   3.  New memory is allocated from the first available free block.
**
** This algorithm is described in: J. M. Robson. "Bounds for Some Functions
** Concerning Dynamic Storage Allocation". Journal of the Association for
** Computing Machinery, Volume 21, Number 8, July 1974, pages 491-499.
**
** Let n be the size of the largest allocation divided by the minimum
** allocation size (after rounding all sizes up to a power of 2.)  Let M
** be the maximum amount of memory ever outstanding at one time.  Let
** N be the total amount of memory available for allocation.  Robson
** proved that this memory allocator will never breakdown due to
** fragmentation as long as the following constraint holds:
**
**      N >=  M*(1 + log2(n)/2) - n + 1
**
** The sqlite3_status() logic tracks the maximum values of n and M so
** that an application can, at any time, verify this constraint.
 */
/* #include "sqliteInt.h" */

/*
** This version of the memory allocator is used only when
** SQLITE_ENABLE_MEMSYS5 is defined.
 */

/************** End of mem5.c ************************************************/
/************** Begin file mutex.c *******************************************/
/*
** 2007 August 14
**
** 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.
**
*************************************************************************
** This file contains the C functions that implement mutexes.
**
** This file contains code that is common across all mutex implementations.
 */
/* #include "sqliteInt.h" */

func init() {
	p := unsafe.Pointer(&_fts5Vocab)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_fts5VocabCreateMethod)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_fts5VocabConnectMethod)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_fts5VocabBestIndexMethod)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_fts5VocabDisconnectMethod)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_fts5VocabDestroyMethod)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_fts5VocabOpenMethod)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_fts5VocabCloseMethod)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_fts5VocabFilterMethod)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_fts5VocabNextMethod)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_fts5VocabEofMethod)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_fts5VocabColumnMethod)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_fts5VocabRowidMethod)
}

/* Here ends the fts5.c composite file. */

/************** End of fts5.c ************************************************/
/************** Begin file stmt.c ********************************************/
/*
** 2017-05-31
**
** 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.
**
*************************************************************************
**
** This file demonstrates an eponymous virtual table that returns information
** about all prepared statements for the database connection.
**
** Usage example:
**
**     .load ./stmt
**     .mode line
**     .header on
**     SELECT * FROM stmt;
 */

func init() {
	p := unsafe.Pointer(&_fts5Mod)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_fts5CreateMethod)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_fts5ConnectMethod)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_fts5BestIndexMethod)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_fts5DisconnectMethod)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_fts5DestroyMethod)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_fts5OpenMethod)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_fts5CloseMethod)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_fts5FilterMethod)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_fts5NextMethod)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_fts5EofMethod)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_fts5ColumnMethod)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_fts5RowidMethod)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_fts5UpdateMethod)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_fts5BeginMethod)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_fts5SyncMethod)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_fts5CommitMethod)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_fts5RollbackMethod)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_fts5FindFunctionMethod)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_fts5RenameMethod)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_fts5SavepointMethod)
	*(*uintptr)(unsafe.Add(p, 84)) = __ccgo_fp(_fts5ReleaseMethod)
	*(*uintptr)(unsafe.Add(p, 88)) = __ccgo_fp(_fts5RollbackToMethod)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_fts5ShadowName)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_fts5IntegrityMethod)
}

func init() {
	p := unsafe.Pointer(&_pragmaVtabModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_pragmaVtabConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_pragmaVtabBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_pragmaVtabDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_pragmaVtabOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_pragmaVtabClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_pragmaVtabFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_pragmaVtabNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_pragmaVtabEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_pragmaVtabColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_pragmaVtabRowid)
}

func init() {
	p := unsafe.Pointer(&_statPushFuncdef)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statPush)
}

func init() {
	p := unsafe.Pointer(&_jsonEachModule)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_jsonEachConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_jsonEachBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_jsonEachDisconnect)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_jsonEachOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_jsonEachClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_jsonEachFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_jsonEachNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_jsonEachEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_jsonEachColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_jsonEachRowid)
}

func init() {
	p := unsafe.Pointer(&_statInitFuncdef)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statInit)
}

func init() {
	p := unsafe.Pointer(&_aAgg)
	*(*uintptr)(unsafe.Add(p, 0)) = __ccgo_fp(_geopolyBBoxStep)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_geopolyBBoxFinal)
}

/************** End of geopoly.c *********************************************/
/************** Continuing where we left off in rtree.c **********************/

func init() {
	p := unsafe.Pointer(&_rtreeModule)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_rtreeCreate)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_rtreeConnect)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_rtreeBestIndex)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_rtreeDisconnect)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_rtreeDestroy)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_rtreeOpen)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_rtreeClose)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_rtreeFilter)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_rtreeNext)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_rtreeEof)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_rtreeColumn)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_rtreeRowid)
	*(*uintptr)(unsafe.Add(p, 52)) = __ccgo_fp(_rtreeUpdate)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_rtreeBeginTransaction)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_rtreeEndTransaction)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_rtreeRollback)
	*(*uintptr)(unsafe.Add(p, 76)) = __ccgo_fp(_rtreeRename)
	*(*uintptr)(unsafe.Add(p, 80)) = __ccgo_fp(_rtreeSavepoint)
	*(*uintptr)(unsafe.Add(p, 92)) = __ccgo_fp(_rtreeShadowName)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_rtreeIntegrity)
}

func init() {
	p := unsafe.Pointer(&_statGetFuncdef)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_statGet)
}

func init() {
	p := unsafe.Pointer(&_memdb_io_methods)
	*(*uintptr)(unsafe.Add(p, 4)) = __ccgo_fp(_memdbClose)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_memdbRead)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_memdbWrite)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_memdbTruncate)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_memdbSync)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_memdbFileSize)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_memdbLock)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_memdbUnlock)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_memdbFileControl)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_memdbDeviceCharacteristics)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_memdbFetch)
	*(*uintptr)(unsafe.Add(p, 72)) = __ccgo_fp(_memdbUnfetch)
}

func init() {
	p := unsafe.Pointer(&_aWindowFuncs)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_row_numberStepFunc)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_row_numberValueFunc)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_row_numberValueFunc)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 56)) = __ccgo_fp(_dense_rankStepFunc)
	*(*uintptr)(unsafe.Add(p, 60)) = __ccgo_fp(_dense_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 64)) = __ccgo_fp(_dense_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 68)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 96)) = __ccgo_fp(_rankStepFunc)
	*(*uintptr)(unsafe.Add(p, 100)) = __ccgo_fp(_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 104)) = __ccgo_fp(_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 108)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 136)) = __ccgo_fp(_percent_rankStepFunc)
	*(*uintptr)(unsafe.Add(p, 140)) = __ccgo_fp(_percent_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 144)) = __ccgo_fp(_percent_rankValueFunc)
	*(*uintptr)(unsafe.Add(p, 148)) = __ccgo_fp(_percent_rankInvFunc)
	*(*uintptr)(unsafe.Add(p, 176)) = __ccgo_fp(_cume_distStepFunc)
	*(*uintptr)(unsafe.Add(p, 180)) = __ccgo_fp(_cume_distValueFunc)
	*(*uintptr)(unsafe.Add(p, 184)) = __ccgo_fp(_cume_distValueFunc)
	*(*uintptr)(unsafe.Add(p, 188)) = __ccgo_fp(_cume_distInvFunc)
	*(*uintptr)(unsafe.Add(p, 216)) = __ccgo_fp(_ntileStepFunc)
	*(*uintptr)(unsafe.Add(p, 220)) = __ccgo_fp(_ntileValueFunc)
	*(*uintptr)(unsafe.Add(p, 224)) = __ccgo_fp(_ntileValueFunc)
	*(*uintptr)(unsafe.Add(p, 228)) = __ccgo_fp(_ntileInvFunc)
	*(*uintptr)(unsafe.Add(p, 256)) = __ccgo_fp(_last_valueStepFunc)
	*(*uintptr)(unsafe.Add(p, 260)) = __ccgo_fp(_last_valueFinalizeFunc)
	*(*uintptr)(unsafe.Add(p, 264)) = __ccgo_fp(_last_valueValueFunc)
	*(*uintptr)(unsafe.Add(p, 268)) = __ccgo_fp(_last_valueInvFunc)
	*(*uintptr)(unsafe.Add(p, 296)) = __ccgo_fp(_nth_valueStepFunc)
	*(*uintptr)(unsafe.Add(p, 300)) = __ccgo_fp(_nth_valueFinalizeFunc)
	*(*uintptr)(unsafe.Add(p, 304)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 308)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 336)) = __ccgo_fp(_first_valueStepFunc)
	*(*uintptr)(unsafe.Add(p, 340)) = __ccgo_fp(_first_valueFinalizeFunc)
	*(*uintptr)(unsafe.Add(p, 344)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 348)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 376)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 380)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 384)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 388)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 416)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 420)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 424)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 428)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 456)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 460)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 464)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 468)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 496)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 500)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 504)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 508)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 536)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 540)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 544)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 548)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 576)) = __ccgo_fp(_noopStepFunc)
	*(*uintptr)(unsafe.Add(p, 580)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 584)) = __ccgo_fp(_noopValueFunc)
	*(*uintptr)(unsafe.Add(p, 588)) = __ccgo_fp(_noopStepFunc)
}

func init() {
	p := unsafe.Pointer(&_defaultMethods1)
	*(*uintptr)(unsafe.Add(p, 8)) = __ccgo_fp(_pcache1Init)
	*(*uintptr)(unsafe.Add(p, 12)) = __ccgo_fp(_pcache1Shutdown)
	*(*uintptr)(unsafe.Add(p, 16)) = __ccgo_fp(_pcache1Create)
	*(*uintptr)(unsafe.Add(p, 20)) = __ccgo_fp(_pcache1Cachesize)
	*(*uintptr)(unsafe.Add(p, 24)) = __ccgo_fp(_pcache1Pagecount)
	*(*uintptr)(unsafe.Add(p, 28)) = __ccgo_fp(_pcache1Fetch)
	*(*uintptr)(unsafe.Add(p, 32)) = __ccgo_fp(_pcache1Unpin)
	*(*uintptr)(unsafe.Add(p, 36)) = __ccgo_fp(_pcache1Rekey)
	*(*uintptr)(unsafe.Add(p, 40)) = __ccgo_fp(_pcache1Truncate)
	*(*uintptr)(unsafe.Add(p, 44)) = __ccgo_fp(_pcache1Destroy)
	*(*uintptr)(unsafe.Add(p, 48)) = __ccgo_fp(_pcache1Shrink)
}

type t__predefined_ptrdiff_t = int32

type t__predefined_size_t = uint32
